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; }
// 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); }
/** Actually display the already created model */ public void showScene() { scene.compile(); uni.addBranchGraph(scene); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. uni.getViewingPlatform().setNominalViewingTransform(); uni.getViewer().getView().setFieldOfView(FIELD_OF_VIEW_RADIANS); uni.getViewer().getView().setFrontClipDistance(FRONT_CLIP_DISTANCE); }
// In this method, the objects for the scene are generated and added to // the SimpleUniverse. public void createSceneGraph(SimpleUniverse su) { // Create the root of the branch group for the scene. BranchGroup theScene = new BranchGroup(); // Generate an Appearance for the sphere. Color3f ambientColourSphere = new Color3f(0.2f, 0.2f, 0.2f); Color3f emissiveColourSphere = new Color3f(0.0f, 0.0f, 0.0f); Color3f diffuseColourSphere = new Color3f(0.6f, 0.6f, 0.6f); Color3f specularColourSphere = new Color3f(0.5f, 0.5f, 0.5f); float shininessSphere = 20.0f; Appearance sphereApp = new Appearance(); sphereApp.setMaterial( new Material( ambientColourSphere, emissiveColourSphere, diffuseColourSphere, specularColourSphere, shininessSphere)); // n spheres with radius r will be shown. int n = 5; float r = 0.15f; float shift = 2 * r + 0.05f; // The distance between the centres of the spheres. // Arrays for the sphere, their transformations and their transformation groups // transformation groups (for positioning). Sphere[] spheres = new Sphere[n]; TransformGroup[] tg = new TransformGroup[n]; Transform3D[] tf = new Transform3D[n]; // Generate the sphere, their transformations and their // transformation groups. Add everyting to the scene. for (int i = 0; i < n; i++) { spheres[i] = new Sphere(r, Sphere.GENERATE_NORMALS, 4 + i * i * i, sphereApp); tf[i] = new Transform3D(); tf[i].setTranslation(new Vector3f(-0.95f + r + shift * i, 0.0f, 0.0f)); tg[i] = new TransformGroup(tf[i]); tg[i].addChild(spheres[i]); theScene.addChild(tg[i]); } // 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), 1000.0); bg.setApplicationBounds(bounds); theScene.addChild(bg); theScene.compile(); // Add the scene to the universe. su.addBranchGraph(theScene); }
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); }
private BranchGroup setApperancePackInBranchGroup(Shape3D shape, Node handle) { shape.setUserData(this); shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); BranchGroup bg = new BranchGroup(); bg.setCapability(BranchGroup.ALLOW_DETACH); bg.addChild(handle); bg.compile(); return bg; }
public void init() { // initialize our SimpleUniverse -> u u = new SimpleUniverse(this); // set viewing platform (the camera) vp = u.getViewingPlatform(); view = u.getViewer().getView(); view.setScreenScalePolicy(View.SCALE_EXPLICIT); view.setBackClipPolicy(View.VIRTUAL_EYE); view.setFrontClipPolicy(View.VIRTUAL_EYE); view.setBackClipDistance(FARTHEST); view.setFrontClipDistance(CLOSEST); fieldOfView = view.getFieldOfView(); view.setDepthBufferFreezeTransparent(false); cameraTG = vp.getViewPlatformTransform(); cameraT3D = new Transform3D(); cameraTG.getTransform(cameraT3D); // initialize root of our scene -> BranchGroup kainBG and TransformGroup kainTG kainBG = new BranchGroup(); kainBG.setCapability(BranchGroup.ALLOW_CHILDREN_READ); kainBG.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); kainBG.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); background = new Background(new Color3f(0, 0, 0)); background.setCapability(Background.ALLOW_COLOR_READ); background.setCapability(Background.ALLOW_COLOR_WRITE); background.setCapability(Background.ALLOW_IMAGE_READ); background.setCapability(Background.ALLOW_IMAGE_WRITE); background.setApplicationBounds(new BoundingSphere(new Point3d(0, 0, 0), FARTHEST)); background.setImageScaleMode(Background.SCALE_FIT_ALL); kainBG.addChild(background); kainTG = new TransformGroup(); kainTG.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); kainTG.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE); kainBG.addChild(kainTG); // branch for axis lines axisBG = new BranchGroup(); axisBG.setCapability(BranchGroup.ALLOW_DETACH); axisLines = createAxisLines(); axisBG.addChild(axisLines); // branch for ground groundBG = new BranchGroup(); groundBG.setCapability(BranchGroup.ALLOW_DETACH); ground = createGround(); groundBG.addChild(ground); kainBG.compile(); u.addBranchGraph(kainBG); currentAppearance = Appearance3DChangerCookie.Appearance.WIREFRAME; }
private BranchGroup createSceneGraph() { BranchGroup root = new BranchGroup(); root.setCapability(BranchGroup.ALLOW_DETACH); createSpinTG(); root.addChild(spin); SimpleBehavior myRotationBehavior = new SimpleBehavior(spin); myRotationBehavior.setSchedulingBounds(new BoundingSphere()); root.addChild(myRotationBehavior); KeyNavigatorBehavior behavior = new KeyNavigatorBehavior(spin); BoundingSphere bounds = new BoundingSphere(); behavior.setSchedulingBounds(bounds); root.addChild(behavior); // mouse-directed rotation MouseRotate rotator = new MouseRotate(spin); rotator.setSchedulingBounds(bounds); root.addChild(rotator); // mouse-based translation MouseTranslate translator = new MouseTranslate(spin); translator.setSchedulingBounds(bounds); root.addChild(translator); // mouse-directed zoom MouseZoom zoom = new MouseZoom(); zoom.setSchedulingBounds(bounds); root.addChild(zoom); // make background blue Background background = new Background(Colors.blue); background.setApplicationBounds(bounds); root.addChild(background); // light AmbientLight light = new AmbientLight(true, new Color3f(Color.red)); light.setInfluencingBounds(bounds); root.addChild(light); PointLight ptlight = new PointLight(new Color3f(Color.red), new Point3f(0f, 0f, -5f), new Point3f(1f, 0f, 0f)); ptlight.setInfluencingBounds(bounds); root.addChild(ptlight); PointLight ptlight2 = new PointLight( new Color3f(Color.orange), new Point3f(-2f, 2f, 2f), new Point3f(1f, 0f, 0f)); ptlight2.setInfluencingBounds(bounds); root.addChild(ptlight2); // let Java3d perform optimization on this scene graph root.compile(); return root; }
public void activate() { viewGroup.compile(); objGroup.compile(); locale.addBranchGraph(viewGroup); locale.addBranchGraph(objGroup); }
private void start() throws PluginException, IfcModelInterfaceException { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try { setIconImage(ImageIO.read(getClass().getResource("haussmall.png"))); } catch (IOException e) { LOGGER.error("", e); } setSize(800, 600); getContentPane().setBackground(Color.BLACK); setTitle("IFC Visualiser"); setVisible(true); VirtualUniverse universe = new VirtualUniverse(); Locale locale = new Locale(universe); canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); sceneBranchGroup = new BranchGroup(); sceneBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); sceneBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); createLoaderSceneGraph(); locale.addBranchGraph(sceneBranchGroup); showLoader = true; new Thread() { public void run() { float x = 0; float y = 0; while (showLoader) { Matrix3f matrixX = new Matrix3f(); matrixX.rotX(x); Matrix3f matrixY = new Matrix3f(); matrixY.rotY(y); Matrix3f rot = new Matrix3f(); rot.mul(matrixX, matrixY); Transform3D transform3d = new Transform3D(); transform3d.setRotation(rot); transform3d.setTranslation(new Vector3d(10, 0, 0)); loaderTransformGroup.setTransform(transform3d); y -= 0.05; x += 0.015; try { Thread.sleep(25); } catch (InterruptedException e) { LOGGER.error("", e); } } }; }.start(); viewBranchGroup = new BranchGroup(); createViewBranch(); viewBranchGroup.compile(); locale.addBranchGraph(viewBranchGroup); add(canvas, BorderLayout.CENTER); canvas.setVisible(true); validate(); sharedGroup = new SharedGroup(); try { pluginManager = LocalDevPluginLoader.createPluginManager(new File("home")); } catch (PluginException e) { LOGGER.error("", e); } DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", true); Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration()); deserializer.init(pluginManager.requireSchemaDefinition()); File file = new File("../TestData/data/AC11-Institute-Var-2-IFC.ifc"); try { model = deserializer.read(file); } catch (DeserializationException e) { LOGGER.error("", e); } catch (Exception e) { LOGGER.error("", e); } ifcEngine = pluginManager.requireRenderEngine().createRenderEngine(new PluginConfiguration()); ifcEngine.init(); try { ifcEngineModel = ifcEngine.openModel(file); try { RenderEngineSurfaceProperties initializeModelling = ifcEngineModel.initializeModelling(); geometry = ifcEngineModel.finalizeModelling(initializeModelling); createSceneGraph(); } finally { ifcEngineModel.close(); } } finally { ifcEngine.close(); } }