📄 morphretained.java
字号:
Object[] obj = new Object[2]; if (newAppearance == null) { obj[0] = null; } else { obj[0] = appearance.mirror; } obj[1] = new Integer(changedFrequent); createMessage[0].args[3] = obj; createMessage[0].args[4] = Shape3DRetained.getGeomAtomsArray(mirrorShape3D); if(visibleIsDirty) { createMessage[1] = new J3dMessage(); createMessage[1].threads = J3dThread.UPDATE_GEOMETRY; createMessage[1].type = J3dMessage.SHAPE3D_CHANGED; createMessage[1].universe = universe; createMessage[1].args[0] = this; createMessage[1].args[1]= new Integer(APPEARANCE_CHANGED); createMessage[1].args[2]= visible?Boolean.TRUE:Boolean.FALSE; createMessage[1].args[3]= createMessage[0].args[4]; } VirtualUniverse.mc.processMessage(createMessage); } else { if (newAppearance == null) { appearance = null; } else { appearance = (AppearanceRetained) newAppearance.retained; } } } /** * Retrieves the morph node's appearance component. * @return the morph node's appearance */ Appearance getAppearance() { return (appearance == null ? null : (Appearance) this.appearance.source); } void setAppearanceOverrideEnable(boolean flag) { if (((Morph)this.source).isLive()) { // Send a message J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ENVIRONMENT | J3dThread.UPDATE_RENDER;; createMessage.type = J3dMessage.MORPH_CHANGED; createMessage.universe = universe; createMessage.args[0] = this; createMessage.args[1]= new Integer(APPEARANCEOVERRIDE_CHANGED); Shape3DRetained[] s3dArr = new Shape3DRetained[mirrorShape3D.size()]; mirrorShape3D.toArray(s3dArr); createMessage.args[2] = s3dArr; Object[] obj = new Object[2]; if (flag) { obj[0] = Boolean.TRUE; } else { obj[0] = Boolean.FALSE; } obj[1] = new Integer(changedFrequent); createMessage.args[3] = obj; createMessage.args[4] = Shape3DRetained.getGeomAtomsArray(mirrorShape3D); VirtualUniverse.mc.processMessage(createMessage); } appearanceOverrideEnable = flag; } boolean getAppearanceOverrideEnable() { return appearanceOverrideEnable; } boolean intersect(PickInfo pickInfo, PickShape pickShape, int flags ) { Transform3D localToVworld = pickInfo.getLocalToVWorldRef(); Transform3D vworldToLocal = new Transform3D(); vworldToLocal.invert(localToVworld); PickShape newPS = pickShape.transform(vworldToLocal); GeometryRetained geo = (GeometryRetained) (morphedGeometryArray.retained); if (geo.mirrorGeometry != null) { geo = geo.mirrorGeometry; } if (((flags & PickInfo.CLOSEST_INTERSECTION_POINT) == 0) && ((flags & PickInfo.CLOSEST_DISTANCE) == 0) && ((flags & PickInfo.CLOSEST_GEOM_INFO) == 0) && ((flags & PickInfo.ALL_GEOM_INFO) == 0)) { return geo.intersect(newPS, null, 0, null, null, 0); } else { Point3d closestIPnt = new Point3d(); Point3d iPnt = new Point3d(); Point3d iPntVW = new Point3d(); if (geo.intersect(newPS, pickInfo, flags, iPnt, geo, 0)) { iPntVW.set(iPnt); localToVworld.transform(iPntVW); double distance = pickShape.distance(iPntVW); if ((flags & PickInfo.CLOSEST_DISTANCE) != 0) { pickInfo.setClosestDistance(distance); } if((flags & PickInfo.CLOSEST_INTERSECTION_POINT) != 0) { pickInfo.setClosestIntersectionPoint(iPnt); } return true; } } return false; } /** * Check if the geometry component of this shape node under path * intersects with the pickShape. * @return true if intersected else false. If return is true, dist * contains the closest distance of intersection if it is not * equal to null. */ boolean intersect(SceneGraphPath path, PickShape pickShape, double[] dist) { // This method will not do bound intersect check, as it assume caller // has already done that. ( For performance and code simplification // reasons. ) int flags; PickInfo pickInfo = new PickInfo(); Transform3D localToVworld = path.getTransform(); if (localToVworld == null) { throw new RuntimeException(J3dI18N.getString("MorphRetained5")); } pickInfo.setLocalToVWorldRef( localToVworld); //System.err.println("MorphRetained.intersect() : "); if (dist == null) { //System.err.println(" no dist request ...."); return intersect(pickInfo, pickShape, 0); } flags = PickInfo.CLOSEST_DISTANCE; if (intersect(pickInfo, pickShape, flags)) { dist[0] = pickInfo.getClosestDistance(); return true; } return false; } /** * Sets the Morph node's weight vector * @param wieghts the new vector of weights for the morph node */ void setWeights(double weights[]) { int i; double sum= 0.0; if (weights.length != numGeometryArrays) throw new IllegalArgumentException(J3dI18N.getString("MorphRetained7")); for (i=weights.length-1; i>=0; i--) { sum += weights[i]; } if (Math.abs(sum - 1.0) > TOLERANCE) throw new IllegalArgumentException(J3dI18N.getString("MorphRetained8")); // Weights array is ALWAYS malloced in setGeometryArrays method for (i=numGeometryArrays-1; i>=0; i--) this.weights[i] = weights[i]; if (source.isLive()) { ((GeometryArrayRetained)morphedGeometryArray.retained).updateData(this); J3dMessage mChangeMessage = null; mChangeMessage = new J3dMessage(); mChangeMessage.type = J3dMessage.MORPH_CHANGED; mChangeMessage.threads = (J3dThread.UPDATE_GEOMETRY | J3dThread.UPDATE_TRANSFORM); // If its a indexed geometry array, unindexify in renderBin if (this.geometryArrays[0] instanceof IndexedGeometryArrayRetained) mChangeMessage.threads |= J3dThread.UPDATE_RENDERING_ATTRIBUTES; mChangeMessage.args[0] = this; mChangeMessage.args[1]= new Integer(GEOMETRY_CHANGED); mChangeMessage.args[3] = Shape3DRetained.getGeomAtomsArray(mirrorShape3D); mChangeMessage.universe = universe; VirtualUniverse.mc.processMessage(mChangeMessage); } } /** * Retrieves the Morph node's weight vector * @return the morph node's weight vector. */ double[] getWeights() { return (double[]) weights.clone(); } /** * Gets the bounding object of a node. * @return the node's bounding object */ Bounds getBounds() { if(boundsAutoCompute) { GeometryArrayRetained mga = (GeometryArrayRetained)morphedGeometryArray.retained; if (mga != null) { synchronized(mga.geoBounds) { return (Bounds) mga.geoBounds.clone(); } } else { return null; } } else { return super.getBounds(); } } Bounds getEffectiveBounds() { if(boundsAutoCompute) { return getBounds(); } else { return super.getEffectiveBounds(); } } /** * ONLY needed for SHAPE, MORPH, and LINK node type. * Compute the combine bounds of bounds and its localBounds. */ void computeCombineBounds(Bounds bounds) { if(boundsAutoCompute) { GeometryArrayRetained mga = (GeometryArrayRetained)morphedGeometryArray.retained; if (mga != null) { synchronized(mga.geoBounds) { bounds.combine((Bounds) mga.geoBounds); } } } else { // Should this be lock too ? ( MT safe ? ) synchronized(localBounds) { bounds.combine((Bounds) localBounds); } } } // Return the number of geometry arrays in this MorphRetained object. int getNumGeometryArrays() { return numGeometryArrays; } // If the geometry of a morph changes, make sure that the // validVertexCount has not changed void updateMorphedGeometryArray(GeometryArrayRetained geo, boolean coordinatesChanged) { if (numGeometryArrays > 0) { // check if not the first geo, then compare with the first geometry if (geometryArrays[0] != geo) { doErrorCheck(geo, geometryArrays[0]); } else { // if first geo, compare with the second geo if (numGeometryArrays > 1) { doErrorCheck(geo, geometryArrays[1]); } } } ((GeometryArrayRetained)morphedGeometryArray.retained).updateData(this); // Compute the bounds once if (boundsAutoCompute && coordinatesChanged) { GeometryArrayRetained mga = (GeometryArrayRetained)morphedGeometryArray.retained; mga.incrComputeGeoBounds(); // This compute the bbox if dirty mga.decrComputeGeoBounds(); } } /** * Update GeometryArray computed by morphing input GeometryArrays * with weights */ public void updateData(Geometry mga) { int i,j,k, vFormat, geoType, stripVCount[]; int iCount = 0; int numStrips = 0; int texCoordSetCount = 0; float coord[] = new float[3], color[] = new float[4], normal[] = new float[3], texCoord[] = new float[3]; vFormat = geometryArrays[0].vertexFormat; geoType = ((GeometryArrayRetained)geometryArrays[0]).geoType; texCoordSetCount = geometryArrays[0].getTexCoordSetCount(); int vc = 0, nc = 0, cc = 0, n = 0; int count = 0; if (geometryArrays[0] instanceof IndexedGeometryArrayRetained){ count = geometryArrays[0].getNumCoordCount(); } else { count = geometryArrays[0].validVertexCount; } for (i=0; i < count; i++) { Mcoord[vc++] = Mcoord[vc++] = Mcoord[vc++] = 0.0f; } if ((vFormat & GeometryArray.COLOR) != 0) { if (geometryArrays[0] instanceof IndexedGeometryArrayRetained){ count = geometryArrays[0].getNumColorCount(); } else { count = geometryArrays[0].validVertexCount; } for (i=0; i < count; i++) { if ((vFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_3) Mcolor[cc++] = Mcolor[cc++] = Mcolor[cc++] = 0.0f; else if ((vFormat & GeometryArray.COLOR_4) == GeometryArray.COLOR_4) Mcolor[cc++] = Mcolor[cc++] = Mcolor[cc++] = Mcolor[cc++] = 0.0f; } } if ((vFormat & GeometryArray.NORMALS) != 0) { if (geometryArrays[0] instanceof IndexedGeometryArrayRetained){ count = geometryArrays[0].getNumNormalCount(); } else { count = geometryArrays[0].validVertexCount; } for (i=0; i < count; i++) { Mnormal[nc++] = Mnormal[nc++] = Mnormal[nc++] = 0.0f; } } if ((vFormat & GeometryArray.TEXTURE_COORDINATE) != 0) { for (k = 0; k < texCoordSetCount; k++) { if (geometryArrays[0] instanceof IndexedGeometryArrayRetained){ count = geometryArrays[0].getNumTexCoordCount(k); } else { count = geometryArrays[0].validVertexCount; } int tcount = 0; for (i=0; i < count; i++) { MtexCoord[k][tcount++] = MtexCoord[k][tcount++] = 0.0f; if ((vFormat & GeometryArray.TEXTURE_COORDINATE_3) != 0) { MtexCoord[k][tcount++] = 0.0f; } else if ((vFormat & GeometryArray.TEXTURE_COORDINATE_4) != 0) { MtexCoord[k][tcount++] = 0.0f; MtexCoord[k][tcount++] = 0.0f; } } } } // If by copy, then ... if ((vFormat & GeometryArray.BY_REFERENCE) == 0) { count = 0; for (j=0;j < numGeometryArrays;j++) { double w = weights[j]; if (w != 0) { vc = 0; nc = 0; cc = 0; int initialVertex = 0; if (geometryArrays[j] instanceof IndexedGeometryArrayRetained) { initialVertex = 0; count = geometryArrays[j].getNumCoordCount(); } else { initialVertex = geometryArrays[j].getInitialVertexIndex(); count = geometryArrays[j].validVertexCount; } int endVertex = initialVertex + count; for (i=initialVertex; i< endVertex; i++) { geometryArrays[j].getCoordinate(i, coord); Mcoord[vc++] += coord[0]*w; Mcoord[vc++] += coord[1]*w; Mcoord[vc++] += coord[2]*w; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -