⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 j3dlwoparser.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				float[] textureCoords, int[] textureIndices) {      /*	   the actual math in these coord calculations comes directly from	   Newtek - they posted sample code to help compute tex coords based	   on the type of mapping:	   Here are some simplified code fragments showing how LightWave	   computes UV coordinates from X, Y, and Z.  If the resulting	   UV coordinates are not in the range from 0 to 1, the	   appropriate integer should be added to them to bring them into	   that range (the fract function should have accomplished	   this by subtracting the floor of each number from itself).	   Then they can be multiplied by the width and height (in pixels)	   of an image map to determine which pixel to look up.  The	   texture size, center, and tiling parameters are taken right	   off the texture control panel.	   x -= xTextureCenter;	   y -= yTextureCenter;	   z -= zTextureCenter;	   if (textureType == TT_PLANAR) {	   s = (textureAxis == TA_X) ? z / zTextureSize + .5 :	   x / xTextureSize + .5;	   t = (textureAxis == TA_Y) ? -z / zTextureSize + .5 :	   -y / yTextureSize + .5;	   u = fract(s);	   v = fract(t);	   }	   else if (type == TT_CYLINDRICAL) {	   if (textureAxis == TA_X) {	   xyztoh(z,x,-y,&lon);	   t = -x / xTextureSize + .5;	   }	   else if (textureAxis == TA_Y) {	   xyztoh(-x,y,z,&lon);	   t = -y / yTextureSize + .5;	   }	   else {	   xyztoh(-x,z,-y,&lon);	   t = -z / zTextureSize + .5;	   }	   lon = 1.0 - lon / TWOPI;	   if (widthTiling != 1.0)	   lon = fract(lon) * widthTiling;	   u = fract(lon);	   v = fract(t);	   }	   else if (type == TT_SPHERICAL) {	   if (textureAxis == TA_X)	   xyztohp(z,x,-y,&lon,&lat);	   else if (textureAxis == TA_Y)	   xyztohp(-x,y,z,&lon,&lat);	   else	   xyztohp(-x,z,-y,&lon,&lat);	   lon = 1.0 - lon / TWOPI;	   lat = .5 - lat / PI;	   if (widthTiling != 1.0)	   lon = fract(lon) * widthTiling;	   if (heightTiling != 1.0)	   lat = fract(lat) * heightTiling;	   u = fract(lon);	   v = fract(lat);	   }	   support functions:	   void xyztoh(float x,float y,float z,float *h)	   {	   if (x == 0.0 && z == 0.0)	   *h = 0.0;	   else {	   if (z == 0.0)	   *h = (x < 0.0) ? HALFPI : -HALFPI;	   else if (z < 0.0)	   *h = -atan(x / z) + PI;	   else	   *h = -atan(x / z);	   }	   }	   void xyztohp(float x,float y,float z,float *h,float *p)	   {	   if (x == 0.0 && z == 0.0) {	   *h = 0.0;	   if (y != 0.0)	   *p = (y < 0.0) ? -HALFPI : HALFPI;	   else	   *p = 0.0;	   }	   else {	   if (z == 0.0)	   *h = (x < 0.0) ? HALFPI : -HALFPI;	   else if (z < 0.0)	   *h = -atan(x / z) + PI;	   else	   *h = -atan(x / z);	   x = sqrt(x * x + z * z);	   if (x == 0.0)	   *p = (y < 0.0) ? -HALFPI : HALFPI;	   else	   *p = atan(y / x);	   }	   }      */	debugOutputLn(TRACE, "calculateTextureCoords()");	// Compute texture coord stuff	float sx = 0, sz = 0, ty = 0, tz = 0;	double s, t;	int textureAxis = texture.getTextureAxis();	Vector3f textureSize = texture.getTextureSize();	Vector3f textureCenter = texture.getTextureCenter();	String mappingType = texture.getMappingType();	if (mappingType.startsWith("Cylindrical"))	    calculateCylindricalTextureCoords(textureAxis, textureSize,					      textureCenter, textureCoords,					      textureIndices,					      verts, indices);	else if (mappingType.startsWith("Spherical"))	    calculateSphericalTextureCoords(textureAxis, 					    textureCenter, textureCoords,					    textureIndices,					    verts, indices);	else if (mappingType.startsWith("Planar"))	    calculatePlanarTextureCoords(textureAxis, textureSize,					 textureCenter, textureCoords,					 textureIndices,					 verts, indices);    }    /** See the comments in calculateTextureCoordinates*/    double xyztoh(float x,float y,float z) {	if (x == 0.0 && z == 0.0)	    return 0.0;	else {	    if (z == 0.0)		return (x < 0.0) ? Math.PI/2.0 : -Math.PI/2.0;	    else if (z < 0.0)		return -Math.atan(x / z) + Math.PI;	    else		return -Math.atan(x / z);	}    }	    /** See the comments in calculateTextureCoordinates*/    double xyztop(float x,float y,float z) {	double p;		if (x == 0.0 && z == 0.0) {	    if (y != 0.0)		p = (y < 0.0) ? -Math.PI/2 : Math.PI/2;	    else		p = 0.0;	}	else {	    x = (float)Math.sqrt(x * x + z * z);	    if (x == 0.0)		p = (y < 0.0) ? -Math.PI/2 : Math.PI/2;	    else		p = Math.atan(y / x);	}	return p;    }        /** See the comments in calculateTextureCoordinates*/    void calculateSphericalTextureCoords(int textureAxis,					 Vector3f textureCenter,					 float textureCoords[],					 int textureIndices[],					 float verts[], int indices[]) {	debugOutputLn(TRACE, "calculateSphericalTextureCoords");	double s, t;			for (int i = 0; i < indices.length; ++i) {	    float x = verts[3*indices[i]] - textureCenter.x;	    float y = verts[3*indices[i]+1] - textureCenter.y;	    float z = -(verts[3*indices[i]+2] + textureCenter.z);	    if (textureAxis == 1){ // X Axis		s = xyztoh(z, x, -y);		t = xyztop(z,x,-y);	    }	    else if (textureAxis == 2) { // Y Axis		s = xyztoh(-x,y,z);		t = xyztop(-x,y,z);	    }	    else {			// Z Axis		s = xyztoh(-x,z,-y);		t = xyztop(-x,z,-y);	    }	    s = 1.0 - s / (2*Math.PI);	    t = -(.5 - t / Math.PI);	    textureCoords[indices[i]*2] = (float)s;	    textureCoords[indices[i]*2 + 1] = (float)t;	    textureIndices[i] = indices[i];	}    }	    /** See the comments in calculateTextureCoordinates*/    void calculateCylindricalTextureCoords(int textureAxis,					   Vector3f textureSize,					   Vector3f textureCenter,					   float textureCoords[],					   int textureIndices[],					   float verts[], int indices[]) {	debugOutputLn(TRACE, "calculateCylindricalTextureCoords");	debugOutputLn(VALUES, "axis, size, center, tc, ti, v, i = " +		      textureAxis + ", " +		      textureSize + ", " +		      textureCenter + ", " +		      textureCoords + ", " +		      textureIndices + ", " +		      verts + ", " +		      indices);	double s, t;		debugOutputLn(VALUES, "Cyl Texture Coords:");	for (int i = 0; i < indices.length; ++i) {	    float x = verts[3*indices[i]] - textureCenter.x;	    float y = verts[3*indices[i]+1] - textureCenter.y;	    float z = -(verts[3*indices[i]+2] + textureCenter.z);	    // Negate z value because we invert geom z's to swap handedness	    if (textureAxis == 1) { // X axis		s = xyztoh(z,x,-y);		t = x / textureSize.x + .5;	    }	    else if (textureAxis == 2) { // Y Axis		s = xyztoh(-x,y,z);		t = y / textureSize.y + .5;	    }	    else {		s = xyztoh(-x,z,-y);		t = z / textureSize.z + .5;	    }	    s = 1.0 - s / (2*Math.PI);	    textureCoords[indices[i]*2] = (float)s;	    textureCoords[indices[i]*2 + 1] = (float)t;	    textureIndices[i] = indices[i];	    debugOutputLn(VALUES, "x, y, z = " +			  x + ", " + y + ", " + z + "    " +			  "s, t = " + s + ", " + t);	}    }        /** See the comments in calculateTextureCoordinates*/    void calculatePlanarTextureCoords(int textureAxis, Vector3f textureSize,				      Vector3f textureCenter,				      float textureCoords[],				      int textureIndices[],				      float verts[], int indices[]) {	debugOutputLn(TRACE, "calculatePlanarTextureCoords");	debugOutputLn(VALUES, "size, center, axis = " +		      textureSize + textureCenter + ", " + textureAxis);	float sx = 0, sz = 0, ty = 0, tz = 0;	double s, t;	if (textureAxis == 1) {		// X Axis	    sz = -1.0f / textureSize.z;  // Negate because we negate z in geom	    ty = 1.0f / textureSize.y;	}	else if (textureAxis == 2) {	// Y Axis	    sx = 1.0f / textureSize.x;	    tz = -1.0f / textureSize.z;  // Negate because we negate z in geom	}	else {				// Z Axis	    sx = 1.0f / textureSize.x;	    ty = 1.0f / textureSize.y;	}	debugOutputLn(VALUES, "Planar Texture Coords:");	for (int i = 0; i < indices.length; ++i) {	    float x = verts[3*indices[i]] - textureCenter.x;	    float y = verts[3*indices[i]+1] - textureCenter.y;	    float z = verts[3*indices[i]+2] + textureCenter.z;	    s = x*sx + z*sz + .5;	    t = y*ty + z*tz + .5;	    textureCoords[indices[i]*2] = (float)s;	    textureCoords[indices[i]*2 + 1] = (float)t;	    textureIndices[i] = indices[i];	    debugOutputLn(VALUES, "x, y, z = " +			  x + ", " + y + ", " + z + "    " +			  "s, t = " + s + ", " + t);	}    }        Shape3D getJava3dShape() {	return objectShape;    }    Vector getJava3dShapeList() {	return objectShapeList;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -