List of usage examples for javax.media.j3d LineArray LineArray
public LineArray(int vertexCount, int vertexFormat)
From source file:KeyNavigatorApp.java
Shape3D createLand() { LineArray landGeom = new LineArray(44, GeometryArray.COORDINATES | GeometryArray.COLOR_3); float l = -50.0f; for (int c = 0; c < 44; c += 4) { landGeom.setCoordinate(c + 0, new Point3f(-50.0f, 0.0f, l)); landGeom.setCoordinate(c + 1, new Point3f(50.0f, 0.0f, l)); landGeom.setCoordinate(c + 2, new Point3f(l, 0.0f, -50.0f)); landGeom.setCoordinate(c + 3, new Point3f(l, 0.0f, 50.0f)); l += 10.0f;//from w ww . j a v a 2 s. c om } Color3f c = new Color3f(0.1f, 0.8f, 0.1f); for (int i = 0; i < 44; i++) landGeom.setColor(i, c); return new Shape3D(landGeom); }
From source file:edu.uci.ics.jung.visualization3d.PluggableRenderContext.java
public PluggableRenderContext() { super();/*from w ww . j a v a 2s .c om*/ Color3f lightGray = new Color3f(0.7f, 0.7f, 0.7f); Color3f black = new Color3f(0, 0, 0); Color3f white = new Color3f(1, 1, 1); Color3f gray = new Color3f(.2f, .2f, .2f); Color3f red = new Color3f(1, 0, 0); Color3f yellow = new Color3f(0, 1, 1); Material lightGrayMaterial = new Material(lightGray, black, lightGray, white, 100.0f); Material blackMaterial = new Material(lightGray, black, black, lightGray, 10.0f); Material whiteMaterial = new Material(white, white, white, white, 100.0f); Material grayMaterial = new Material(gray, black, gray, gray, 100.0f); Material redMaterial = new Material(red, black, red, red, 100.0f); Material yellowMaterial = new Material(yellow, black, yellow, yellow, 100.0f); final Appearance lightGrayLook = new Appearance(); lightGrayLook.setMaterial(lightGrayMaterial); Appearance blackLook = new Appearance(); blackLook.setMaterial(blackMaterial); Appearance whiteLook = new Appearance(); whiteLook.setMaterial(whiteMaterial); Appearance grayLook = new Appearance(); grayLook.setMaterial(grayMaterial); // grayLook.setCapability(Appearance.ALLOW_MATERIAL_READ); // grayLook.setCapability(Appearance.ALLOW_MATERIAL_WRITE); final Appearance redLook = new Appearance(); redLook.setMaterial(redMaterial); final Appearance yellowLook = new Appearance(); yellowLook.setMaterial(yellowMaterial); final Cylinder cylinder = new Cylinder(1, 1, Cylinder.GENERATE_NORMALS | Cylinder.ENABLE_GEOMETRY_PICKING, 26, 26, lightGrayLook); final Sphere sphere = new Sphere(10, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, redLook); final Box box = new Box(10, 10, 10, Box.GENERATE_NORMALS | Box.ENABLE_GEOMETRY_PICKING, redLook); this.edgeAppearanceTransformer = new ConstantTransformer(lightGrayLook); this.edgeShapeTransformer = new Transformer<Context<Graph<V, E>, E>, Node>() { public Node transform(Context<Graph<V, E>, E> ec) { LineArray lineArray = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3); lineArray.setCoordinates(0, new Point3f[] { new Point3f(0, -.5f, 0), new Point3f(0, .5f, 0) }); lineArray.setColor(0, new Color3f(1, 1, 1)); lineArray.setColor(1, new Color3f(1, 1, 1)); Shape3D shape = new Shape3D(); shape.setGeometry(lineArray); return shape; // return new Cylinder(1, 1, // Cylinder.GENERATE_NORMALS | // Cylinder.ENABLE_GEOMETRY_PICKING, // 26, 26, lightGrayLook); } }; this.vertexAppearanceTransformer = new ConstantTransformer(redLook); this.vertexShapeTransformer = new Transformer<V, Node>() { public Node transform(V arg0) { return new Sphere(10, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING | Sphere.ENABLE_APPEARANCE_MODIFY, redLook); } }; }
From source file:LineTypes.java
Group createLineTypes() { Group lineGroup = new Group(); Appearance app = new Appearance(); ColoringAttributes ca = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT); app.setColoringAttributes(ca);/*from ww w . java2 s .c o m*/ // Plain line Point3f[] plaPts = new Point3f[2]; plaPts[0] = new Point3f(-0.9f, -0.7f, 0.0f); plaPts[1] = new Point3f(-0.5f, 0.7f, 0.0f); LineArray pla = new LineArray(2, LineArray.COORDINATES); pla.setCoordinates(0, plaPts); Shape3D plShape = new Shape3D(pla, app); lineGroup.addChild(plShape); // line pattern dot Point3f[] dotPts = new Point3f[2]; dotPts[0] = new Point3f(-0.4f, -0.7f, 0.0f); dotPts[1] = new Point3f(-0.0f, 0.7f, 0.0f); LineArray dot = new LineArray(2, LineArray.COORDINATES); dot.setCoordinates(0, dotPts); LineAttributes dotLa = new LineAttributes(); dotLa.setLineWidth(2.0f); dotLa.setLinePattern(LineAttributes.PATTERN_DOT); Appearance dotApp = new Appearance(); dotApp.setLineAttributes(dotLa); dotApp.setColoringAttributes(ca); Shape3D dotShape = new Shape3D(dot, dotApp); lineGroup.addChild(dotShape); // line pattern dash Point3f[] dashPts = new Point3f[2]; dashPts[0] = new Point3f(-0.0f, -0.7f, 0.0f); dashPts[1] = new Point3f(0.4f, 0.7f, 0.0f); LineArray dash = new LineArray(2, LineArray.COORDINATES); dash.setCoordinates(0, dashPts); LineAttributes dashLa = new LineAttributes(); dashLa.setLineWidth(4.0f); dashLa.setLinePattern(LineAttributes.PATTERN_DASH); Appearance dashApp = new Appearance(); dashApp.setLineAttributes(dashLa); dashApp.setColoringAttributes(ca); Shape3D dashShape = new Shape3D(dash, dashApp); lineGroup.addChild(dashShape); // line pattern dot-dash Point3f[] dotDashPts = new Point3f[2]; dotDashPts[0] = new Point3f(0.5f, -0.7f, 0.0f); dotDashPts[1] = new Point3f(0.9f, 0.7f, 0.0f); LineArray dotDash = new LineArray(2, LineArray.COORDINATES); dotDash.setCoordinates(0, dotDashPts); LineAttributes dotDashLa = new LineAttributes(); dotDashLa.setLineWidth(4.0f); dotDashLa.setLinePattern(LineAttributes.PATTERN_DASH_DOT); Appearance dotDashApp = new Appearance(); dotDashApp.setLineAttributes(dotDashLa); dotDashApp.setColoringAttributes(ca); Shape3D dotDashShape = new Shape3D(dotDash, dotDashApp); lineGroup.addChild(dotDashShape); return lineGroup; }
From source file:IntersectTest.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode);//from w w w . j ava 2 s .co m // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f); Vector3f light2Direction = new Vector3f(-6.0f, -2.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objRoot.addChild(light2); Transform3D t3 = new Transform3D(); // Shapes for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { t3.setTranslation(new Vector3d(-4 + x * 4.0, -4 + y * 4.0, -20 - z * 4.0)); TransformGroup objTrans = new TransformGroup(t3); objRoot.addChild(objTrans); // Create a simple shape leaf node, add it to the scene // graph. GeometryArray geom = null; if (((x + y + z) % 2) == 0) { geom = new RandomColorCube(); } else { geom = new RandomColorTetrahedron(); } Shape3D shape = new Shape3D(geom); // use the utility method to set the capabilities PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL); objTrans.addChild(shape); } } } // Lines Point3f[] verts = { new Point3f(-2.0f, 0.0f, 0.0f), new Point3f(2.0f, 0.0f, 0.0f) }; Color3f grey = new Color3f(0.7f, 0.7f, 0.7f); Color3f[] colors = { grey, grey }; for (int y = 0; y < 5; y++) { for (int z = 0; z < 5; z++) { t3.setTranslation(new Vector3d(7.0, -4 + y * 2.0, -20.0 - z * 2.0)); TransformGroup objTrans = new TransformGroup(t3); objRoot.addChild(objTrans); LineArray la = new LineArray(verts.length, LineArray.COORDINATES | LineArray.COLOR_3); la.setCoordinates(0, verts); la.setColors(0, colors); Shape3D shape = new Shape3D(); shape.setGeometry(la); // use the utility method to set the capabilities PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL); objTrans.addChild(shape); } } // Points for (double x = -2.0; x <= 2.0; x += 1.0) { for (double y = -2.0; y <= 2.0; y += 1.0) { for (double z = -2.0; z <= 2.0; z += 1.0) { t3.setTranslation(new Vector3d(-10.0 + 2.0 * x, 0.0 + 2.0 * y, -20.0 + 2.0 * z)); TransformGroup objTrans = new TransformGroup(t3); objRoot.addChild(objTrans); PointArray pa = new PointArray(1, PointArray.COORDINATES | PointArray.COLOR_3); pa.setCoordinate(0, new Point3d(0.0, 0.0, 0.0)); pa.setColor(0, grey); Shape3D shape = new Shape3D(); shape.setGeometry(pa); // use the utility method to set the capabilities PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL); objTrans.addChild(shape); } } } return objRoot; }
From source file:ffx.potential.MolecularAssembly.java
/** * <p>// www. j a v a 2s. c om * createBox</p> */ public void createBox() { int vertices = 8; LineArray la = new LineArray(4 * vertices, GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS); la.setCapability(LineArray.ALLOW_COORDINATE_WRITE); la.setCapability(LineArray.ALLOW_COORDINATE_READ); la.setCapability(LineArray.ALLOW_COLOR_WRITE); la.setCapability(LineArray.ALLOW_COUNT_READ); la.setCapability(LineArray.ALLOW_INTERSECT); la.setCapability(LineArray.ALLOW_FORMAT_READ); // Create a normal // for (ListIterator li = bondlist.listIterator(); li.hasNext(); ){ // la.setCoordinate(i, a1); // la.setColor(i, col); // la.setNormal(i++, a1); // } ColoringAttributes cola = new ColoringAttributes(new Color3f(), ColoringAttributes.SHADE_GOURAUD); Appearance app = new Appearance(); lineAttributes = new LineAttributes(); lineAttributes.setLineWidth(RendererCache.bondwidth); lineAttributes.setCapability(LineAttributes.ALLOW_WIDTH_WRITE); lineAttributes.setLineAntialiasingEnable(true); app.setLineAttributes(lineAttributes); app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ); app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE); RenderingAttributes ra = new RenderingAttributes(); ra.setAlphaTestValue(0.1f); ra.setAlphaTestFunction(RenderingAttributes.GREATER); ra.setDepthBufferEnable(true); ra.setDepthBufferWriteEnable(true); app.setRenderingAttributes(ra); app.setColoringAttributes(cola); Shape3D wireframe = new Shape3D(la, app); // PickTool.setCapabilities(wire, PickTool.INTERSECT_COORD); wireframe.setUserData(this); wireframe.setBounds(new BoundingSphere(new Point3d(0, 0, 0), 10.0)); try { wireframe.setBoundsAutoCompute(false); } catch (Exception e) { e.printStackTrace(); } wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ); wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ); // return wire; }
From source file:ViewProj.java
public BranchGroup createVWorldViewSG() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); objRoot.setCapability(BranchGroup.ALLOW_DETACH); // setup a transform group to hold the scaled scene TransformGroup objTrans = new TransformGroup(); objRoot.addChild(objTrans);/*from w w w. j a v a 2s . c om*/ // get the eye point, field of view and clip distances float fov = (float) view.getFieldOfView(); // figure out the angle factors to find points along the edges // of the FOV // X = fovSpreadX * (Y - eyeVW.y) + eyeVW.x; float fovSpreadX = (float) Math.tan(fov / 2); // Z = fovSpreadZ * (X - eyeVW.x) + eyeVW.z; float fovSpreadZ = 1.0f / fovSpreadX; //System.out.println("fovSpreadX = " + fovSpreadX); //System.out.println("fovSpreadZ = " + fovSpreadZ); Transform3D vpTransform = new Transform3D(); viewingPlatform.getViewPlatformTransform().getTransform(vpTransform); Vector3f vpTranslation = new Vector3f(); vpTransform.get(vpTranslation); eyePtVW.set(vpTranslation); eyePtVW.negate(); // get the eye point in our 2D coord system. Point3f eyePt = new Point3f(0.0f, eyePtVW.z, 0.1f); float frontClipDist = (float) view.getFrontClipDistance(); float backClipDist = (float) view.getBackClipDistance(); // set up the clip plane lines Point3f[] cpPoints = new Point3f[5]; cpPoints[0] = new Point3f(frontClipDist * fovSpreadX, eyePtVW.z + frontClipDist, 0.1f); cpPoints[1] = new Point3f(cpPoints[0]); cpPoints[1].x *= -1; Point3f backLeft = new Point3f(-backClipDist * fovSpreadX, eyePtVW.z + backClipDist, 0.1f); cpPoints[2] = backLeft; Point3f backRight = new Point3f(backLeft); backRight.x *= -1; cpPoints[3] = backRight; cpPoints[4] = cpPoints[0]; //for (int i = 0; i < 4; i++) { // System.out.println("cpPoints[" + i + "] = " + cpPoints[i]); //} int[] cpLength = new int[1]; cpLength[0] = 5; LineStripArray cpLines = new LineStripArray(5, LineArray.COORDINATES, cpLength); cpLines.setCoordinates(0, cpPoints); Appearance cpApp = new Appearance(); ColoringAttributes cpCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT); cpApp.setColoringAttributes(cpCa); Shape3D cpShape = new Shape3D(cpLines, cpApp); objTrans.addChild(cpShape); // get the limits of the space float minY = eyePt.y; float maxY = backLeft.y; float minX = backLeft.x; float maxX = backRight.x; // figure out the X and Y extents and offsets float deltaX = maxX - minX; float deltaY = maxY - minY; float offsetX = -(maxX + minX) / 2.0f; float offsetY = -(maxY + minY) / 2.0f; float gridSize = Math.max(deltaX, deltaY); // scale the grid slightly to give a border around the edge gridSize *= 1.1f; //System.out.println("offsetX = " + offsetX); //System.out.println("offsetY = " + offsetY); // Scale the view to fit -1 to 1 Transform3D trans = new Transform3D(); trans.set(new Vector3f(offsetX, offsetY, 0.0f), 2.0f / gridSize); objTrans.setTransform(trans); // figure out a grid step that is a multiple of 10 which keeps the // number of steps less than 30. float gridStep = 1.0f; while ((gridSize / gridStep) > 30.0) { gridStep *= 10; } int gridNumSteps = (int) Math.ceil(gridSize / gridStep) + 1; // allocate the grid points array, four points for each step (x and y) // with a couple extra points for the extra grid points added // below int gridNumPoints = 4 * (gridNumSteps + 4); Point3f[] gridPts = new Point3f[gridNumPoints]; for (int i = 0; i < gridNumPoints; i++) { gridPts[i] = new Point3f(); } // find the grid limits. Add a step on each side to make sure // the grid is larger than the view float gridMinY = gridStepFloor(minY, gridStep) - gridStep; float gridMaxY = gridStepCeil(maxY, gridStep) + gridStep; float gridMinX = gridStepFloor(minX, gridStep) - gridStep; float gridMaxX = gridStepCeil(maxX, gridStep) + gridStep; //System.out.println("gridMinY = " + gridMinY); //System.out.println("gridMaxY = " + gridMaxY); //System.out.println("gridMinX = " + gridMinX); //System.out.println("gridMaxX = " + gridMaxX); // set up the background grid Appearance bgApp = new Appearance(); ColoringAttributes bgCa = new ColoringAttributes(); bgCa.setColor(grey); LineAttributes bgLa = new LineAttributes(); bgApp.setColoringAttributes(bgCa); // clear out the clip grid point list numClipGridPts = 0; // set up the vertical lines int numPts = 0; for (float x = gridMinX; x <= gridMaxX; x += gridStep) { gridPts[numPts].x = x; gridPts[numPts].y = gridMinY; gridPts[numPts].z = -0.2f; gridPts[numPts + 1].x = x; gridPts[numPts + 1].y = gridMaxY; gridPts[numPts + 1].z = -0.2f; numPts += 2; // try to add a line to the clipped grid // find the intersection of the clipped line with the FOV sides // this is a distance relative to the eye float clipZ = fovSpreadZ * Math.abs(x - eyePtVW.x); if (clipZ < frontClipDist) { // clip to front clip plane clipZ = frontClipDist; } if (clipZ < backClipDist) { // clip to back clip plane // line is not clipped clipGridPtsVW[numClipGridPts].x = x; clipGridPtsVW[numClipGridPts].y = clipZ + eyePtVW.z; clipGridPtsVW[numClipGridPts].z = -0.1f; clipGridPtsVW[numClipGridPts + 1].x = x; clipGridPtsVW[numClipGridPts + 1].y = backClipDist + eyePtVW.z; clipGridPtsVW[numClipGridPts + 1].z = -0.1f; numClipGridPts += 2; } } LineArray vertLa = new LineArray(numPts, LineArray.COORDINATES); vertLa.setCoordinates(0, gridPts, 0, numPts); Shape3D vertShape = new Shape3D(vertLa, bgApp); objTrans.addChild(vertShape); // set up the horizontal lines numPts = 0; for (float y = gridMinY; y <= gridMaxY; y += gridStep) { gridPts[numPts].x = gridMinX; gridPts[numPts].y = y; gridPts[numPts++].z = -0.2f; gridPts[numPts].x = gridMaxX; gridPts[numPts].y = y; gridPts[numPts++].z = -0.2f; // try to add a line to the clipped grid // find the intersection of the clipped line with the FOV sides // this is a distance relative to the eye float clipDist = (y - eyePtVW.z); if ((clipDist > frontClipDist) && (clipDist < backClipDist)) { float clipX = fovSpreadX * clipDist; clipGridPtsVW[numClipGridPts].x = -clipX; clipGridPtsVW[numClipGridPts].y = y; clipGridPtsVW[numClipGridPts].z = -0.1f; clipGridPtsVW[numClipGridPts + 1].x = clipX; clipGridPtsVW[numClipGridPts + 1].y = y; clipGridPtsVW[numClipGridPts + 1].z = -0.1f; numClipGridPts += 2; } } LineArray horizLa = new LineArray(numPts, LineArray.COORDINATES); horizLa.setCoordinates(0, gridPts, 0, numPts); Shape3D horizShape = new Shape3D(horizLa, bgApp); objTrans.addChild(horizShape); // draw the clipped grid. if (numClipGridPts > 0) { LineArray clipLa = new LineArray(numClipGridPts, LineArray.COORDINATES); clipLa.setCoordinates(0, clipGridPtsVW, 0, numClipGridPts); Appearance clipGridApp = new Appearance(); ColoringAttributes clipCa = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT); clipGridApp.setColoringAttributes(clipCa); LineAttributes clipGridLa = new LineAttributes(); Shape3D clipShape = new Shape3D(clipLa, clipGridApp); objTrans.addChild(clipShape); } // set up the coordinate system Appearance coordSysApp = new Appearance(); LineAttributes coordSysLa = new LineAttributes(); coordSysLa.setLineWidth(3.0f); coordSysApp.setLineAttributes(coordSysLa); ColoringAttributes coordSysCa = new ColoringAttributes(grey, ColoringAttributes.SHADE_FLAT); coordSysApp.setColoringAttributes(coordSysCa); Point3f[] coordSysPts = new Point3f[4]; coordSysPts[0] = new Point3f(gridMinX, 0, -0.5f); coordSysPts[1] = new Point3f(gridMaxX, 0, -0.5f); coordSysPts[2] = new Point3f(0, gridMinY, -0.5f); coordSysPts[3] = new Point3f(0, gridMaxY, -0.5f); LineArray coordSysLines = new LineArray(4, LineArray.COORDINATES); coordSysLines.setCoordinates(0, coordSysPts); Shape3D coordSysShape = new Shape3D(coordSysLines, coordSysApp); objTrans.addChild(coordSysShape); // set up the circle Appearance circleApp = new Appearance(); ColoringAttributes circleCa = new ColoringAttributes(); circleCa.setColor(red); circleApp.setColoringAttributes(circleCa); PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(PolygonAttributes.CULL_NONE); circleApp.setPolygonAttributes(pa); int step = 360 / (numCirclePts - 1); for (int deg = 0; deg < 360; deg += step) { double angle = Math.toRadians(deg); circlePtsVW[deg / 10].x = sphereRadius * (float) Math.sin(angle); circlePtsVW[deg / 10].y = sphereRadius * (float) Math.cos(angle); circlePtsVW[deg / 10].z = -0.3f; } circlePtsVW[numCirclePts - 1].set(circlePtsVW[0]); int[] lineStripLength = new int[1]; lineStripLength[0] = numCirclePts; //LineStripArray circleLineStrip = new LineStripArray(numCirclePts, // LineArray.COORDINATES, lineStripLength); TriangleFanArray circleLineStrip = new TriangleFanArray(numCirclePts, LineArray.COORDINATES, lineStripLength); circleLineStrip.setCoordinates(0, circlePtsVW); Shape3D circleShape = new Shape3D(circleLineStrip, circleApp); objTrans.addChild(circleShape); return objRoot; }
From source file:AppearanceExplorer.java
Shape3D createLineArray() { Point3f pnt[] = new Point3f[4]; pnt[0] = new Point3f(-1.0f, -1.0f, 0.0f); pnt[1] = new Point3f(1.0f, -1.0f, 0.0f); pnt[2] = new Point3f(1.0f, 1.0f, 0.0f); pnt[3] = new Point3f(-1.0f, 1.0f, 0.0f); Color3f colrs[] = new Color3f[4]; colrs[0] = black;/* w w w . ja va 2 s .c om*/ colrs[1] = white; colrs[2] = red; colrs[3] = green; LineArray la = new LineArray(4, GeometryArray.COORDINATES | GeometryArray.COLOR_3); la.setCoordinates(0, pnt); la.setColors(0, colrs); return new Shape3D(la, appearance); }
From source file:ViewProj.java
public BranchGroup createProjViewSG() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); objRoot.setCapability(BranchGroup.ALLOW_DETACH); // setup a transform group to hold the scaled scene TransformGroup objTrans = new TransformGroup(); Transform3D scale = new Transform3D(); scale.set(0.9);//from w w w.ja va2 s . c o m objTrans.setTransform(scale); objRoot.addChild(objTrans); // create the clip limits line Point3f[] cpPoints = new Point3f[5]; cpPoints[0] = new Point3f(-1, -1, 0.1f); cpPoints[1] = new Point3f(1, -1, 0.1f); cpPoints[2] = new Point3f(1, 1, 0.1f); cpPoints[3] = new Point3f(-1, 1, 0.1f); cpPoints[4] = cpPoints[0]; int[] cpLength = new int[1]; cpLength[0] = 5; LineStripArray cpLines = new LineStripArray(5, LineArray.COORDINATES, cpLength); cpLines.setCoordinates(0, cpPoints); Appearance cpApp = new Appearance(); ColoringAttributes cpCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT); cpApp.setColoringAttributes(cpCa); LineAttributes cpLa = new LineAttributes(); Shape3D cpShape = new Shape3D(cpLines, cpApp); objTrans.addChild(cpShape); // transform and render the clip grid points updateProjTrans(); if (numClipGridPts > 0) { // transform the clipGridPts for (int i = 0; i < numClipGridPts; i++) { projectPoint(clipGridPtsVW[i], clipGridPtsProj[i]); } LineArray clipLn = new LineArray(numClipGridPts, LineArray.COORDINATES); clipLn.setCoordinates(0, clipGridPtsProj, 0, numClipGridPts); Appearance clipGridApp = new Appearance(); ColoringAttributes clipCa = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT); clipGridApp.setColoringAttributes(clipCa); LineAttributes clipLa = new LineAttributes(); Shape3D clipShape = new Shape3D(clipLn, clipGridApp); objTrans.addChild(clipShape); } // set up the circle Appearance circleApp = new Appearance(); ColoringAttributes circleCa = new ColoringAttributes(); circleCa.setColor(red); circleApp.setColoringAttributes(circleCa); PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(PolygonAttributes.CULL_NONE); circleApp.setPolygonAttributes(pa); // transform the circlePts for (int i = 0; i < numCirclePts; i++) { projectPoint(circlePtsVW[i], circlePtsProj[i]); } int[] lineStripLength = new int[1]; lineStripLength[0] = numCirclePts; //LineStripArray circleLineStrip = new LineStripArray(numCirclePts, // LineArray.COORDINATES, lineStripLength); TriangleFanArray circleLineStrip = new TriangleFanArray(numCirclePts, LineArray.COORDINATES, lineStripLength); circleLineStrip.setCoordinates(0, circlePtsProj); Shape3D circleShape = new Shape3D(circleLineStrip, circleApp); objTrans.addChild(circleShape); return objRoot; }
From source file:ExSpotLight.java
public AnnotationLine(float x, float y, float z, float x2, float y2, float z2) { float[] coord = new float[3]; float[] texcoord = new float[2]; // Build a shape shape = new Shape3D(); shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); // Create geometry for a 2-vertex straight line line = new LineArray(2, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2); line.setCapability(GeometryArray.ALLOW_COLOR_WRITE); // Starting point coord[0] = x;// w w w .j a v a2 s . c om coord[1] = y; coord[2] = z; texcoord[0] = 0.0f; texcoord[1] = 0.0f; line.setCoordinate(0, coord); line.setTextureCoordinate(0, texcoord); // Ending point coord[0] = x2; coord[1] = y2; coord[2] = z2; texcoord[0] = 1.0f; texcoord[1] = 0.0f; line.setCoordinate(1, coord); line.setTextureCoordinate(1, texcoord); shape.setGeometry(line); // Create an appearance mainAppearance = new Appearance(); mainAppearance.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE); mainAppearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE); lineAttributes = new LineAttributes(); lineAttributes.setLineWidth(lineWidth); mainAppearance.setLineAttributes(lineAttributes); coloringAttributes = new ColoringAttributes(); coloringAttributes.setColor(lineColor); coloringAttributes.setShadeModel(ColoringAttributes.SHADE_FLAT); mainAppearance.setColoringAttributes(coloringAttributes); addChild(shape); }
From source file:ffx.potential.MolecularAssembly.java
private Shape3D renderWire() { ArrayList<ROLS> bonds = getBondList(); int numbonds = bonds.size(); if (numbonds < 1) { return null; }/* w ww. j a v a2s . c o m*/ Vector3d bondmidpoint = new Vector3d(); double[] mid = { 0, 0, 0 }; Vector3d v1 = new Vector3d(); Vector3d v2 = new Vector3d(); float[] a1 = { 0, 0, 0 }; float[] a2 = { 0, 0, 0 }; float[] col = new float[4]; Bond bond; Atom atom1, atom2; LineArray la = new LineArray(4 * numbonds, GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS); la.setCapability(LineArray.ALLOW_COORDINATE_WRITE); la.setCapability(LineArray.ALLOW_COORDINATE_READ); la.setCapability(LineArray.ALLOW_COLOR_WRITE); la.setCapability(LineArray.ALLOW_COUNT_READ); la.setCapability(LineArray.ALLOW_INTERSECT); la.setCapability(LineArray.ALLOW_FORMAT_READ); atomLookUp = new Atom[4 * numbonds]; int i = 0; col[3] = 0.9f; for (ListIterator li = bonds.listIterator(); li.hasNext();) { bond = (Bond) li.next(); bond.setWire(la, i); atom1 = bond.getAtom(0); atom2 = bond.getAtom(1); atom1.getV3D(v1); atom2.getV3D(v2); a1[0] = (float) v1.x; a1[1] = (float) v1.y; a1[2] = (float) v1.z; a2[0] = (float) v2.x; a2[1] = (float) v2.y; a2[2] = (float) v2.z; // Find the bond center bondmidpoint.add(v1, v2); bondmidpoint.scale(0.5d); bondmidpoint.get(mid); // Atom #1 Atom.AtomColor.get(atom1.getAtomicNumber()).get(col); atomLookUp[i] = atom1; la.setCoordinate(i, a1); la.setColor(i, col); la.setNormal(i, a2); i++; atomLookUp[i] = atom1; la.setCoordinate(i, mid); la.setColor(i, col); la.setNormal(i, a2); i++; // Atom #2 Atom.AtomColor.get(atom2.getAtomicNumber()).get(col); atomLookUp[i] = atom2; la.setCoordinate(i, a2); la.setColor(i, col); la.setNormal(i, a1); i++; atomLookUp[i] = atom2; la.setCoordinate(i, mid); la.setColor(i, col); la.setNormal(i, a1); i++; } ColoringAttributes cola = new ColoringAttributes(new Color3f(), ColoringAttributes.SHADE_GOURAUD); Appearance app = new Appearance(); lineAttributes = new LineAttributes(); lineAttributes.setLineWidth(RendererCache.bondwidth); lineAttributes.setCapability(LineAttributes.ALLOW_WIDTH_WRITE); lineAttributes.setLineAntialiasingEnable(true); app.setLineAttributes(lineAttributes); app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ); app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE); RenderingAttributes ra = new RenderingAttributes(); ra.setAlphaTestValue(0.1f); ra.setAlphaTestFunction(RenderingAttributes.GREATER); ra.setDepthBufferEnable(true); ra.setDepthBufferWriteEnable(true); app.setRenderingAttributes(ra); app.setColoringAttributes(cola); Shape3D wireframe = new Shape3D(la, app); // PickTool.setCapabilities(wire, PickTool.INTERSECT_COORD); wireframe.setUserData(this); wireframe.setBounds(new BoundingSphere(new Point3d(0, 0, 0), 1000.0)); try { wireframe.setBoundsAutoCompute(false); } catch (Exception e) { e.printStackTrace(); } wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ); wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ); wireframe.setCapability(Shape3D.ALLOW_LOCAL_TO_VWORLD_READ); return wireframe; }