📄 shape3dretained.java
字号:
if(newGeom != null) { newGeom.addUser(mS3d); } int gSize = geometryList.size(); for(i=0; i<gSize; i++) { geometry = (GeometryRetained) geometryList.get(i); if(geometry != null) { newGA.geoType = geometry.geoType; newGA.alphaEditable = mS3d.isAlphaEditable(geometry); break; } } if((geometry != null) && (geometry.geoType == GeometryRetained.GEO_TYPE_TEXT3D)) { for(i = 0; i<gSize; i++) { geometry = (GeometryRetained) geometryList.get(i); if(geometry != null) { Text3DRetained tempT3d = (Text3DRetained)geometry; geometryCnt += tempT3d.numChars; } else { // This is slightly wasteful, but not quite worth to optimize yet. geometryCnt++; } } newGA.geometryArray = new GeometryRetained[geometryCnt]; newGA.lastLocalTransformArray = new Transform3D[geometryCnt]; // Reset geometryCnt; geometryCnt = 0; } else { newGA.geometryArray = new GeometryRetained[gSize]; } newGA.locale = mS3d.locale; newGA.visible = visible; newGA.source = mS3d; for(gaCnt = 0; gaCnt<gSize; gaCnt++) { geometry = (GeometryRetained) geometryList.get(gaCnt); if(geometry == null) { newGA.geometryArray[geometryCnt++] = null; } else { if (geometry.geoType == GeometryRetained.GEO_TYPE_TEXT3D) { Text3DRetained t = (Text3DRetained)geometry; GeometryRetained geo; for (i=0; i<t.numChars; i++, geometryCnt++) { geo = t.geometryList[i]; if (geo!= null) { newGA.geometryArray[geometryCnt] = geo; newGA.lastLocalTransformArray[geometryCnt] = t.charTransforms[i]; } else { newGA.geometryArray[geometryCnt] = null; newGA.lastLocalTransformArray[geometryCnt] = null; } } } else { newGA.geometryArray[geometryCnt++] = geometry; } } } oldGAArray = new GeometryAtom[s3dMSize]; newGAArray = new GeometryAtom[s3dMSize]; oldGAArray[0] = oldGA; newGAArray[0] = newGA; mS3d.geomAtom = newGA; mS3d.mirrorShape3DLock.writeUnlock(); // ..... clone the rest of mirrorS3D's GA with the above newGA, but modify // its source. for (i = 1; i < s3dMSize; i++) { mS3d = (Shape3DRetained) mirrorShape3D.get(i); mS3d.mirrorShape3DLock.writeLock(); oldGA = mS3d.geomAtom; newGA = new GeometryAtom(); if(newGeom != null) { newGeom.addUser(mS3d); } newGA.geoType = newGAArray[0].geoType; newGA.locale = mS3d.locale; newGA.visible = visible; newGA.source = mS3d; newGA.alphaEditable = newGAArray[0].alphaEditable; newGA.geometryArray = new GeometryRetained[newGAArray[0].geometryArray.length]; for(j=0; j<newGA.geometryArray.length; j++) { newGA.geometryArray[j] = newGAArray[0].geometryArray[j]; } oldGAArray[i] = oldGA; newGAArray[i] = newGA; mS3d.geomAtom = newGA; mS3d.mirrorShape3DLock.writeUnlock(); } TargetsInterface ti = ((GroupRetained)parent).getClosestTargetsInterface( TargetsInterface.TRANSFORM_TARGETS); CachedTargets[] newCtArr = null; if (ti != null) { CachedTargets ct; newCtArr = new CachedTargets[s3dMSize]; for (i=0; i<s3dMSize; i++) { ct = ti.getCachedTargets( TargetsInterface.TRANSFORM_TARGETS, i, -1); if (ct != null) { newCtArr[i] = new CachedTargets(); newCtArr[i].copy(ct); newCtArr[i].replace(oldGAArray[i], newGAArray[i], Targets.GEO_TARGETS); } else { newCtArr[i] = null; } } ti.resetCachedTargets(TargetsInterface.TRANSFORM_TARGETS, newCtArr, -1); } J3dMessage changeMessage = new J3dMessage(); changeMessage.type = J3dMessage.SHAPE3D_CHANGED; // Who to send this message to ? changeMessage.threads = J3dThread.UPDATE_RENDER | J3dThread.UPDATE_TRANSFORM | J3dThread.UPDATE_GEOMETRY; changeMessage.universe = universe; changeMessage.args[0] = this; changeMessage.args[1] = new Integer(GEOMETRY_CHANGED); changeMessage.args[2] = oldGAArray; changeMessage.args[3] = newGAArray; if (ti != null) { changeMessage.args[4] = ti; changeMessage.args[5] = newCtArr; } if (boundsAutoCompute) { getCombineBounds((BoundingBox)localBounds); } VirtualUniverse.mc.processMessage(changeMessage); } // ********** End of New 1.2.1 code .... Shape3DRetained getMirrorShape(SceneGraphPath path) { if (!inSharedGroup) { return (Shape3DRetained) mirrorShape3D.get(0); } HashKey key = new HashKey(""); path.getHashKey(key); return getMirrorShape(key); } Shape3DRetained getMirrorShape(HashKey key) { if (key == null) { return (Shape3DRetained) mirrorShape3D.get(0); } else { int i = key.equals(localToVworldKeys, 0, localToVworldKeys.length); if (i>=0) { return (Shape3DRetained) mirrorShape3D.get(i); } } // Not possible throw new RuntimeException("Shape3DRetained: MirrorShape Not found!"); } void setBoundsAutoCompute(boolean autoCompute) { GeometryRetained geometry; if (autoCompute != boundsAutoCompute) { if (autoCompute) { // localBounds may not have been set to bbox localBounds = new BoundingBox((BoundingBox) null); if (source.isLive() && geometryList != null) { int size = geometryList.size()*mirrorShape3D.size(); for (int i=0; i<size; i++) { geometry = (GeometryRetained) geometryList.get(i); geometry.incrComputeGeoBounds(); } } getCombineBounds((BoundingBox)localBounds); } else { if (source.isLive() && geometryList != null) { int size = geometryList.size()*mirrorShape3D.size(); for (int i=0; i<size; i++) { geometry = (GeometryRetained) geometryList.get(i); geometry.decrComputeGeoBounds(); } } } super.setBoundsAutoCompute(autoCompute); if (source.isLive()) { J3dMessage message = new J3dMessage(); message.type = J3dMessage.BOUNDS_AUTO_COMPUTE_CHANGED; message.threads = J3dThread.UPDATE_TRANSFORM | J3dThread.UPDATE_GEOMETRY | J3dThread.UPDATE_RENDER; message.universe = universe; message.args[0] = getGeomAtomsArray(mirrorShape3D); // no need to clone localBounds message.args[1] = localBounds; VirtualUniverse.mc.processMessage(message); } } } // This method is called when coordinates of a geometry in the geometrylist // changed and autoBoundsCompute is true void updateBounds() { localBounds = new BoundingBox((BoundingBox) null); getCombineBounds((BoundingBox)localBounds); synchronized(mirrorShape3D) { if (source.isLive()) { J3dMessage message = new J3dMessage(); message.type = J3dMessage.BOUNDS_AUTO_COMPUTE_CHANGED; message.threads = J3dThread.UPDATE_TRANSFORM | J3dThread.UPDATE_GEOMETRY | J3dThread.UPDATE_RENDER; message.universe = universe; message.args[0] = getGeomAtomsArray(mirrorShape3D); // no need to clone localBounds message.args[1] = localBounds; VirtualUniverse.mc.processMessage(message); } } } boolean allowIntersect() { GeometryRetained ga = null; for(int i=0; i<geometryList.size(); i++) { ga = (GeometryRetained) geometryList.get(i); if(ga != null) if (!ga.source.getCapability(Geometry.ALLOW_INTERSECT)) { return false; } } return true; } boolean intersectGeometryList(Shape3DRetained otherShape) { GeometryRetained geom1, geom2; ArrayList gaList = otherShape.geometryList; int gaSize = gaList.size(); Transform3D otherLocalToVworld = otherShape.getCurrentLocalToVworld(); Transform3D thisLocalToVworld = getCurrentLocalToVworld(); View views = null; int primaryViewIdx = -1; if (this instanceof OrientedShape3DRetained) { primaryViewIdx = getPrimaryViewIdx(); thisLocalToVworld.mul(((OrientedShape3DRetained)this). getOrientedTransform(primaryViewIdx)); } if (otherShape instanceof OrientedShape3DRetained) { if (primaryViewIdx < 0) { primaryViewIdx = getPrimaryViewIdx(); } otherLocalToVworld.mul(((OrientedShape3DRetained)otherShape). getOrientedTransform(primaryViewIdx)); } for (int i=geometryList.size()-1; i >=0; i--) { geom1 = (GeometryRetained) geometryList.get(i); if (geom1 != null) { for (int j=gaSize-1; j >=0; j--) { geom2 = (GeometryRetained) gaList.get(j); if ((geom2 != null) && geom1.intersect(thisLocalToVworld, otherLocalToVworld, geom2)) { return true; } } } } return false; } boolean intersectGeometryList(Transform3D thisLocalToVworld, Bounds targetBound) { GeometryRetained geometry; if (this instanceof OrientedShape3DRetained) { Transform3D orientedTransform = ((OrientedShape3DRetained)this). getOrientedTransform(getPrimaryViewIdx()); thisLocalToVworld.mul(orientedTransform); } for (int i=geometryList.size() - 1; i >=0; i--) { geometry = (GeometryRetained) geometryList.get(i); if ((geometry != null) && geometry.intersect(thisLocalToVworld, targetBound)) { return true; } } return false; } /** * This initialize the mirror shape to reflect the state of the * real Morph. */ void initMirrorShape3D(SetLiveState s, MorphRetained morph, int index) { GeometryRetained geometry; GeometryAtom[] newGeometryAtoms = null; universe = morph.universe; inSharedGroup = morph.inSharedGroup; inBackgroundGroup = morph.inBackgroundGroup; geometryBackground = morph.geometryBackground; parent = morph.parent; locale = morph.locale; OrderedPath op = (OrderedPath)s.orderedPaths.get(index); if (op.pathElements.size() == 0) { orderedPath = null; } else { orderedPath = op; } staticTransform = morph.staticTransform; if (morph.boundsAutoCompute) { localBounds.set(morph.localBounds); } bounds = localBounds; vwcBounds = new BoundingBox((BoundingBox) null); vwcBounds.transform(bounds, getCurrentLocalToVworld(0)); if (morph.collisionBound == null) { collisionBound = null; collisionVwcBound = vwcBounds; } else { collisionBound = morph.collisionBound; collisionVwcBound = (Bounds)collisionBound.clone(); collisionVwcBound.transform(getCurrentLocalToVworld(0)); } appearanceOverrideEnable = morph.appearanceOverrideEnable; // mga is the final geometry we're interested. geometryList = new ArrayList(1); geometryList.add((GeometryArrayRetained)morph.morphedGeometryArray.retained); GeometryAtom gAtom = new GeometryAtom(); gAtom.geometryArray = new GeometryRetained[1]; gAtom.locale = locale; gAtom.visible = morph.visible; gAtom.source = this; geometry = (GeometryRetained) geometryList.get(0); if(geometry ==null) { gAtom.geometryArray[0] = null; } else { gAtom.geometryArray[0] = (GeometryArrayRetained)morph. morphedGeometryArray.retained; gAtom.geoType = gAtom.geometryArray[0].geoType; } geomAtom = gAtom; // Assign the parent of this mirror shape node sourceNode = morph; } // geometries in morph object is modified, update the geometry // list in the mirror shapes and the geometry array in the geometry atom void setMorphGeometry(Geometry geometry, ArrayList mirrorShapes) { GeometryAtom oldGA, newGA; Shape3DRetained ms; TransformGroupRetained tg; int nMirrorShapes = mirrorShapes.size(); int i; GeometryAtom oldGAArray[] = new GeometryAtom[nMirrorShapes]; GeometryAtom newGAArray[] = new GeometryAtom[nMirrorShapes]; for (i = 0; i < nMirrorShapes; i++) { ms = (Shape3DRetained) mirrorShapes.get(i); oldGA = Shape3DRetained.getGeomAtom(ms); ms.geometryList = new ArrayList(1); ms.geometryList.add((GeometryArrayRetained)geometry.retained); newGA = new GeometryAtom(); newGA.geometryArray = new GeometryRetained[1]; if (geometry ==null) { newGA.geometryArray[0] = null; } else { newGA.geometryArray[0] = (GeometryArrayRetained)geometry.retained; newGA.geoType = newGA.geometryArray[0].geoType; } newGA.locale = locale; newGA.visible = oldGA.visible; newGA.source = this; oldGAArray[i] = oldGA; newGAArray[i] = newGA; Shape3DRetained.setGeomAtom(ms, newGA); } TargetsInterface ti = ((GroupRetained)parent).getClosestTargetsInterface( TargetsInterface.TRANSFORM_TARGETS); CachedTargets[] newCtArr = null; if (ti != null) { CachedTargets ct; newCtArr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -