Establish communication between EAI mode and SAI mode

zhaozj2021-02-08  204

Establish communication between EAI mode and SAI mode

Solving a practical question of Java Control VRML Scene Hou Guangmin (Wearebug@tang.com) In January 2002, it was found that there were two ways to control the VRML scene, which is EAI mode. And SAI mode. The full name of EXTERNAL Authoring Interface, using this control method can enter various parameters in the applet to change the content of the scene, the control is very flexible. Sai mode, it does not need to have Applet, As long as you write the corresponding script code for objects in the scene, use it to implement complex logic display that many VRML specifications cannot be provided. The two can be said to have a long, but I am writing a program that controls the VRML scene. To the problem. I put a set of chip models in the scene, I want to achieve the purpose of clicking on a chip in the scene or a pin of a chip, can display the internal structural map or tube of the chip in the applet. The name and level state of the foot, I must use this information to change the corresponding model parameters. But simple SAI mode cannot communicate with Applet, clicking the result can't be perceived by Applet. And the simple EAI mode can not solve this problem, Because a model in the scene is to be controlled, you must first get the name of the model. But in this case the name of the model cannot be specified in advance, it must change with the change of the mouse. To solve this problem, you must The way to communicate information between EAI mode control and SAI control. After reviewing the VRML specification, I found a Node type Proto for users to extend in the VRML specification, which I came up with the problem of solving this problem. Measures. In fact, this method is simple, just use proto's custom domain to cache data that needs to be communicated. The specific practice is to define a Proto node called Bridge in the scenario file to add a series of domains. In this specific question, I define two domains of sfstring name, sfbool volume, and Sfsting type Pointa, PointB. Then add the SAI mode for each model that needs to communicate with Applet, click Event (or you can Other events trigger a process, the process writes the name of the model to the Name Domain of Bridge or Pointa, PointB, writes the status. The following is the VRML file sample code:

#the Node That Exchange Data Between Sai and Eai

Proto bridge [exposedfield sfstring pointa "### ^ - ^"

Exposedfield Sfstring PointB "### ^ - ^"

Exposedfield Sfstring Name "Null"

Exposedfield Sfbool Voltage False

] {} //

Def se bridge {}

.......

DEF LEG17 Transform {

Translation 35.5 16.7 -203

Rotation 0.577 0.577 -0.577 -4.19

Children [

DEF LEG17_TOUCH TOUCHSENSOR {}

Shape {

APPEARANCE USE LEGCOLOR

Geometry Use Leg17-Faces

}

]

}

......

DEF LEG17_S Script {// Chip's node of the seventeenth pin

URL "NODEScript.class"

Eventin sfbool leg17

FIELD SFNODE Node Use LEG17

Field sfnode select use selection

}

.....

Route leg17_touch.isactive to leg17_s.leg17

.....

The following is the script code snippet of the node:

Public Class Nodescript Extends Script

{

Private sfnode theseled;

Private sfstring selecteda, self; browser br;

Public void initialize ()

{

Therelected = (sfnode) getfield ("SELECT");

Br = getBrowser ();

}

Public Void Processevent (Event E)

{Constsfbool v = (constsfbool) E.GETVALUE ();

Node SELECTED = (Node) ThereElected.getValue ();

// ** Get the domain of the exchange node

SELECTEDA = (sfstring) Selected.getexposedfield ("Pointa");

SELECTEDB = (sfstring) Selected.getexposedfield ("PointB");

// * /

Br.SetDescription (E.GETNAME ()); // Displays node name at the bottom of the browser

// There is a change in this, do not use the switch value, and use the queue advanced first write value 2001/11/30

IF (v.getvalue ())

{SELECTEDB.SetValue (SELECTEDA.GETVALUE ()); // b -> a

SELECTEDA.SETVALUE (E.GetName ()); // newValue -> B

}

}

} Then add a thread to the applet in the EAI mode code, and its unlimited loop read the domain value of the Bridge node and then displayed, and complete the data from SAI to EAI, it is as simple. The following is sample code:

Public Class DisplayPanel Extends Panel IMPLEments Runnable

{public static label label1 = new label ();

Public static label label2 = new label ();

Browser Br;

.......

Public void Run ()

{

While (TRUE) // Cycle Monitor Click

{SWICH = VRMLOBJECT.GETSWICHNAME (B);

Voltage = VRMLObject.getswichvoltage (br);

DisplayPanel.label1.settext (VRMLObject.getnodea (br)); // VRMLObject class packaged access to nodes

DisplayPanel.label2.settext (VRMLObject.getnodeb (br));

}

}

} Using this way, you can expand the BRIDGE's domain to cache the data types specified in the various VRML specification.

About the author Hou Guangmin: Tianjin Institute of Technology Computer Science and Engineering Department is studying a virtual laboratory of multi-user collaboration with Java and VRML. Welcome to contact me: wearebug@etang.com

转载请注明原文地址:https://www.9cbs.com/read-2904.html

New Post(0)