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

📄 pickintersection.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	    if (geometryIsIndexed()) {		primitiveColorIndices = 		    new int[primitiveVertexIndices.length];		for (int i = 0; i < primitiveVertexIndices.length; i++) {		    primitiveColorIndices[i] =  			((IndexedGeometryArray)(geometry)).getColorIndex(primitiveVertexIndices[i]);		}	    } else {		primitiveColorIndices = primitiveVertexIndices;	    }	}	return primitiveColorIndices;    }    /**      * Get the colors of the intersected primitive.  This will return null if     * the primitive does not contain colors.  If the geometry was defined     * using GeometryArray.COLOR_3, the 'w' value of the color will be set to 1.0.     * @return an array of Point3d's for the primitive that was intersected     */    public Color4f[] getPrimitiveColors() {// 	System.out.println("PI.getPrimitiveColors " + primitiveColors);		GeometryArray geom = (GeometryArray) geometry;	if (hasColors && (primitiveColors == null)) {	    primitiveColors = new Color4f[primitiveVertexIndices.length];	    int[] indices = getPrimitiveColorIndices();	    int vformat = geom.getVertexFormat();	    if ((vformat & GeometryArray.BY_REFERENCE) == 0) {		if ((vformat & GeometryArray.COLOR_4) == 		    GeometryArray.COLOR_4) {		    for (int i = 0; i < indices.length; i++) {			primitiveColors[i] = new Color4f();			geom.getColor(indices[i], primitiveColors[i]);		    }		} else {		    Color3f color = new Color3f();		    for (int i = 0; i < indices.length; i++) {			primitiveColors[i] = new Color4f();			geom.getColor(indices[i], color);			primitiveColors[i].x = color.x;			primitiveColors[i].y = color.y;			primitiveColors[i].z = color.z;			primitiveColors[i].w = 1.0f;		    }		}	    }	    else {		if ((vformat & GeometryArray.INTERLEAVED) == 0) {		    float[] floatData = geom.getColorRefFloat();		    // If data was set as float then ..		    if (floatData == null) {			byte[] byteData = geom.getColorRefByte();			if (byteData == null) {			    throw new UnsupportedOperationException("Deprecated : BY_REF - c3b and c3f");			}			else {			    // Could be color3 or color4			    int val;			    if ((vformat & GeometryArray.COLOR_4) == 				GeometryArray.COLOR_4) {				for (int i = 0; i < indices.length; i++) {				    val = indices[i] << 2; // for color4f				    primitiveColors[i] = new Color4f(byteData[val],								     byteData[val+1],								     byteData[val+2],								     byteData[val+3]);				}			    }			    else {				for (int i = 0; i < indices.length; i++) {				    val = indices[i] * 3; // for color3f				    primitiveColors[i] = new Color4f(byteData[val],								     byteData[val+1],								     byteData[val+2], 								     1.0f);				}			    }			}		    }		    else {			// Could be color3 or color4			int val;			if ((vformat & GeometryArray.COLOR_4) == 			    GeometryArray.COLOR_4) {			    for (int i = 0; i < indices.length; i++) {				val = indices[i] << 2; // for color4f				primitiveColors[i] = new Color4f(floatData[val],								 floatData[val+1],								 floatData[val+2],								 floatData[val+3]);			    }			}			else {			    for (int i = 0; i < indices.length; i++) {				val = indices[i] * 3; // for color3f				primitiveColors[i] = new Color4f(floatData[val],								 floatData[val+1],								 floatData[val+2],								 1.0f);			    }			}		    }		}		else {		    float[] floatData = geom.getInterleavedVertices();		    int offset = getInterleavedColorOffset(geom);		    int stride = getInterleavedStride(geom); 		    for (int i = 0; i < indices.length; i++) {			int val = stride * indices[i]+offset;			if ((vformat & GeometryArray.COLOR_4) == 			    GeometryArray.COLOR_4) {			    primitiveColors[i] = new Color4f(floatData[val],							     floatData[val+1],							     floatData[val+2],							     floatData[val+3]);			}			else {			    primitiveColors[i] = new Color4f(floatData[val],							     floatData[val+1],							     floatData[val+2],							     1.0f);			}		    }		}	    }	}	return primitiveColors;    }    /**      * Get the coordinates indices for the intersected primitive.  For a non-indexed     * primitive, this will be the same as the primitive vertex indices     * @return an array indices     */    public int[] getPrimitiveCoordinateIndices() {	if (primitiveCoordinateIndices == null) {	    if (geometryIsIndexed()) {		primitiveCoordinateIndices = 		    new int[primitiveVertexIndices.length];		for (int i = 0; i < primitiveVertexIndices.length; i++) {		    primitiveCoordinateIndices[i] =  			((IndexedGeometryArray)(geometry)).getCoordinateIndex(primitiveVertexIndices[i]);		}	    } else {		primitiveCoordinateIndices = primitiveVertexIndices;	    }	}	return primitiveCoordinateIndices;    }    /**      * Get the local coordinates intersected primitive      * @return an array of Point3d's for the primitive that was intersected     */    public Point3d[] getPrimitiveCoordinates() {// 	System.out.println("PI.getPrimitiveCoordinates " + primitiveCoordinates);		GeometryArray geom = (GeometryArray) geometry;	if (primitiveCoordinates == null) {	    primitiveCoordinates = new Point3d[primitiveVertexIndices.length];	    int[] indices = getPrimitiveCoordinateIndices();	    int vformat = geom.getVertexFormat();	    int val;	    // 	    System.out.println("---- indices.length - " + indices.length);	    if ((vformat & GeometryArray.BY_REFERENCE) == 0) {		for (int i = 0; i < indices.length; i++) {		    primitiveCoordinates[i] = new Point3d();		    // System.out.println("PickIntersection : indices["+i+"] = " + indices[i]);		    geom.getCoordinate(indices[i], primitiveCoordinates[i]);		}	    }	    else {		if ((vformat & GeometryArray.INTERLEAVED) == 0) {		    double[] doubleData = geom.getCoordRefDouble();		    // If data was set as float then ..		    if (doubleData == null) {			float[] floatData = geom.getCoordRefFloat();			if (floatData == null) {			    throw new UnsupportedOperationException("Deprecated : BY_REF - c3f and c3d");					}			else {			    for (int i = 0; i < indices.length; i++) {				val = indices[i] * 3;				primitiveCoordinates[i] = new Point3d(floatData[val], 								      floatData[val+1], 								      floatData[val+2]);			    }			}		    }		    else {			for (int i = 0; i < indices.length; i++) {			    val = indices[i] * 3;			    primitiveCoordinates[i] = new Point3d(doubleData[val], 								  doubleData[val+1], 								  doubleData[val+2]);			}					    }		}		else {		    float[] floatData = geom.getInterleavedVertices();		    int offset = getInterleavedVertexOffset(geom);		    int stride = offset + 3; // for the vertices .		    for (int i = 0; i < indices.length; i++) {			val = stride * indices[i]+offset;			primitiveCoordinates[i] = new Point3d(floatData[val], 							      floatData[val+1], 							      floatData[val+2]);		    }		}	    }	}	return primitiveCoordinates;    }        /**      * Get VWorld coordinates of the intersected primitive      * @return an array of Point3d's for the primitive that was picked     */    public Point3d[] getPrimitiveCoordinatesVW() {// 	System.out.println("PI.getPrimitiveCoordinatesVW " + primitiveCoordinatesVW);		if (primitiveCoordinatesVW == null) {	    // We need to call getPrimitiveCoordinates first.	    Point3d[] coords = getPrimitiveCoordinates();	    primitiveCoordinatesVW = new Point3d[coords.length];	    for (int i = 0; i < coords.length; i++) {		primitiveCoordinatesVW[i] = new Point3d();		primitiveCoordinatesVW[i].x = coords[i].x;		primitiveCoordinatesVW[i].y = coords[i].y;		primitiveCoordinatesVW[i].z = coords[i].z;		l2vw.transform(primitiveCoordinatesVW[i]);	    }	}	return primitiveCoordinatesVW;    }        /**      * Get the normal indices for the intersected primitive.  For a non-indexed     * primitive, this will be the same as the primitive vertex indices     * If the geometry array does not contain normals this will return null     *	@return an array indices     */    public int[] getPrimitiveNormalIndices() {	if (hasNormals && (primitiveNormalIndices == null)) {	    if (geometryIsIndexed()) {		primitiveNormalIndices = 		    new int[primitiveVertexIndices.length];		for (int i = 0; i < primitiveVertexIndices.length; i++) {		    primitiveNormalIndices[i] = 			((IndexedGeometryArray)(geometry)).getNormalIndex(primitiveVertexIndices[i]);		}	    } else {		primitiveNormalIndices = primitiveVertexIndices;	    }	}	return primitiveNormalIndices;    }    /**      * Get the normals of the intersected primitive.  This will return null if     * the primitive does not contain normals.     * @return an array of Point3d's for the primitive that was intersected     */    public Vector3f[] getPrimitiveNormals() {// 	System.out.println("PI.getPrimitiveNormals " + primitiveNormals);		GeometryArray geom = (GeometryArray) geometry;	if (hasNormals && (primitiveNormals == null)) {	    primitiveNormals = new Vector3f[primitiveVertexIndices.length];	    int[] indices = getPrimitiveNormalIndices();	    int vformat = geom.getVertexFormat();	    int val;	    if ((vformat & GeometryArray.BY_REFERENCE) == 0) {		for (int i = 0; i < indices.length; i++) {		    primitiveNormals[i] = new Vector3f();		    geom.getNormal(indices[i], primitiveNormals[i]);		}	    }	    else {		if ((vformat & GeometryArray.INTERLEAVED) == 0) {		    float[] floatNormals = geom.getNormalRefFloat();		    if (floatNormals != null) {			for (int i = 0; i < indices.length; i++) {			    val = indices[i] * 3;			    primitiveNormals[i] = new Vector3f(floatNormals[val],							       floatNormals[val+1],							       floatNormals[val+2]);			}		    }		    else {			throw new UnsupportedOperationException("Deprecated : BY_REF - n3f");		    }		}		else {		    float[] floatData = geom.getInterleavedVertices();		    int offset = getInterleavedColorOffset(geom);		    int stride = getInterleavedStride(geom);		    for (int i = 0; i < indices.length; i++) {			val = stride * indices[i]+offset;			primitiveNormals[i] = new Vector3f(floatData[val],floatData[val+1],floatData[val+2]);		    }		}	    }	}	return primitiveNormals;    }    /**      * Get the texture coordinate indices for the intersected primitive at the specifed      * index in the specified texture coordinate set.  For a   non-indexed     * primitive, this will be the same as the primitive vertex indices     * If the geometry array does not contain texture coordinates, this will      * return null.     * @return an array indices     */    public int[] getPrimitiveTexCoordIndices(int index) {	if (hasTexCoords && (primitiveTexCoordIndices == null)) {	    if (geometryIsIndexed()) {		primitiveTexCoordIndices = 		    new int[primitiveVertexIndices.length];		for (int i = 0; i < primitiveVertexIndices.length; i++) {		    primitiveTexCoordIndices[i] =  			((IndexedGeometryArray)(geometry)).getTextureCoordinateIndex(index, primitiveVertexIndices[i]);		}	    } else {		primitiveTexCoordIndices = primitiveVertexIndices;	    }	}	return primitiveTexCoordIndices;    }    /**      * Get the texture coordinates of the intersected primitive at the specifed      * index in the specified texture coordinate set.     * null if the primitive does not contain texture coordinates.       * If the geometry was defined     * using GeometryArray.TEXTURE_COORDINATE_2, the 'z' value of the texture     * coordinate will be set to 0.0.     * @return an array of TexCoord3f's for the primitive that was intersected     */    public TexCoord3f[] getPrimitiveTexCoords (int index) {// 	System.out.println("PI.getPrimitiveTexCoords " + primitiveTexCoords);		GeometryArray geom = (GeometryArray) geometry;	if (primitiveTexCoords == null) {	    primitiveTexCoords = new TexCoord3f[primitiveVertexIndices.length];	    int[] indices = getPrimitiveTexCoordIndices(index);	    int vformat = geom.getVertexFormat();	    if ((vformat & GeometryArray.BY_REFERENCE) == 0) {		for (int i = 0; i < indices.length; i++) {		    primitiveTexCoords[i] = new TexCoord3f();		    geom.getTextureCoordinate(index, indices[i], primitiveTexCoords[i]);		}	    }	    else {		if ((vformat & GeometryArray.INTERLEAVED) == 0) {		    int val;		    float[] floatTexCoords = geom.getTexCoordRefFloat(index);		    if (floatTexCoords != null) {			if ((vformat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2) {			    for (int i = 0; i < indices.length; i++) {				val = indices[i] << 1; // t2f				primitiveTexCoords[i] = new TexCoord3f(floatTexCoords[val],								       floatTexCoords[val+1],								       0.0f);			    }			}			else {			    for (int i = 0; i < indices.length; i++) {				val = indices[i] * 3; // t3f				primitiveTexCoords[i] = new TexCoord3f(floatTexCoords[val],								       floatTexCoords[val+1],								       floatTexCoords[val+2]);			    }			}		    }		    else {			throw new UnsupportedOperationException("Deprecated : BY_REF - t2f and t3f");		    }		}		else {		    float[] floatData = geom.getInterleavedVertices();		    int stride = getInterleavedStride(geom);		    int offset;		    // Get the correct tex coord set		    if ((vformat & GeometryArray.TEXTURE_COORDINATE_2) ==			GeometryArray.TEXTURE_COORDINATE_2) {			offset = index << 1;		    }		    else {			offset = index * 3;		    }		    for (int i = 0; i < indices.length; i++) {			int val = stride * indices[i];			if ((vformat & GeometryArray.TEXTURE_COORDINATE_2) == 			    GeometryArray.TEXTURE_COORDINATE_2) {			    primitiveTexCoords[i] = 				new TexCoord3f(floatData[val+offset],					       floatData[val+1+offset],					       0.0f);			}			else {			    primitiveTexCoords[i] = 				new TexCoord3f(floatData[val+offset],					       floatData[val+1+offset],					       floatData[val+2+offset]);			}		    }		}	    }	}	return primitiveTexCoords;    }    /**      * Get vertex indices of the intersected primitive     * @return an array which contains the list of indices     */    public int [] getPrimitiveVertexIndices() {	return primitiveVertexIndices;    }    /**     * Gets the IntersectionInfo this intersection is part of.     */    public PickInfo.IntersectionInfo getIntersectionInfo() {	return iInfo;    }    /**     * String representation of this object     */     public String toString() {	String rt = new String ("PickIntersection: ");	rt += " IntersectionInfo = "+ iInfo + "\n";	rt += " geometry = "+ geometry + "\n";	if (distance != -1) rt += " dist:"+distance + "\n";	if (pointCoordinates != null) rt += " pt:" + pointCoordinates + "\n";	if (pointCoordinatesVW != null) rt += " ptVW:" + pointCoordinatesVW + "\n";	if (primitiveCoordinateIndices != null) {	    rt += " prim coordinate ind:" + "\n";	    for (int i=0;i<primitiveCoordinateIndices.length;i++) {		rt += " "+primitiveCoordinateIndices[i] + "\n";	    }	}

⌨️ 快捷键说明

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