使用Java3D获取3d对象的3D坐标

时间:2015-09-08 13:25:40

标签: java java-3d

我需要你的帮助。我是Java3D的新手。我需要做的是获取Java3D对象中每个点的坐标(x,y,z),而无需使用鼠标单击或用户的任何输入。

到目前为止,我已成功将3D物体放入宇宙中。但我还没能获得几何点数。我打算做的是从一个角度获取(x,y,z),旋转对象,然后再次获得该角度的坐标,重复此过程直到360度旋转。

如何开始这方面的任何帮助将不胜感激!谢谢!

编辑:以下是我的代码。请注意,大部分内容,我只是从我发现的几个例子中得到的。现在,我设法获得宇宙中的3d对象。

    universe = new VirtualUniverse();
    Locale locale = new Locale(universe);
    sceneBranchGroup = new BranchGroup();

    BranchGroup rootBranch = sceneBranchGroup;
    applicationBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    Bounds lightBounds = applicationBounds;
    AmbientLight ambLight = new AmbientLight(true, new Color3f(1.0f, 1.0f,
            1.0f));
    ambLight.setInfluencingBounds(lightBounds);
    rootBranch.addChild(ambLight);

    DirectionalLight headLight = new DirectionalLight();
    headLight.setInfluencingBounds(lightBounds);
    rootBranch.addChild(headLight);

    TransformGroup tg = new TransformGroup();

    BranchGroup sceneRoot = loadVrmlFile("C:/Users/rache_000/Desktop/wrl files/2b.wrl");
    tg.addChild(sceneRoot);

    rootBranch.addChild(tg);

    ViewPlatform vp = new ViewPlatform();
    vp.setViewAttachPolicy(View.RELATIVE_TO_FIELD_OF_VIEW);
    vp.setActivationRadius(100);

    TransformGroup viewTG = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(1.0);
    t3d.setTranslation(new Vector3d(0.0, 0.0, -20.0));
    t3d.invert();
    viewTG.setTransform(t3d);

    BranchGroup viewBranchGroup = new BranchGroup();
    Group parentGroup = viewBranchGroup;
    parentGroup.addChild(viewTG);
    parentGroup = viewTG;

    viewTG.addChild(vp);

    View view = new View();

    PhysicalBody physicalBody = new PhysicalBody();
    PhysicalEnvironment physicalEnvirontment = new PhysicalEnvironment();

    view.setPhysicalBody(physicalBody);
    view.setPhysicalEnvironment(physicalEnvirontment);
    view.attachViewPlatform(vp);

    view.setBackClipDistance(100.0);
    view.setFrontClipDistance(1.0);

    GraphicsConfigTemplate3D gc3D = new GraphicsConfigTemplate3D();
    gc3D.setSceneAntialiasing(GraphicsConfigTemplate.PREFERRED);
    GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getScreenDevices();

    Canvas3D c3d = new Canvas3D(gd[0].getBestConfiguration(gc3D));
    c3d.setSize(300, 300);
    view.addCanvas3D(c3d);
    setLayout(new BorderLayout());
    add(c3d, BorderLayout.CENTER);
    doLayout();

    pickCanvas = new PickCanvas(c3d, sceneBranchGroup);
    pickCanvas.setMode(PickTool.GEOMETRY_INTERSECT_INFO);
    pickCanvas.setTolerance(4.0f);

    Background back = new Background(new Color3f(0.9f, 0.9f, 0.9f));

    back.setApplicationBounds(applicationBounds);
    rootBranch.addChild(back);

    locale.addBranchGraph(rootBranch);

    locale.addBranchGraph(viewBranchGroup);
  

目前,此功能无效。

    getCoordinates(sceneRoot);

我知道它只是一大块代码,但是我们将非常感谢任何帮助。我真的不知道如何接近它,正确的方向是我需要的。谢谢!

0 个答案:

没有答案