private void createLoaderSceneGraph() { loaderBranchGroup = new BranchGroup(); loaderBranchGroup.setCapability(BranchGroup.ALLOW_DETACH); loaderTransformGroup = new TransformGroup(); loaderTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); addLights(loaderBranchGroup); Appearance loaderAppearance = new Appearance(); Color3f loaderColor = new Color3f(0.5f, 0.5f, 0.5f); Material loaderMaterial = new Material(loaderColor, new Color3f(), loaderColor, loaderColor, 10); loaderMaterial.setLightingEnable(true); loaderAppearance.setMaterial(loaderMaterial); for (int i = 0; i < 20; i++) { Transform3D translate3d = new Transform3D(); translate3d.setTranslation(new Vector3f(0f, 0f, 0.9f)); TransformGroup translate = new TransformGroup(translate3d); Transform3D rotationY3d = new Transform3D(); rotationY3d.rotY((Math.PI * 2 * i) / 20); TransformGroup rotateY = new TransformGroup(rotationY3d); rotateY.addChild(translate); Box box = new Box(0.1f, 0.1f, 0.1f, loaderAppearance); translate.addChild(box); loaderTransformGroup.addChild(rotateY); } loaderBranchGroup.addChild(loaderTransformGroup); sceneBranchGroup.addChild(loaderBranchGroup); }
// In this method, the objects for the scene are generated and added to // the SimpleUniverse. public void createSceneGraph(SimpleUniverse su) { // *** The root of the graph containing the scene (with a cube and a sphere). *** BranchGroup theScene = new BranchGroup(); // Generate an Appearance. Color3f ambientColourShaded = new Color3f(0.0f, 0.4f, 0.4f); Color3f emissiveColourShaded = new Color3f(0.0f, 0.0f, 0.0f); Color3f diffuseColourShaded = new Color3f(0.0f, 0.7f, 0.7f); Color3f specularColourShaded = new Color3f(0.0f, 0.5f, 0.5f); float shininessShaded = 20.0f; Appearance shadedApp = new Appearance(); shadedApp.setMaterial( new Material( ambientColourShaded, emissiveColourShaded, diffuseColourShaded, specularColourShaded, shininessShaded)); float r = 0.3f; // The radius of the sphere. float boxHL = 0.7f * r; // Half the vertex length of the cube. float shift = 3.0f * r; // Distance between cube and sphere. // *** The sphere and its transformation group *** Sphere s = new Sphere(r, Sphere.GENERATE_NORMALS, 100, shadedApp); Transform3D tfSphere = new Transform3D(); tfSphere.setTranslation(new Vector3f(-0.95f + r, 0.0f, 0.0f)); TransformGroup tgSphere = new TransformGroup(tfSphere); tgSphere.addChild(s); theScene.addChild(tgSphere); // *** The cube and its transformation group *** Box b2 = new Box(boxHL, boxHL, boxHL, shadedApp); Transform3D tfBox2 = new Transform3D(); tfBox2.setTranslation(new Vector3f(-0.95f + r + shift, 0.0f, 0.0f)); Transform3D rotation = new Transform3D(); rotation.rotY(Math.PI / 4); Transform3D rotationX = new Transform3D(); rotationX.rotX(Math.PI / 6); rotation.mul(rotationX); tfBox2.mul(rotation); TransformGroup tgBox2 = new TransformGroup(tfBox2); tgBox2.addChild(b2); theScene.addChild(tgBox2); // Generate a white background. Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f)); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Double.MAX_VALUE); bg.setApplicationBounds(bounds); theScene.addChild(bg); theScene.compile(); // Add the scene to the universe. su.addBranchGraph(theScene); }
/** @see boogiepants.model.Displayable#display() */ public Node display() { Appearance a = new Appearance(); Group shape = new Sphere(.15f, a); a.setColoringAttributes(new ColoringAttributes(.5f, .5f, 1f, ColoringAttributes.NICEST)); a.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST, .3f)); Transform3D t = new Transform3D(); if (loPoint == null) { loPoint = new Point3d(0d, 0d, 0d); } t.set(new Vector3d(loPoint.x, loPoint.y, loPoint.z)); transformGroupLo = new TransformGroup(); transformGroupLo.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); transformGroupLo.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); transformGroupLo.setTransform(t); transformGroupLo.addChild(shape); loEndpoint = endpoint(loPoint, transformGroupLo); Shape3D geom = (Shape3D) shape.getChild(0); geom.setUserData(loEndpoint); a = new Appearance(); shape = new Sphere(.15f, a); a.setColoringAttributes(new ColoringAttributes(1f, .5f, .5f, ColoringAttributes.NICEST)); a.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST, .3f)); t = new Transform3D(); if (hiPoint == null) { hiPoint = new Point3d(0d, 0d, 0d); } t.set(new Vector3d(hiPoint.x, hiPoint.y, hiPoint.z)); transformGroupHi = new TransformGroup(); transformGroupHi.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); transformGroupHi.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); transformGroupHi.setTransform(t); transformGroupHi.addChild(shape); hiEndpoint = endpoint(hiPoint, transformGroupHi); geom = (Shape3D) shape.getChild(0); geom.setUserData(hiEndpoint); container = new BranchGroup(); container.setCapability(BranchGroup.ALLOW_DETACH); container.addChild(transformGroupHi); container.addChild(transformGroupLo); stickGroup = BoogiepantsDisplayWindow.getInstance().getStickGroup(); behavior = new ScaleInstrumentBehavior(oscaddress, loPoint, hiPoint, stickGroup); container.addChild(behavior); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); behavior.setSchedulingBounds(bounds); editGroup = new BranchGroup(); editGroup.setCapability(BranchGroup.ALLOW_DETACH); editGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); editGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); container.addChild(editGroup); behavior.computeLineLen(); return container; }
public void draw(DrawModel d) { view.detach(); rotation.removeAllChildren(); drawModel = d; if (drawModel.getPicture() == null) return; Integer i = 0; for (VisualShape v : drawModel.getPicture()) { TransformGroup shapeGroup = new TransformGroup(); rotation.addChild(shapeGroup); BranchGroup faces = v.getFaces2(BranchGroup.class); BranchGroup edges = v.getEdges2(BranchGroup.class); BranchGroup text = v.getText2(BranchGroup.class); if (faces == null && edges == null) continue; i++; if (faces != null) { faces.detach(); rotation.addChild(faces); faces.setPickable(true); faces.setUserData(v); faces.setCapability(TransformGroup.ENABLE_PICK_REPORTING); faces.setName(i.toString()); } if (edges != null) { edges.detach(); rotation.addChild(edges); edges.setPickable(true); edges.setUserData(v); edges.setCapability(TransformGroup.ENABLE_PICK_REPORTING); edges.setName(i.toString()); } if (text != null) { text.detach(); rotation.addChild(text); text.setPickable(false); if (text instanceof BranchGroup) { BranchGroup bg = (BranchGroup) text; for (int j = 0; j < bg.numChildren(); j++) { Node child = bg.getChild(j); if (child instanceof TransformGroup) { TransformGroup tg = (TransformGroup) child; tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); textLabels.add(tg); } } } // edges.setUserData(v); // edges.setCapability(TransformGroup.ENABLE_PICK_REPORTING); // edges.setName(i.toString()); } } root.addChild(view); }
/** Constructor that creates a group with its transformations */ public SMGroup() { _rotation = new TransformGroup(); _translation = new TransformGroup(); _scale = new TransformGroup(); _child = new BranchGroup(); // Constructs the tree of the SMGroup super.addChild(_translation); _translation.addChild(_rotation); _rotation.addChild(_scale); _scale.addChild(_child); }
public BranchGroup addTriangle(Simplex simplex, Color3f color) { int[] p = simplex.getPoints(); BranchGroup bgTriangle = new BranchGroup(); bgTriangle.setCapability(BranchGroup.ALLOW_DETACH); javax.vecmath.Point3d[] coords = new javax.vecmath.Point3d[6]; TriangleArray ta = new TriangleArray(6, TriangleArray.COORDINATES | TriangleArray.COLOR_3); Point3d p0 = (Point3d) complex.getPoints().get(simplex.getPoints()[0]); Point3d p1 = (Point3d) complex.getPoints().get(simplex.getPoints()[1]); Point3d p2 = (Point3d) complex.getPoints().get(simplex.getPoints()[2]); coords[0] = new javax.vecmath.Point3d(p0.getX(), p0.getY(), p0.getZ()); coords[1] = new javax.vecmath.Point3d(p1.getX(), p1.getY(), p1.getZ()); coords[2] = new javax.vecmath.Point3d(p2.getX(), p2.getY(), p2.getZ()); coords[3] = new javax.vecmath.Point3d(p0.getX(), p0.getY(), p0.getZ()); coords[4] = new javax.vecmath.Point3d(p2.getX(), p2.getY(), p2.getZ()); coords[5] = new javax.vecmath.Point3d(p1.getX(), p1.getY(), p1.getZ()); ta.setCoordinates(0, coords); Color3f[] colors = new Color3f[6]; for (int i = 0; i < 3; i++) colors[i] = Colors.black; for (int i = 3; i < 6; i++) colors[i] = Colors.yellow; ta.setColors(0, colors); Appearance ap = new Appearance(); ap.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ); ap.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE); ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ); ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE); ap.setLineAttributes(new LineAttributes(2, LineAttributes.PATTERN_SOLID, false)); ap.setMaterial(new Material()); ap.setTransparencyAttributes( new TransparencyAttributes(TransparencyAttributes.SCREEN_DOOR, 0.5f)); Shape3D shape = new Shape3D(ta, ap); shape.setCapability(Shape3D.ALLOW_APPEARANCE_READ); shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); simplex.setTriangle(shape); // simplex.bgTriangle = bgTriangle; TransformGroup tgTriangle = new TransformGroup(); tgTriangle.addChild(shape); bgTriangle.addChild(tgTriangle); spin.addChild(bgTriangle); return bgTriangle; }
public BranchGroup addSphere(geom3d.Point3d p, double radius, Color3f color) { BranchGroup bgSphere = new BranchGroup(); bgSphere.setCapability(BranchGroup.ALLOW_DETACH); Appearance ap = new Appearance(); ap.setColoringAttributes(new ColoringAttributes(color, ColoringAttributes.NICEST)); ap.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST, 0.5f)); Sphere sphere = new Sphere(new Float(radius), ap); Transform3D tr = new Transform3D(); tr.setTranslation(new javax.vecmath.Vector3d(p.getX(), p.getY(), p.getZ())); TransformGroup tgSphere = new TransformGroup(tr); tgSphere.addChild(sphere); bgSphere.addChild(tgSphere); spin.addChild(bgSphere); return bgSphere; }
private void loadSheep() { VrmlLoader loader = new VrmlLoader(); Scene myScene = null; try { myScene = loader.load("models" + File.separator + "Sheep.wrl"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IncorrectFormatException e) { e.printStackTrace(); } catch (ParsingErrorException e) { e.printStackTrace(); } BranchGroup bg = new BranchGroup(); TransformGroup offset = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setRotation(new AxisAngle4d(1.0, 0.0, 0.0, Math.PI / 2)); t3d.setTranslation(new Vector3d(0.0, 0.0, 0.025)); offset.setTransform(t3d); bg.addChild(offset); offset.addChild(myScene.getSceneGroup()); sheepObject = new ModelObject(bg); viewer.addObject(sheepObject); }
/** set up canvas to display all faces. */ protected void setupWholeSphere() { if (allView && allGroup != null) allGroup.detach(); allGroup = new BranchGroup(); int nfaces = 12; try { theMap = theMap.regrade(nside); } catch (Exception e) { new Exception("Regrading failed", e); } // Find map min and max double min = theMap.getMin(); double max = theMap.getMax(); System.out.println("********** #Min(0)=" + min); System.out.println("********** #Max(0)=" + max); HealpixBase index = null; try { index = new HealpixBase(theMap.nside(), Scheme.NESTED); } catch (Exception e) { e.printStackTrace(); } for (int f = 0; f < nfaces; f++) { HealSphere face = new DataSphere(f, theMap, 0, min, max, index); setAppearance(face); allGroup.addChild(face); } allGroup.setCapability(BranchGroup.ALLOW_DETACH); objTrans.addChild(allGroup); if (!allView) allGroup.detach(); }
@Override public final TransformGroup getNode() { TransformGroup tg = super.getNode(); ArrayList<KeyFrameObj> frames = this.getFrames(); float[] knots = new float[frames.size()]; Point3f[] positions = new Point3f[frames.size()]; for (int i = 0; i < knots.length; i++) { KeyFrameObj f = frames.get(i); knots[i] = f.getKnots(); // System.out.println(knots[i]); positions[i] = f.getPoint3f(); } // frames = null; PositionPathInterpolator interpolator = new PositionPathInterpolator(getAlpha(), tg, getAxis(), knots, positions); interpolator.setSchedulingBounds(bound); tg.addChild(interpolator); // System.out.println("a"); return tg; // g.addChild(getTransformGroup()); }
/** * Ad block with default size of 50cm x 50cm x 50cm * * @param material - name of material. Must be rom World._availableMaterials list. * @param startCoordinates - given in cells unit */ public void addNewBlock(Model.Material material, Vector3d startCoordinates, Point3d blocSize) { BranchGroup childBG = new BranchGroup(); TransformGroup tg = new TransformGroup(); Transform3D transform = new Transform3D(); Vector3d vector = new Vector3d(startCoordinates.x, startCoordinates.y, startCoordinates.z); transform.setTranslation(vector); tg.setTransform(transform); Appearance app = new Appearance(); Color3f cellColor = new Color3f(); // float transparency = 0.8f; cellColor = material.get_color(); float transparency = material.get_transparency(); ColoringAttributes coloringAttributes = new ColoringAttributes(cellColor, ColoringAttributes.NICEST); app.setColoringAttributes(coloringAttributes); app.setTransparencyAttributes( new TransparencyAttributes(TransparencyAttributes.FASTEST, transparency)); tg.addChild( new Box( (float) (blocSize.x / 2), (float) (blocSize.z / 2), (float) (blocSize.y / 2), Box.ENABLE_APPEARANCE_MODIFY, app)); tg.getChild(0).setCapability(Box.ENABLE_APPEARANCE_MODIFY); childBG.addChild(tg); _startsOfBlocks.add(vector); childBG.setCapability(BranchGroup.ALLOW_DETACH); _contents.addChild(childBG); }
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create the TransformGroup node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at run time. Add it to // the root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans); // Create a simple Shape3D node; add it to the scene graph. objTrans.addChild(new ColorCube(0.4)); // Create a new Behavior object that will perform the // desired operation on the specified transform and add // it into the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, 4000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 1.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objRoot.addChild(rotator); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
/** * This method creates a planar polygon shape with lava texture. * * @param radius a float for the size of the base polygon. * @param divisions an int for the number of divisons. * @param appearance an Appearance object. * @return Node a polygon. */ private Node createShape(final float radius, final int divisions) { TriangleFanArray geometry = new TriangleFanArray( divisions, TriangleFanArray.COORDINATES | TriangleFanArray.TEXTURE_COORDINATE_2, new int[] {divisions}); for (int i = 0; i < divisions; i++) { float baseX = (float) Math.cos(2 * Math.PI * i / divisions); float baseZ = -(float) Math.sin(2 * Math.PI * i / divisions); geometry.setCoordinate(i, new Point3f(radius * baseX, 0, radius * baseZ)); geometry.setTextureCoordinate(0, i, new TexCoord2f((baseX + 1) / 2, (-baseZ + 1) / 2)); } GeometryInfo gInfo = new GeometryInfo(geometry); new NormalGenerator().generateNormals(gInfo); gInfo.convertToIndexedTriangles(); Shape3D fin = new Shape3D(gInfo.getGeometryArray()); PolygonAttributes polyAttr = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0); my_appearance.setPolygonAttributes(polyAttr); geometry.setCapability(Geometry.ALLOW_INTERSECT); fin = new Shape3D(geometry, my_appearance); Transform3D rotate = new Transform3D(); rotate.rotY(Math.PI / 4); TransformGroup tg = new TransformGroup(rotate); tg.addChild(fin); return tg; }
/** * Specify whether to make equator visible. * * @param b whether visible. */ public void setViewEquator(boolean b) { if (b) { if (!equatorView) objTrans.addChild(equatorGroup); } else { if (equatorView) equatorGroup.detach(); } equatorView = b; }
/** * Specify whether to make axes visible. * * @param b whether visible. */ public void setViewAxis(boolean b) { if (b) { if (!axisView) objTrans.addChild(axisGroup); } else { if (axisView) axisGroup.detach(); } axisView = b; }
/** * Specify whether to make the view of a single face visible. * * @param b whether visible. */ public void setViewSpecificFace(boolean b) { if (b) { if (loneFaceGroup == null) setFace(faceNo); if (!loneFaceView && loneFaceGroup != null) objTrans.addChild(loneFaceGroup); } else { if (loneFaceView && loneFaceGroup != null) loneFaceGroup.detach(); } loneFaceView = b; }
/** * Specify whether to make a view of the whole sphere visible. * * @param b whether visible. */ public void setViewWholeSphere(boolean b) { if (b) { if (allGroup == null && theMap != null) setupWholeSphere(); if (!allView && allGroup != null) objTrans.addChild(allGroup); } else { if (allGroup != null && allView) allGroup.detach(); } allView = b; }
public void addSphere(Simplex simplex, double radius, Color3f color) { geom3d.Point3d p = (Point3d) complex.getPoints().get(simplex.getPoints()[0]); BranchGroup bgSphere = new BranchGroup(); bgSphere.setCapability(BranchGroup.ALLOW_DETACH); Appearance ap = new Appearance(); ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ); ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE); ap.setColoringAttributes(new ColoringAttributes(color, ColoringAttributes.NICEST)); simplex.setSphere(new Sphere(new Float(radius), ap)); simplex.getSphere().getShape().setCapability(Shape3D.ALLOW_APPEARANCE_READ); simplex.getSphere().getShape().setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); Transform3D tr = new Transform3D(); tr.setTranslation(new javax.vecmath.Vector3d(p.getX(), p.getY(), p.getZ())); TransformGroup tgSphere = new TransformGroup(tr); tgSphere.addChild(simplex.getSphere()); bgSphere.addChild(tgSphere); spin.addChild(bgSphere); }
/** * Adds a SMRotationInterpolator Behavior to the SMGroup * * @param duration * @param start * @param rotXAxis Angle about x in which the axis of rotation is going to be rotated * @param rotYAxis Angle about y in which the axis of rotation is going to be rotated * @param rotZAxis Angle about z in which the axis of rotation is going to be rotated * @param startAngle * @param finsishAngle */ public void addRotationAnim( long duration, long start, double rotXAxis, double rotYAxis, double rotZAxis, float startAngle, float finishAngle) { // Creates a necessary TransformGroup for the SMRotationInterpolator TransformGroup tg = new TransformGroup(); // Adds the animation between the child and it Parent Group parent = (Group) _child.getParent(); parent.removeChild(_child); tg.addChild(_child); parent.addChild(tg); // Allows writing on TransfomGroup tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // Creates an Alpha function Alpha rotationAlpha = new Alpha(1, duration); rotationAlpha.setStartTime(System.currentTimeMillis() + start); // Calculates the axis of rotation Transform3D rX = new Transform3D(); Transform3D rY = new Transform3D(); Transform3D rZ = new Transform3D(); rX.rotX(rotXAxis); rY.rotY(rotYAxis); rZ.rotZ(rotZAxis); rY.mul(rZ); rX.mul(rY); // Creates the SMRotationInterpolator SMRotationInterpolator rotator = new SMRotationInterpolator(rotationAlpha, tg, rX, startAngle, finishAngle, start); // Sets the area to render rotator.setSchedulingBounds(_bounds); // Adds the rotation animation to the TransformGroup tg.addChild(rotator); }
public ObjectViewer(URL url) { setLayout(new BorderLayout()); Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); add("Center", canvas3D); BoundingSphere bounds = new BoundingSphere(new Point3d(), 1000); BranchGroup root = new BranchGroup(); BranchGroup scene = createSceneGraph(url); scene.setBoundsAutoCompute(true); System.out.println(scene.getBounds()); BoundingSphere sceneBounds = new BoundingSphere(scene.getBounds()); SimpleUniverse univ = new SimpleUniverse(canvas3D); ViewingPlatform view = univ.getViewingPlatform(); view.setNominalViewingTransform(); Transform3D t = new Transform3D(); TransformGroup viewTransform = view.getViewPlatformTransform(); t.set(new Vector3d(0, 0, 3 * sceneBounds.getRadius())); viewTransform.setTransform(t); BranchGroup lights = new BranchGroup(); Light light = new AmbientLight(); light.setInfluencingBounds(bounds); lights.addChild(light); light = new DirectionalLight(); light.setInfluencingBounds(bounds); lights.addChild(light); root.addChild(lights); TransformGroup tg = new TransformGroup(); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tg.addChild(scene); root.addChild(tg); MouseRotate mouse = new MouseRotate(); mouse.setTransformGroup(tg); mouse.setSchedulingBounds(bounds); root.addChild(mouse); MouseZoom mousezoom = new MouseZoom(); mousezoom.setTransformGroup(tg); mousezoom.setSchedulingBounds(bounds); root.addChild(mousezoom); Background background = new Background(1, 1, 1); background.setApplicationBounds(bounds); root.addChild(background); root.compile(); univ.addBranchGraph(root); }
protected void createViewBranch() { TransformGroup viewTG = new TransformGroup(); viewTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); ViewPlatform viewPlatform = new ViewPlatform(); view = new View(); view.setBackClipDistance(30000); view.addCanvas3D(canvas); view.setPhysicalBody(new PhysicalBody()); view.setPhysicalEnvironment(new PhysicalEnvironment()); view.attachViewPlatform(viewPlatform); float halfRadius = (float) (getBoundingSphere(sceneBranchGroup).getRadius() / 2f); Point3d center = new Point3d(); getBoundingSphere(sceneBranchGroup).getCenter(center); BoundingSphere globalBounds = new BoundingSphere(); globalBounds.setRadius(Double.MAX_VALUE); orbitBehaviorInterim = new OrbitBehaviorInterim( canvas, viewTG, OrbitBehaviorInterim.REVERSE_ROTATE | OrbitBehaviorInterim.REVERSE_TRANSLATE); orbitBehaviorInterim.setRotationCenter(center); orbitBehaviorInterim.setViewingTransform( new Point3d( halfRadius, getViewPlatformDistance(sceneBranchGroup, canvas, view), halfRadius), center, new Vector3d(0, -1, 0), true); orbitBehaviorInterim.setVpView(view); orbitBehaviorInterim.setTransFactors(3.0, 3.0); orbitBehaviorInterim.setSchedulingBounds(globalBounds); viewTG.addChild(viewPlatform); viewTG.addChild(orbitBehaviorInterim); viewBranchGroup.addChild(viewTG); }
public void addLinesAroundRegion(TransformGroup tg) { Color3f x = new Color3f(Color.green.brighter().brighter()); Color3f y = new Color3f(Color.yellow.brighter().brighter()); Color3f z = new Color3f(Color.red.brighter().brighter()); LineArray wireframe = new LineArray(12 * 2, GeometryArray.COORDINATES | GeometryArray.COLOR_3); wireframe.setCapability(LineArray.ALLOW_COLOR_WRITE); wireframe.setCapability(LineArray.ALLOW_COORDINATE_READ); wireframe.setCapability(LineArray.ALLOW_COUNT_READ); ArrayList<Point3f> vx = getVertices(); // Add lines parallel to x wireframe.setCoordinate(0, vx.get(0)); wireframe.setCoordinate(1, vx.get(2)); wireframe.setCoordinate(2, vx.get(1)); wireframe.setCoordinate(3, vx.get(3)); wireframe.setCoordinate(4, vx.get(4)); wireframe.setCoordinate(5, vx.get(6)); wireframe.setCoordinate(6, vx.get(5)); wireframe.setCoordinate(7, vx.get(7)); for (int i = 0; i < 8; i++) wireframe.setColor(i, x); // Add lines parallel to y wireframe.setCoordinate(8, vx.get(0)); wireframe.setCoordinate(9, vx.get(4)); wireframe.setCoordinate(10, vx.get(1)); wireframe.setCoordinate(11, vx.get(5)); wireframe.setCoordinate(12, vx.get(2)); wireframe.setCoordinate(13, vx.get(6)); wireframe.setCoordinate(14, vx.get(3)); wireframe.setCoordinate(15, vx.get(7)); for (int i = 8; i < 16; i++) wireframe.setColor(i, y); // Add lines parallel to z wireframe.setCoordinate(16, vx.get(0)); wireframe.setCoordinate(17, vx.get(1)); wireframe.setCoordinate(18, vx.get(2)); wireframe.setCoordinate(19, vx.get(3)); wireframe.setCoordinate(20, vx.get(4)); wireframe.setCoordinate(21, vx.get(5)); wireframe.setCoordinate(22, vx.get(6)); wireframe.setCoordinate(23, vx.get(7)); for (int i = 16; i < 24; i++) wireframe.setColor(i, z); Shape3D shape = new Shape3D(wireframe); tg.addChild(shape); }
private TransformGroup makeText(Vector3d vertex, String text) // Create a Text2D object at the specified vertex { Text2D message = new Text2D(text, white, "SansSerif", 36, Font.BOLD); // 36 point bold Sans Serif TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(vertex); tg.setTransform(t3d); tg.addChild(message); return tg; } // end of getTG()
// Directional light rotating around the scene and some ambient light. public void addLight(SimpleUniverse su) { BranchGroup bgLight = new BranchGroup(); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Double.MAX_VALUE); // Directional light (to be rotated). Color3f lightColour = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lightDir = new Vector3f(0.0f, 0.0f, -1.0f); DirectionalLight light = new DirectionalLight(lightColour, lightDir); light.setInfluencingBounds(bounds); // The transformation group for the directional light and its rotation. TransformGroup tfmLight = new TransformGroup(); tfmLight.addChild(light); // The Alpha for the rotation. Alpha alphaLight = new Alpha(-1, 4000); // The rotation RotationInterpolator rot = new RotationInterpolator( alphaLight, tfmLight, new Transform3D(), 0.0f, (float) Math.PI * 2); rot.setSchedulingBounds(bounds); tfmLight.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tfmLight.addChild(rot); bgLight.addChild(tfmLight); // Ambient light. Color3f ambientLightColour = new Color3f(0.5f, 0.5f, 0.5f); AmbientLight ambLight = new AmbientLight(ambientLightColour); ambLight.setInfluencingBounds(bounds); bgLight.addChild(ambLight); su.addBranchGraph(bgLight); }
private void createSceneGraph() throws PluginException, IfcModelInterfaceException { buildingTransformGroup = new TransformGroup(); Set<Class<? extends IfcRoot>> classesToConvert = new HashSet<Class<? extends IfcRoot>>(); classesToConvert.add(IfcWall.class); classesToConvert.add(IfcWallStandardCase.class); classesToConvert.add(IfcWindow.class); classesToConvert.add(IfcOpeningElement.class); classesToConvert.add(IfcSlab.class); classesToConvert.add(IfcRoof.class); classesToConvert.add(IfcColumn.class); classesToConvert.add(IfcSpace.class); classesToConvert.add(IfcDoor.class); classesToConvert.add(IfcRailing.class); classesToConvert.add(IfcFurnishingElement.class); classesToConvert.add(IfcStair.class); classesToConvert.add(IfcBeam.class); classesToConvert.add(IfcFlowTerminalType.class); classesToConvert.add(IfcDistributionFlowElement.class); classesToConvert.add(IfcSite.class); // classesToConvert.add(IfcProxy.class); for (IdEObject idEObject : model.getValues()) { if (classesToConvert.contains(idEObject.eClass().getInstanceClass())) { setGeometry((IfcRoot) idEObject); } } buildingBranchGroup = new BranchGroup(); addLights(buildingBranchGroup); buildingBranchGroup.addChild(buildingTransformGroup); showLoader = false; sceneBranchGroup.removeChild(loaderBranchGroup); sharedGroup.addChild(buildingBranchGroup); // for (int x = 0; x < 5; x++) { // for (int y = 0; y < 5; y++) { Link link1 = new Link(sharedGroup); Transform3D t3d1 = new Transform3D(); // t3d1.setTranslation(new Vector3f(x * 20, y * 20, 0f)); BranchGroup x1 = new BranchGroup(); TransformGroup t1 = new TransformGroup(t3d1); x1.addChild(t1); t1.addChild(link1); sceneBranchGroup.addChild(x1); // } // } reInitView(); }
public CubeBehavior(Cubie[] cubies, double viewDistance) { this.cubies = cubies; this.initialCubies = new Cubie[this.cubies.length]; this.rubikCube = new TransformGroup(); for (int i = 0; i < this.cubies.length; i++) { initialCubies[i] = cubies[i]; rubikCube.addChild(cubies[i]); } viewTransform = new ViewPoint(viewDistance); wakeUp = new WakeupOnElapsedFrames(0); running = false; command = new LinkedList<Command>(); currentCommand = NOP; counter = 0; }
@Deprecated public void addText2D(String text, Font font, Color3f color, Point3f position) { Text2D renderedText = new Text2D(text, color, font.getName(), font.getSize(), font.getStyle()); Transform3D transform = new Transform3D(); transform.setTranslation(new Vector3f(position)); TransformGroup transformations = new TransformGroup(); transformations.setTransform(transform); transformations.addChild(renderedText); PlatformGeometry platformGeometry = new PlatformGeometry(); platformGeometry.addChild(transformations); getViewingPlatform().setPlatformGeometry(platformGeometry); }
private void prepareGeometry() { displayedMenuItems.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); displayedMenuItems.setCapability(TransformGroup.ALLOW_CHILDREN_READ); displayedMenuItems.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE); displayedMenuItems.setCapability(BranchGroup.ALLOW_DETACH); menuItemsGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); menuItemsGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ); menuItemsGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE); menuItemsGroup.addChild(displayedMenuItems); menuItemsPosition.rotX(Math.PI / 2); menuItemsPosition.setTranslation(new Vector3d(0, 0, 0.025)); menuItemsGroup.setTransform(menuItemsPosition); addChild(menuItemsGroup); }
@SuppressWarnings("unchecked") public void saveAsFile() { TransformGroup themodel = lobj.getModel3D(); File file = showSaveImageDialog(); if (file != null) { BranchGroup scene = new BranchGroup(); render.removeObj3D(lobj); Enumeration<Group> enume = themodel.getAllChildren(); while (enume.hasMoreElements()) { Group next = enume.nextElement(); themodel.removeChild(next); scene.addChild(next); } // String file=this.getModel3DHref(); // file.replace(".3ds", ".j3d"); // OutputStream outS; try { SceneGraphFileWriter filew = new SceneGraphFileWriter(file, null, false, "genereted by Neptus", null); filew.writeBranchGraph(scene); System.err.println("vehicle w:" + file.getPath() + "\n"); filew.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedUniverseException e) { // TODO Auto-generated catch block e.printStackTrace(); } TransformGroup themodel2 = new TransformGroup(); enume = scene.getAllChildren(); while (enume.hasMoreElements()) { Group next = enume.nextElement(); scene.removeChild(next); themodel2.addChild(next); } lobj = new Obj3D(); lobj.setModel3D(themodel2); render.addObj3D(lobj); } }
public void prepareCorak( String projectPath, CorakLSystem cor, CorakDataObject obj, boolean encloseOBJ) { this.projectPath = projectPath; // initiate our "turtle" -> Canting canting = new Canting(cor, obj); // start creating shapes based on Cor timer = System.currentTimeMillis(); canting.generate(encloseOBJ); BoundingSphere lightingBounds = new BoundingSphere(new Point3d(0, 0, 0), FARTHEST); camLamp = new PointLight(); camLamp.setCapability(PointLight.ALLOW_POSITION_READ); camLamp.setCapability(PointLight.ALLOW_POSITION_WRITE); camLamp.setColor(new Color3f(1.0f, 1.0f, 1.0f)); camLamp.setInfluencingBounds(lightingBounds); ambient = new AmbientLight(); ambient.setColor(new Color3f(1.0f, 1.0f, 1.0f)); ambient.setInfluencingBounds(lightingBounds); canting.getBatikBG().addChild(camLamp); canting.getBatikBG().addChild(ambient); // attach generated shapes to root TransformGroup Enumeration kaintgchildren = kainTG.getAllChildren(); while (kaintgchildren.hasMoreElements()) { Node child = (Node) kaintgchildren.nextElement(); if (child instanceof Measurer) { ((Measurer) child).removeAllChildren(); } else { kainTG.removeChild(child); } } // canting.getBatikBG().compile(); kainTG.addChild(canting.getBatikBG()); timer = System.currentTimeMillis() - timer; // System.out.println("Timer= " + timer); bs = (BoundingSphere) canting.getBatikBG().getBounds(); }