Hi Rob,
Hope this is some help. I've been using this on
models from various different sources.
I simply traverse the scenegraph for the given root
node to retrieve all of its Appearance node components. Then I set the indiviual
appearance components for each Appearance to attributes which I have previously
defined. In this way the attributes are shared between all of the appearances,
so that , for example, when I change my polygon attributes all of my models are
changed.e.g.
polygonAttr.setPolygonMode(PolygonAttributes.POLYGON_LINE);
has the effect of changing my models to
wireframe.
I find that retrieving the different appearance
components and keeping references to them before the graph is live makes
changing the appearance much easier once the graph is live, because you
don't have to set the necessary capabilities for traversing the live graph
(Also means you can compile the scene graph). Obviously you still need to set
the capabilities for the appearance components,
e.g.
polygonAttr.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
If you prefer to keep the appearance components
already associated with each model you can use the Appearance get methods
rather than set.
Cheers,
Ewan
// Adds a new model to the scene graph after
retrieving its Appearance components
public void addModel(Node model)
{
// Retrieve all the appearance
node components associated with the model
visitedSharedGroups = new
HashSet();
appearances = new Vector();
retrieveAppearances(model);appearances = new Vector();
// Set the rendering
attributes for the appearances
for (int i = 0; i < appearances.size(); i++)
{
Appearance app = (Appearance)appearances.elementAt(i);
app.setPolygonAttributes(polygonAttr);
app.setTextureAttributes(textureAttr);
app.setColoringAttributes(colourAttr);
}
for (int i = 0; i < appearances.size(); i++)
{
Appearance app = (Appearance)appearances.elementAt(i);
app.setPolygonAttributes(polygonAttr);
app.setTextureAttributes(textureAttr);
app.setColoringAttributes(colourAttr);
}
..... Rest of my code adds model
to scene graph
} // addModel
// Retrieve all the Appearance node components in
the scene graph which begins at root
private void retrieveAppearances(Node root) throws CapabilityNotSetException
private void retrieveAppearances(Node root) throws CapabilityNotSetException
{
// If this is a null tree then return
if (root == null)
return;
// If this is a null tree then return
if (root == null)
return;
// If the root is a
shared group then make sure it hasn't already been
considered
if (root instanceof SharedGroup)
{
// If it has been visited previously then return
if (visitedSharedGroups.contains(root))
return;
if (root instanceof SharedGroup)
{
// If it has been visited previously then return
if (visitedSharedGroups.contains(root))
return;
// If not then add it to the list of visited shared
groups
else
visitedSharedGroups.add(root);
}
else
visitedSharedGroups.add(root);
}
// If the current
root node is a Shape3D then retrieve it's appearance node
component
// and place that in the appearances vector
if (root instanceof Shape3D)
appearances.add(((Shape3D)root).getAppearance());
// and place that in the appearances vector
if (root instanceof Shape3D)
appearances.add(((Shape3D)root).getAppearance());
// If root is a
group then traverse all of its children
else if (root instanceof Group)
{
Enumeration e = ((Group)root).getAllChildren();
while(e.hasMoreElements())
retrieveAppearances((Node)e.nextElement());
else if (root instanceof Group)
{
Enumeration e = ((Group)root).getAllChildren();
while(e.hasMoreElements())
retrieveAppearances((Node)e.nextElement());
}
// If root is a link
then traverse its shared group
else if (root instanceof Link)
retrieveAppearances(((Link)root).getSharedGroup());
else if (root instanceof Link)
retrieveAppearances(((Link)root).getSharedGroup());
} // retrieveAppearances
----- Original Message -----
From: "Rob Brown" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, March 11, 2002 1:24 PM
Subject: [JAVA3D] obj loader
>
> After, I load in an object from an OBJ file. How can I make it render as
> points, wire frame, flat shaded, etc... basically a quick mod to ObjLoad
> that comes with J3d.
>
>
> Thanks for any help
>
>
> Rob Brown
> Eyetronics Inc
> Developer
> [EMAIL PROTECTED]
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
