Cortona还是Contact,真是个问题。BS Contact提供的javascript接口是以传递字符串的方式工作的,简单而有弹性。不过处理字符串是个脏活儿。
而Cortona Automation provides full control over the VRML scene,everything is described in Cortona SDK.不过好像没人有cortona sdk完整版,价格是:$749.95 USD,都没银子啊。演示版是用来吊人胃口的,信息量太少。搜了一遍又一遍,所得点滴信息整理如下:
在html中嵌入cortona 浏览器
<OBJECT name=”objectName” id=”objectName” CLASSID=”CLSID:86A88967-7A20-11d2-8EDA-00600818EDB1″ CODEBASE=”http://www.parallelgraphics.com/bin/cortvrml.cab#Version=4,2,0,93″ WIDTH=”400″ HEIGHT=”300″>
<param name=”src” value=”your_wrl_file.wrl”>
<param name=”VRML_DASHBOARD” value=”TRUE”>
<param name=”WaitForAllResources” value=”TRUE”>
<param name=”ContextMenu” value=”TRUE”>
<param name=”RendererHints” value=”32″>
<param name=”RendererName” value=”DirectX Renderer”>
<param name=”LoadDroppedScene” value=”FALSE”>
<param name=”HeadLight” value=”FALSE”>
</object>
从html-javascript访问vrml场景
1 浏览器对象句柄:objectName.Engine
2 访问SFFloat:
objectName.Engine.Nodes(“your_script_node”).Fields(“your_eventIn_field_name”) = someValue;
e.g:
objectName.Engine.Nodes(‘nodeName’).Fields(“radius”)=12;
objectName.Engine.Nodes.Item(‘node’).Fields.Item(‘set_bind’).Value = true;
3 访问SFVec3f:
objectName.Engine.Nodes(‘nodeName’).Fields(‘fieldName’).x
objectName.Engine.Nodes(‘nodeName’).Fields(‘fieldName’).y
objectName.Engine.Nodes(‘nodeName’).Fields(‘fieldName’).z
4 访问SFColor
objectName.Engine.Nodes(‘nodeName’).Fields(‘fieldName’).Red
objectName.Engine.Nodes(‘nodeName’).Fields(‘fieldName’).Green
objectName.Engine.Nodes(‘nodeName’).Fields(‘fieldName’).Blue
6 往复值域里添加单值
objectName.Engine.Nodes(‘nodeName’).Fields(‘fieldName’).Add(some_SFValue);
7 渲染器: objectName.RendererName
‘OpenGL Renderer’ 或 ‘DirectX Renderer’
8 根节点集合:
objectName.Engine.RootNodes
objectName.Engine.RootNodes(1).Fields(“rotation”).angle=3.14;
9 根节点集合的Add方法:
objectName.Engine.RootNodes.Add(objectName.Engine.CreateVrmlFromString(“Transform {translation 0 10 5 children[Shape {geometry Box {}}]}”));
或:
newrootnode = objectName.Engine.CreateNodeFromString(“…”);
objectName.Engine.RootNodes.Add(newrootnode);
10 这个在VB里可用,javascript里就不知道了。
myfield = engine.CreateField(“SFNode”)
testnode = engine.Nodes.Item(“test”)
myfield.value = testnode
11 访问SFOrientation
objectName.Engine.Nodes(‘nodeName’).Fields(‘orientation’).x=0;
objectName.Engine.Nodes(‘nodeName’).Fields(‘orientation’).y=1;
objectName.Engine.Nodes(‘nodeName’).Fields(‘orientation’).z=0;
objectName.Engine.Nodes(‘nodeName’).Fields(‘orientation’).angle=1.57;
12 访问复值:
objectName.Engine.Nodes(“myOrientationInterpolator”).Fields(“keyValue”).Y(0);
javascript 响应事件
<script for=”objectName” event=”OnSceneLoaded(Success)” language=”JavaScript”>
</script>
<script for=”objectName” event=”OnSceneUnLoaded()” language=”JavaScript”>
objectName.renderer.name
objectName.renderer.isReady
objectName.renderer.path
objectName.renderer.version
</script>
Advise works in the following way: you must create a javascript function with three parameters and then call Advise on any exposedField or eventOut with this function. When an event is generated, cortona calls this function, passing the event value, current timestamp and the hint value specified on the Advise call.
<script for=”objectName” event=”OnSceneLoaded(bSuccess)” language=”javascript”>
if(bSuccess)
objectName.Engine.Nodes(“MyTransform”).Fields(“translation”).Advise(myHandler,’my transform’);
function myHandler(value,hint,timestamp){
if(hint==’my transform’) …
</script>
First you must create a javascript function in the HTML page and call Advise() for some eventOut or exposedField in the VRML scene, setting this function as the event handler:
objectName1.Engine.Nodes(“SomeNodeName”).Fields(“someEventOut”).Advise(someFunc
tion,””);
When the event is fired, it runs this function, which can change something in the other Cortona control:
function someFunction(value,hint,timestamp){
objectName2.Engine.Nodes(“SomeNodeName”).Fields(“someEventIn”).Value=value.Value;
}
Engine.nodes,Engine.rootNodes还有fields(“fieldName”)显然有不少方法,哪里去找呢?