String drawing in java3d

I want to draw a line to indicate a point in java 3d.

How can i do this?

for example, to draw a cube, write colorcube.

please help me.

+3
source share
4 answers
+2
source

Use a class LineArray. Create an object with two vertices for it (wherever you are) and add it to the Shape3D.ie object new Shape3D(lineArr). For a linear array:

LineArray lineArr=new LineArray(2,LineArray.COORDINATES);

then:

lineArr.setCoordinate(0,new Point3f());...

do the same for the other vertex.

Then add the object shape3Dto the scene graph or Branchgroup.

That should do the trick.

+4
source

, x:

LineArray lineX = new LineArray(2, LineArray.COORDINATES);
lineX.setCoordinate(0, new Point3f(-100.0f, 0.0f, 0.0f));
lineX.setCoordinate(1, new Point3f(100.0f, 0.0f, 0.0f));
scene.addChild(new Shape3D(lineX));

Appearance appearanceGreen = new Appearance();
ColoringAttributes coloringAttributesGreen = new ColoringAttributes();
coloringAttributesGreen.setColor(new Color3f(Color.green));
appearanceGreen.setColoringAttributes(coloringAttributesGreen);
Shape3D shapeLine = new Shape3D(lineX, appearanceGreen);
scene.addChild(shapeLine);
+1

Java 3D-:

(i.e: tuval1) (, tuval7), .

Also see this link: http://www.itk.ilstu.edu/faculty/javila/ITk356/Java3D/geometry.htm#3.4.2 Point * Classes:

import javax.media.j3d.Appearance;

import javax.media.j3d.BranchGroup;

import javax.media.j3d.GeometryArray;

import javax.media.j3d.LineStripArray;

import javax.media.j3d.Shape3D;

import javax.vecmath.Point3d;

import com.sun.j3d.utils.universe.SimpleUniverse;


public class tuval7 {

    public tuval7(){

     SimpleUniverse u=new SimpleUniverse(); 

    BranchGroup group=new BranchGroup();

    Point3d coords[] = new Point3d[4];

Appearance app=new Appearance();

     coords[0] = new Point3d(-0.5d, -0.2d, 0.1d);
     coords[1] = new Point3d(-0.2d, 0.1d, 0.0d);
     coords[2] = new Point3d(0.2d, -0.3d, 0.1d);
     coords[3] = new Point3d(0.3d, 0.5d, 0.10d);

     int vertexCounts[] = {4};

     LineStripArray lines = new LineStripArray(4,
     GeometryArray.COORDINATES, vertexCounts);

     lines.setCoordinates(0, coords);

    Shape3D shape=new Shape3D(lines , app);

    group.addChild(shape);

    u.addBranchGraph(group);

    u.getViewingPlatform().setNominalViewingTransform();

    }

}

public class tuval1 {

    public static void main(String[] args) {

        // TODO Auto-generated method stub

new tuval7();
    }

}
0
source

Source: https://habr.com/ru/post/1789263/


All Articles