ParallelGraphics Forums
General
You are here: [Forums]::[General]

Registration 
Registration
Forgot your password?

Help 
Help
Support

Quick search 

Subscribe to newsletters 

Install Cortona VRML Client for FREE!
Outline 3D
3D Page Of the Week
email:  password:
  General

Subject: how to manipulate the new object
Sender: alan_z@lycos.co.uk 7.06.04 08:01

Dear all,

I am use EAI class from cortona client and Java 1.3.1. Here is my code, and I want to access the the new
object'node(DEF MAT's diffusecolor) and change its color, but it did not work, I have tried this for several days. Please feel free to modify it. Thanks.

Xin
---------------------

vrml file: root.wrl
DEF Camera Viewpoint {
position 0 0 7
}
DEF ROOT Group {}
---------------------------------
html file: test1.html
<HTML>
<HEAD>
<TITLE>test1</TITLE>
</HEAD>
<BODY>

<center>
<embed src="root.wrl" border=0 height="250" width="375">
</center>

<center>
<P>
<APPLET code="CreateEx2_1.class" width="300" height="200"
mayscript></APPLET>
</P>
</center>

</BODY>
</HTML>
-----------------------------------------------------
java file: CreateEx2_1.java
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import vrml.external.field.*;
import vrml.external.Node;
import vrml.external.Browser;
import vrml.external.exception.*;

public class CreateEx2_1 extends Applet implements ActionListener {
TextArea output = null;
boolean error = false;

// Browser we're using
Browser browser;
// Root of the scene graph (to which we add our nodes)
Node root;
// Shape group hierarchy
Node[] shape;
String sphere = new String("DEF Camera Viewpoint {\n" +
     " position 0 0 5}\n" +
     "DEF MySphere Transform {\n" +
     " children [ \n" +
     " Shape { \n" +
     "     appearance Appearance { \n" +
     "     material DEF MAT Material { \n" +
     "     diffuseColor 0.2 0.2 0.8 \n" +
     "     } \n" +
     "     } \n" +
     "     geometry Sphere {} \n" +
     " }, \n" +
     " ] \n" +
     " } \n"
);

// EventIns of the root node
EventInMFNode addChildren;
EventInMFNode removeChildren;
EventInSFColor diffuseColor;

// Add and Remove Buttons
Button addButton;
Button removeButton;
Button redButton;

public void init() {
    add(addButton = new Button("Add Sphere"));
    add(removeButton =new Button("Remove Sphere"));
add(redButton =new Button("Change Red"));
    addButton.addActionListener(this);
    removeButton.addActionListener(this);
redButton.addActionListener(this);

    output = new TextArea(10, 40);
    add(output);

    browser = Browser.getBrowser(this);

    try {
     // Get root node of the scene, and its EventIns
     root = browser.getNode("ROOT");
     addChildren = (EventInMFNode) root.getEventIn("addChildren");
     removeChildren = (EventInMFNode) root.getEventIn("removeChildren");

     // Instantiate our ubiquitous blue sphere hierarchy
     shape = browser.createVrmlFromString(sphere);

// change the sphere's color
if (shape[0].getType().equals("Material")){
diffuseColor =
(EventInSFColor)shape[0].getEventIn("diffuseColor");
}
    }
    catch (InvalidNodeException e) {
     output.append("PROBLEMS!: " + e + "\n");
     error = true;
    }
    catch (InvalidEventInException e) {
     output.append("PROBLEMS!: " + e + "\n");
     error = true;
    }
    catch (InvalidVrmlException e) {
     output.append("PROBLEMS!: " + e + "\n");
     error = true;
    }

    if (error == false)
     output.append("Ok...\n");
}


public void actionPerformed (ActionEvent event) {

    Object clickedButton = event.getSource();
    if (clickedButton == addButton) {    
     addChildren.setValue(shape);
output.append("add a sphere on the scene\n");
    }
    else if (clickedButton == removeButton) {
     removeChildren.setValue(shape);
output.append("remove a sphere on the scene\n");
    }
else if (clickedButton ==redButton) {
float[] col = new float[3];
col[0] = 0.8f; col[1] = 0.2f; col[2] = 0.2f;
diffuseColor.setValue(col);
output.append("change the sphere to red\n");

}
}
}

 


how to manipulate the new object / alan_z@lycos.co.uk / 7.06.04 08:01

Messages in thread: 1


© 1998-2009 ParallelGraphics. All rights reserved. Terms of use.