java 关于VMRL EAI接口的总结

14年前

JAVA 可以通过IE 实现对于VRML的控制

忙了一天 终于将EAI实现了,下面是一些总结,希望对于其他的人有所帮助

具体配置如下:

1.jdk version   1.3,一定要1.3的

2.添加vrml97.jar,注意路径,及其环境变量的配置

3.安装cortona插件,这个在cortona vrml 游览插件中,可以找到

classes.zip用于实现SAI

corteai.zip用于实现EAI

根据个人采用的方式,添加相应的包,环境变量也要设置

4.装微软的jvm
5.设置IE
  关闭SUN jdk用户Applet执行,并且对于Microsoft VM做如下设置:
  启用JAVA控制台(是)
  启用JAVA JIT编译器 (是)
  启用JAVA记录(否)

 

下面举一个具体的实例

<IMG style="MAX-WIDTH: 500px" title="java 关于VMRL EAI接口的总结 实例" alt="java 关于VMRL EAI接口的总结 实例" src="https://simg.open-open.com/show/3d045b93716ed28dc745e648b3428a26.gif" real_src="http://static3.photo.sina.com.cn/bmiddle/60c11a4946f7f64f71262&690">

JAVA文件:helix.java

//
// Program: Helix Spring.
//
// Description:
//    This program calculates coordinates needed to make a helix spring
//    and sets them in 3D scene. spineLimit x crossSectionLimit = 250 x 10
//    = 2500, and thus satisfies vrml97 conformity requirements for
//    Extrusion node. The animation speed may be adjusted by altering
//    thread.sleep value, but too low values may decrease browser
//    rendering performance.
//
// Author: Vilius Jagminas, vilius@extred.com
// Version: 1.0, 12.11.2000
//
// Edited to produce a more concise spec example by Martin Reddy.
//
// Compiled against the Cortona 3 EAI classes, corteai.zip
//

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

public class helix extends Applet implements Runnable {

  EventInMFVec3f spine = null;
  EventInMFVec2f crossSection = null;
  Thread thread = null;
  Choice choice;
 
  int spineLimit = 250;
  float[][] spinue = new float[spineLimit+1][3];
  int crossSectionLimit = 10;
  float[][] crossSectionValue = new float[crossSectionLimit+1][2];
  float numCoils = 5f;

  // set up the applet controls
  public void init() {
    super.init();
    setBackground(Color.white);
    Panel p1 = new Panel();
    Label lblNCoils = new Label("Number of Coils");
    p1.add(lblNCoils);
    choice= new Choice();
    choice.addItem("5"); choice.addItem("4"); choice.addItem("3");
    choice.addItem("2"); choice.addItem("1");
    p1.add(choice);
    add(p1);
  }

  public void start() {
    // get the VRML Browser reference
    Browser browser = null;
    for (int count = 0; count < 10; count++) {
      browser = BrowserFactory.getBrowser(this);
      if (browser != null) break;
      try { Thread.sleep (200); } catch (InterruptedException e) {}
    }
    if (browser == null) {
      throw new Error("Failed to get the browser after 10 tries!");    
    }

    // get the spine and crossSection fields of the Extrusion node
    try {
      Node coil = browser.getNode("Coil");
      spine = (EventInMFVec3f) coil.getEventIn("set_spine");
      crossSection = (EventInMFVec2f) coil.getEventIn("set_crossSection");
    } catch (vrml.eai.InvalidNodeException ne){
      System.out.println("Node Exception Error:" + ne.getMessage());
    }

    if (thread == null) {
      thread = new Thread(this);
      thread.start();
    } else
      thread.resume();
  }

  public void stop() {
    if (thread != null) thread.suspend();
  }

  public void destroy() {
    thread.stop();
    thread = null;
  }

  public void run() {
    // calculate and set the crossSection values of the Extrusion node
    float thickness = 0.1f;
    float diameter = 1.5f;
    float two_pi = (float) Math.PI * 2.0f;
    for (int j = 0; j <= crossSectionLimit; j++) {
      float angle = j * two_pi / crossSectionLimit;
      crossSectionValue[j][0] = thickness / 2 * (float) Math.sin(angle);
      crossSectionValue[j][1] = thickness / 2 * (float) Math.cos(angle);
    }
    crossSection.setValue(crossSectionValue);

    // oscilate the spring between 0.3 and 1, with 0.05 increments
    float inc = 0.05f;
    float value = 0.3f;
    float springLength = 2f;
    while (true) {
      value += inc;
      //calculate and set the coordinates for the whole spine
      for (int i = 0; i <= spineLimit; i++) {
 float stepsPerCoil = (float) Math.round(spineLimit / numCoils);
 float angle = i * two_pi / stepsPerCoil;
 spinue[i][0] = diameter / 2 * (float) Math.cos(angle);
 spinue[i][1] = springLength / numCoils * value * i / stepsPerCoil;
 spinue[i][2] = diameter / 2 * (float) Math.sin(angle);
      }
      spine.setValue(spinue);

      // sleep for 0.1 seconds
      try { thread.sleep(100); } catch (InterruptedException e) {}

      // reverse movement direction
      if (value >= 1f && inc == 0.05f)
 inc = -0.05f;
      else if (value <= 0.3 && inc == -0.05f)
 inc = 0.05f;       
    }
  }

  // handle input (deprecated Java API)
  public boolean handleEvent(Event event) {
    if (event.id == Event.ACTION_EVENT && event.target == choice)
      changeNumCoils();
    return super.handleEvent(event);
  }

  // changes number of coils in the helix
  private void changeNumCoils() {
    String number = choice.getSelectedItem();
    numCoils = (new Float(number)).floatValue();
  }
}

vrml 文件

helix.wrl

#VRML V2.0 utf8

Viewpoint {
    position 0 4 5
    orientation 1 0 0 -0.5
}

Shape {
   appearance Appearance {
      material Material {
  diffuseColor 0.8 0.8 0.9
  shininess 1
      }
   }
   geometry DEF Coil Extrusion {
      crossSection []
      spine []
      creaseAngle 3.14
   }
}

HTML文件

<html>
<head><title>Helix Spring</title></head>
<body>

<embed src="helix.wrl" border=0 height="200" width="200">
<br>
<applet code="helix.class" mayscript height="100" width="200">
</applet>

</body>
</html>

blog.sina.com.cn/hackyh