Java communicates with VRML using EAI mode

本文详细介绍如何使用Java控制VRML场景,包括设置运行环境、整合HTML与VRML,以及通过Java Applet实现VRML对象的动态控制。适用于初学者理解Java与VRML交互的基本原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Last week several students came to ask me how to use java to  control VRML?This question remembered me something:the same question was asked 2 years ago by one friend of mine,and I even forgot to tell him how.That's really too bad.He is now in Copenhagen,Denmark. I e-mailed him to ask this,he just totally  forgot  it. Well,things in the world are usually out of the control of  your own hand,perhaps at that time I thought I had told him how.But now,I decide to write down the answer,though an old tech,it is useful for the beginners to understand something.

This article assumes you are familiar with Java,VRML and HTML(know about is OK).

To run the example below rightly you should eatablish its running envrionment.This is not our main point to discuss in this article,I'll just give u a clue and the environment information.The running environment is necessary to learn the java EAI mode communicating with VRML.

1.the "vrml97.jar" should be copied to the dir "jre/lib/etc".

2.one VRML plugin is necessary, you may choose"Cortona","Blaxxun" or "BS" as u like.

3.the classpath should be like "C:/jdk1.3.1_06/jre/lib/rt.jar;C:/jdk1.3.1_06/jre/lib/i18n.jar;C:/jdk1.3.1_06/lib/dt.jar;C:/jdk1.3.1_06/lib/tools.jar;C:/Program Files/Common Files/ParallelGraphics/Cortona/classes.zip;C:/Program Files/Common Files/ParallelGraphics/Cortona/corteai.zip
",here one thing I should mention is the jdk version,the 1.3 series is recommended.

4.your Microsoft VM should be reset to "Java Console Enabled (yes)
Java compiler (no)
Java Logging (yes) "

The following is the example,it includes three files:the create.wrl,the index.htm and the createbox.class,which was complied from the createbox.java.We use the java applet embedded in the html to control the wrl object embedded in the html.That's the main idea of EAI.

the index.htm(I use the cortona plugin):

<html>
<head><title>Create Sphere</title></head>
<body>

<object name="cortona" id="cortona" 

codebase
="http://www.parallelgraphics.com/bin/cortvrml.cab#Version=4,0,0,76"

classid
="CLSID:86A88967-7A20-11d2-8EDA-00600818EDB1" width="52%" height="58%"
type
="x-world/x-vrml" standby="Loading...">
  
<param name="src" value="create.wrl">
  
<param name="BackColor" value="#FFFFFF">
  
<param name="VRML_DASHBOARD" value="FALSE">
  
<param name="WaitForAllResources" value="TRUE">
  
<param name="VRML_SPLASHSCREEN" value="FALSE">
  
<embed name="cortona" id="cortona" 

pluginspage
="http://www.parallelgraphics.com/products/cortona/download/"

 type
="x-world/x-vrml" width="52%" height="58%" src="create.wrl"
 vrml_background_color
="#FFFFFF" vrml_dashboard="FALSE" waitforallresources="TRUE" 

vrml_splashscreen
="FALSE">
 
  
</embed>
 
</object>


<applet code="createbox.class" mayscript height="30" width="80"></applet>

</body>
</html>

the create.wrl:(a very simple one)

 

 

#VRML V2.0 utf8

DEF NewNode Group {}
Shape {
   appearance Appearance {
      material DEF BoxMaterial Material {
     diffuseColor 1 0 0
      }
   }
   geometry Box { size 2 2 1 }
}

 

the createbox.java:

 

import java.applet.*;
import vrml.eai.field.*;
import vrml.eai.Node;
import vrml.eai.BrowserFactory;
import vrml.eai.Browser;

public class createbox extends Applet {

  
public void init() {
    
super.init();
  }


  
public void start() {
    Browser       browser  
= null;
    Node          rootnode 
= null;
    EventInMFNode children 
= null;

    
// Get the VRML Browser - try 10 times
    for (int count = 0; count < 10; count++{
      browser 
= BrowserFactory.getBrowser(this);
      
if (browser != nullbreak;
      
try { Thread.sleep(200); } catch (InterruptedException e) {}
    }

    
    
// Get the set_children eventIn of the DEF'd Group node
    try {
      rootnode 
= browser.getNode("NewNode");
      children 
= (EventInMFNode) rootnode.getEventIn("set_children");
    }
 catch (vrml.eai.InvalidNodeException ignored) {}

    
// Create a new blue Sphere Shape node
    String newvrml =
      
"#VRML V2.0 utf8 Shape { appearance Appearance { material " +
      
"Material { diffuseColor 0 0 1 } } geometry Sphere { radius 1 } }";
    
    
// Create and add the new node to the scene graph
    children.setValue( browser.createVrmlFromString( newvrml ) );
  }


}

This example was tested to run well in my computer.

Nasky

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值