Extract GeometryArray from Shape3D

View: New views
4 Messages — Rating Filter:   Alert me  

Extract GeometryArray from Shape3D

by java3d-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is there any way to get back the GeometryArray (actually the TriangleArray) from a Node including all subnodes and all Shape3Ds?

I find getGeometry only, but this is not what I need.

Reason: I loaded an object-file and want to subtract it from a box, which I can create as a TriangleArray. I use jgeom for this.
[Message sent by forum member 'matthixxy' (matthi@...)]

http://forums.java.net/jive/thread.jspa?messageID=369571

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: Extract GeometryArray from Shape3D

by java3d-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

does it work for you?:
[code]
    private void exportNode(Node parent, Node node, String layer, int color) throws IOException {
        if (node instanceof Group) {
            Enumeration<?> enumeration = ((Group) node).getAllChildren();
            while (enumeration.hasMoreElements()) {
                exportNode(parent, (Node) enumeration.nextElement(), layer, color);
            }
        } else if (node instanceof Shape3D) {
            Transform3D transform = getTransformationToParent(parent, node);//This is for my own purpouses, never mind
            Enumeration<?> enumeration = ((Shape3D) node).getAllGeometries();
            while (enumeration.hasMoreElements()) {
                exportNodeGeometry((Geometry) enumeration.nextElement(), transform, layer, color);
            }

    private void exportNodeGeometry(Geometry geometry, Transform3D transform, String layer, int color) throws IOException {
        if (geometry instanceof GeometryArray) {
            GeometryArray geometryArray = (GeometryArray) geometry;

            /**** this is it ****/
            GeometryInfo geometryInfo = new GeometryInfo(geometryArray);
            geometryInfo.convertToIndexedTriangles();
//Now do whatever you want to do with the geometry
(...)
        }
    }
[/code]

Thanks to E. Puybaret
[Message sent by forum member 'alied' (aliedperezmartinez@...)]

http://forums.java.net/jive/thread.jspa?messageID=369682

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: Extract GeometryArray from Shape3D

by java3d-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If your subgraph contains TransformGroups you will also need to transform the coordinates into parent space.
[Message sent by forum member 'lamer77' (tomrbryn@...)]

http://forums.java.net/jive/thread.jspa?messageID=369814

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: Extract GeometryArray from Shape3D

by java3d-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

True. In this case I assumed that there were no transforms. (mea culpa)
Anyway, that is what I do in [code]getTransformationToParent(Node parent, Node child)[/code] in my previous example.

This is what it does:
[code]
    /**
     * Returns the transformation applied to a <code>child</code>
     * on the path to <code>parent</code>.
     */
    private Transform3D getTransformationToParent(Node parent, Node child) {
        Transform3D transform = new Transform3D();
        if (child instanceof TransformGroup) {
            ((TransformGroup) child).getTransform(transform);
        }
        if (child != parent) {
            Transform3D parentTransform = getTransformationToParent(parent, child.getParent());
            parentTransform.mul(transform);
            return parentTransform;
        } else {
            return transform;
        }
    }
[/code]

again, all credits to E. Puybaret
[Message sent by forum member 'alied' (aliedperezmartinez@...)]

http://forums.java.net/jive/thread.jspa?messageID=369817

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...