У меня был следующий код, работающий в средствах просмотра X3D, но теперь я пытаюсь запустить его в веб-браузере (Google Chrome), используя X3DOM (http://x3dom.org/). Я получаю узлы, но не ссылки; какой-то текст отображается как ошибка.
Может быть, какой-нибудь программист X3DOM может посмотреть и сказать мне, как исправить. Думаю, я близок.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en" lang="en">
<head>
<!-- FileName: nodeLinkToggleExtrusion.xhtml -->
<!-- -->
<!-- Description: dynamic scene graph of nodes and link(s): -->
<!-- node toggle of text, -->
<!-- link toggle of text, -->
<!-- extrusion of link(s) between nodes, -->
<!-- animation of packet exchange using -->
<!-- ROUTE mechanism between nodes. -->
<!-- node geometry are spheres using -->
<!-- cylinders for link extrusion. -->
<!-- -->
<!-- By: Andrew M. Neiderer. -->
<!-- -->
<!-- Reference: Sergey Bederov, Parallel Graphics, Inc. -->
<!-- for link extrusion and -->
<!-- packet exchange between nodes. -->
<!-- -->
<!-- Date: 7 July 2020. -->
<meta http-equiv="X-UA-Compatible"
content="chrome=1"/>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css"
src="http://x3dom.org/x3dom/example/x3dom.js"/>
<!-- href="/home/andrewmneiderer/lib/x3dom.css"/> -->
<script type="text/ecmascript"
src="http://x3dom.org/x3dom/example/x3dom.js"/>
<!-- src="/home/andrewmneiderer/lib/x3dom.js"/> -->
</head>
<body>
<X3D profile="Immersive" version="3.1">
<Scene>
<!-- node 1 -->
<Group DEF="GROUP_node1">
<Transform DEF="TRANSFORM_node1"
translation="-2.0 2.0 -2.0">
<Shape DEF="SHAPE_node">
<Appearance>
<Material DEF="MATERIAL_node"
diffuseColor="1.0 0.0 0.0"
transparency="0.3"/>
</Appearance>
<Sphere/>
</Shape>
<!-- toggle text on the node -->
<Switch DEF="SWITCH_node1">
<Transform translation="-1.5 -0.75 -0.5">
<!-- appearance and text -->
<Shape>
<Appearance>
<Material USE="MATERIAL_node"/>
</Appearance>
<Text DEF="TEXT_node1"
containerField="geometry"
maxExtent="0.0"
string="node 1">
<FontStyle DEF="FONT_STYLE_nodeAndLink"
containerField="fontStyle"
family='"SERIF"'
horizontal="true"
justify='"BEGIN"'
leftToRight="true"
size="1.0"
spacing="1.0"
style="PLAIN"
topToBottom="true"/>
</Text>
</Shape>
</Transform>
</Switch>
</Transform>
<PlaneSensor DEF="PLANE_SENSOR_node1"
offset="-2.0 2.0 -2.0"/>
<TouchSensor DEF="TOUCH_SENSOR_node1" enabled="true"/>
</Group>
<Script DEF="SCRIPT_touchSwitch_node1">
<field name="touch_node" type="SFTime" accessType="inputOnly"/>
<field name="onOff_node" type="SFInt32" accessType="outputOnly"/>
<field name="active_node" type="SFBool" accessType="initializeOnly"
value="false"/>
<![CDATA[ecmascript:
function touch_node()
{
if ( active_node ) {
onOff_node = 1;
active_node = false;
}
else {
onOff_node = 0;
active_node = true;
}
}
]]>
</Script>
<!-- node 2 -->
<Group DEF="GROUP_node2">
<Transform DEF="TRANSFORM_node2"
translation="0.0 -2.0 0.0">
<Shape USE="SHAPE_node"/>
<!-- toggle text on the node -->
<Switch DEF="SWITCH_node2">
<Transform translation="-1.5 -0.75 -0.5">
<!-- appearance and text -->
<Shape>
<Appearance>
<Material USE="MATERIAL_node"/>
</Appearance>
<Text DEF="TEXT_node2"
containerField="geometry"
maxExtent="0.0"
string="node 2">
<FontStyle USE="FONT_STYLE_nodeAndLink"/>
</Text>
</Shape>
</Transform>
</Switch>
</Transform>
<PlaneSensor DEF="PLANE_SENSOR_node2"
offset="0.0 -2.0 0.0"/>
<TouchSensor DEF="TOUCH_SENSOR_node2" enabled="true"/>
</Group>
<Script DEF="SCRIPT_touchSwitch_node2">
<field name="touch_node" type="SFTime" accessType="inputOnly"/>
<field name="onOff_node" type="SFInt32" accessType="outputOnly"/>
<field name="active_node" type="SFBool" accessType="initializeOnly"
value="false"/>
<![CDATA[ecmascript:
function touch_node()
{
if ( active_node ) {
onOff_node = 1;
active_node = false;
}
else {
onOff_node = 0;
active_node = true;
}
}
]]>
</Script>
<!-- node 3 -->
<Group DEF="GROUP_node3">
<Transform DEF="TRANSFORM_node3"
translation="2.0 2.0 2.0">
<Shape USE="SHAPE_node"/>
<!-- toggle text on the node -->
<Switch DEF="SWITCH_node3">
<Transform translation="-1.5 -0.75 -0.5">
<!-- appearance and text -->
<Shape>
<Appearance>
<Material USE="MATERIAL_node"/>
</Appearance>
<Text DEF="TEXT_node3"
containerField="geometry"
maxExtent="0.0"
string="node 3">
<FontStyle USE="FONT_STYLE_nodeAndLink"/>
</Text>
</Shape>
</Transform>
</Switch>
</Transform>
<PlaneSensor DEF="PLANE_SENSOR_node3"
offset="2.0 2.0 2.0"/>
<TouchSensor DEF="TOUCH_SENSOR_node3" enabled="true"/>
</Group>
<Script DEF="SCRIPT_touchSwitch_node3">
<field name="touch_node" type="SFTime" accessType="inputOnly"/>
<field name="onOff_node" type="SFInt32" accessType="outputOnly"/>
<field name="active_node" type="SFBool" accessType="initializeOnly"
value="false"/>
<![CDATA[ecmascript:
function touch_node()
{
if ( active_node ) {
onOff_node = 1;
active_node = false;
}
else {
onOff_node = 0;
active_node = true;
}
}
]]>
</Script>
<!-- link from node 1 to node 2 -->
<Group DEF="GROUP_link_1_2">
<Transform DEF="TRANSFORM_link_1_2"
translation="0.0 0.0 0.0">
<Shape DEF="SHAPE_link_1_2">
<Appearance >
<Material DEF="MATERIAL_link"
diffuseColor="0.0 0.3 1.0"/>
</Appearance>
<Extrusion DEF="EXTRUSION_link_1_2"
crossSection=" 0.1 0.2,
0.2 0.0,
0.1 -0.2,
-0.1 -0.2,
-0.2 0.0,
-0.1 0.2,
0.1 0.2"
solid="false"
creaseAngle="1.2"
spine="-2.0 2.0 -2.0,
0.0 -2.0 0.0"/>
</Shape>
<!-- toggle text on the link -->
<Switch DEF="SWITCH_link_1_2">
<Transform translation="-1.0 0.0 -1.0">
<!-- appearance and text -->
<Shape>
<Appearance>
<Material USE="MATERIAL_link"/>
<Text DEF="TEXT_link_1_2"
containerField="geometry"
maxExtent="0.0"
string="link from node 1 to node 2">
<FontStyle USE="FONT_STYLE_nodeAndLink"/>
</Text>
</Shape>
</Transform>
</Switch>
<PlaneSensor DEF="PLANE_SENSOR_link_1_2"
offset="0.0 0.0 0.0"/>
<TouchSensor DEF="TOUCH_SENSOR_link_1_2" enabled="true"/>
</Transform>
</Group>
<Script DEF="SCRIPT_touchSwitch_link_1_2">
<field name="touch_link" type="SFTime" accessType="inputOnly"/>
<field name="onOff_link" type="SFInt32" accessType="outputOnly"/>
<field name="active_link" type="SFBool" accessType="initializeOnly"
value="false"/>
<![CDATA[ecmascript:
function touch_link()
{
if ( active_link ) {
onOff_link = 1;
active_link = false;
}
else {
onOff_link = false;
active_link = 1;
}
}
]]>
</Appearance>
</Script>
<!-- dynamic link from node 1 to node 2 -->
<Script DEF="SCRIPT_link_1_2">
<field name="translationA" type="SFVec3f" accessType="inputOnly"/>
<field name="translationZ" type="SFVec3f" accessType="inputOnly"/>
<field name="spine" type="MFVec3f"
value="-2.0 2.0 -2.0,
0.0 -2.0 0.0"
accessType="initializeOnly"/>
<field name="spine_changed" type="MFVec3f" accessType="outputOnly"/>
<![CDATA[ecmascript:
function translationA(value)
{
spine[0] = value;
spine_changed = spine;
}
function translationZ(value)
{
spine[1] = value;
spine_changed = spine;
}
]]>
</Script>
<!-- link from node 2 to node 3 -->
<Group DEF="GROUP_link_2_3">
<Transform DEF="TRANSFORM_link_2_3"
translation="0.0 0.0 0.0">
<Shape DEF="SHAPE_link_2_3">
<Appearance >
<Material USE="MATERIAL_link"/>
</Appearance>
<Extrusion DEF="EXTRUSION_link_2_3"
crossSection=" 0.1 0.2,
0.2 0.0,
0.1 -0.2,
-0.1 -0.2,
-0.2 0.0,
-0.1 0.2,
0.1 0.2"
solid="false"
creaseAngle="1.2"
spine=" 0.0 -2.0 0.0,
2.0 2.0 2.0"/>
</Shape>
<!-- toggle text on the link -->
<Switch DEF="SWITCH_link_2_3">
<Transform translation="-1.0 0.0 -1.0">
<!-- appearance and text -->
<Shape>
<Appearance>
<Material USE="MATERIAL_link"/>
</Appearance>
<Text DEF="TEXT_link_2_3"
containerField="geometry"
maxExtent="0.0"
string="link from node 2 to node 3">
<FontStyle USE="FONT_STYLE_nodeAndLink"/>
</Text>
</Shape>
</Transform>
</Switch>
<PlaneSensor DEF="PLANE_SENSOR_link_2_3"
offset="0.0 0.0 0.0"/>
<TouchSensor DEF="TOUCH_SENSOR_link_2_3" enabled="true"/>
</Transform>
</Group>
<Script DEF="SCRIPT_touchSwitch_link_2_3">
<field name="touch_link" type="SFTime" accessType="inputOnly"/>
<field name="onOff_link" type="SFInt32" accessType="outputOnly"/>
<field name="active_link" type="SFBool" accessType="initializeOnly"
value="false"/>
<![CDATA[ecmascript:
function touch_link()
{
if ( active_link ) {
onOff_link = 1;
active_link = false;
}
else {
onOff_link = false;
active_link = 1;
}
}
]]>
</Script>
<!-- dynamic link from node 2 to node 3 -->
<Script DEF="SCRIPT_link_2_3">
<field name="translationA" type="SFVec3f" accessType="inputOnly"/>
<field name="translationZ" type="SFVec3f" accessType="inputOnly"/>
<field name="spine" type="MFVec3f"
value=" 0.0 -2.0 0.0,
2.0 2.0 2.0"
accessType="initializeOnly"/>
<field name="spine_changed" type="MFVec3f" accessType="outputOnly"/>
<![CDATA[ecmascript:
function translationA(value)
{
spine[0] = value;
spine_changed = spine;
}
function translationZ(value)
{
spine[1] = value;
spine_changed = spine;
}
]]>
</Script>
<!-- link from node 3 to node 1 -->
<Group DEF="GROUP_link_3_1">
<Transform DEF="TRANSFORM_link_3_1"
translation="0.0 0.0 0.0">
<Shape DEF="SHAPE_link_3_1">
<Appearance >
<Material USE="MATERIAL_link"/>
</Appearance>
<Extrusion DEF="EXTRUSION_link_3_1"
crossSection=" 0.1 0.2,
0.2 0.0,
0.1 -0.2,
-0.1 -0.2,
-0.2 0.0,
-0.1 0.2,
0.1 0.2"
solid="false"
creaseAngle="1.2"
spine=" 2.0 2.0 2.0,
-2.0 2.0 -2.0"/>
</Shape>
<!-- toggle text on the link -->
<Switch DEF="SWITCH_link_3_1">
<Transform translation="-1.0 0.0 -1.0">
<!-- appearance and text -->
<Shape>
<Appearance>
<Material USE="MATERIAL_link"/>
</Appearance>
<Text DEF="TEXT_link_3_1"
containerField="geometry"
maxExtent="0.0"
string="link from node 3 to node 1">
<FontStyle USE="FONT_STYLE_nodeAndLink"/>
</Text>
</Shape>
</Transform>
</Switch>
<PlaneSensor DEF="PLANE_SENSOR_link_3_1"
offset="0.0 0.0 0.0"/>
<TouchSensor DEF="TOUCH_SENSOR_link_3_1" enabled="true"/>
</Transform>
</Group>
<Script DEF="SCRIPT_touchSwitch_link_3_1">
<field name="touch_link" type="SFTime" accessType="inputOnly"/>
<field name="onOff_link" type="SFInt32" accessType="outputOnly"/>
<field name="active_link" type="SFBool" accessType="initializeOnly"
value="false"/>
<![CDATA[ecmascript:
function touch_link()
{
if ( active_link ) {
onOff_link = 1;
active_link = false;
}
else {
onOff_link = false;
active_link = 1;
}
}
]]>
</Script>
<!-- dynamic link from node 3 to node 1 -->
<Script DEF="SCRIPT_link_3_1">
<field name="translationA" type="SFVec3f" accessType="inputOnly"/>
<field name="translationZ" type="SFVec3f" accessType="inputOnly"/>
<field name="spine" type="MFVec3f"
value=" 2.0 2.0 2.0,
-2.0 2.0 -2.0"
accessType="initializeOnly"/>
<field name="spine_changed" type="MFVec3f" accessType="outputOnly"/>
<![CDATA[ecmascript:
function translationA(value)
{
spine[0] = value;
spine_changed = spine;
}
function translationZ(value)
{
spine[1] = value;
spine_changed = spine;
}
]]>
</Script>
<!-- animation -->
<ROUTE fromNode="PLANE_SENSOR_node1" fromField="translation_changed"
toNode= "TRANSFORM_node1" toField= "translation"/>
<ROUTE fromNode="PLANE_SENSOR_node2" fromField="translation_changed"
toNode= "TRANSFORM_node2" toField= "translation"/>
<ROUTE fromNode="PLANE_SENSOR_node3" fromField="translation_changed"
toNode= "TRANSFORM_node3" toField= "translation"/>
<!-- node 1 toggle -->
<ROUTE fromNode="TOUCH_SENSOR_node1" fromField="touchTime"
toNode= "SCRIPT_touchSwitch_node1" toField= "touch_node"/>
<ROUTE fromNode="SCRIPT_touchSwitch_node1" fromField="onOff_node"
toNode= "SWITCH_node1" toField= "whichChoice"/>
<!-- node 2 toggle -->
<ROUTE fromNode="TOUCH_SENSOR_node2" fromField="touchTime"
toNode= "SCRIPT_touchSwitch_node2" toField= "touch_node"/>
<ROUTE fromNode="SCRIPT_touchSwitch_node2" fromField="onOff_node"
toNode= "SWITCH_node2" toField= "whichChoice"/>
<!-- node 3 toggle -->
<ROUTE fromNode="TOUCH_SENSOR_node3" fromField="touchTime"
toNode= "SCRIPT_touchSwitch_node3" toField= "touch_node"/>
<ROUTE fromNode="SCRIPT_touchSwitch_node3" fromField="onOff_node"
toNode= "SWITCH_node3" toField= "whichChoice"/>
<!-- toggle link from node 1 to node 2 -->
<ROUTE fromNode="TOUCH_SENSOR_link_1_2" fromField="touchTime"
toNode= "SCRIPT_touchSwitch_link_1_2" toField= "touch_link"/>
<ROUTE fromNode="SCRIPT_touchSwitch_link_1_2" fromField="onOff_link"
toNode= "SWITCH_link_1_2" toField= "whichChoice"/>
<!-- toggle link from node 2 to node 3 -->
<ROUTE fromNode="TOUCH_SENSOR_link_2_3" fromField="touchTime"
toNode= "SCRIPT_touchSwitch_link_2_3" toField= "touch_link"/>
<ROUTE fromNode="SCRIPT_touchSwitch_link_2_3" fromField="onOff_link"
toNode= "SWITCH_link_2_3" toField= "whichChoice"/>
<!-- toggle link from node 3 to node 1 -->
<ROUTE fromNode="TOUCH_SENSOR_link_3_1" fromField="touchTime"
toNode= "SCRIPT_touchSwitch_link_3_1" toField= "touch_link"/>
<ROUTE fromNode="SCRIPT_touchSwitch_link_3_1" fromField="onOff_link"
toNode= "SWITCH_link_3_1" toField= "whichChoice"/>
<!-- link extrusion(s) for node 1 -->
<ROUTE fromNode="TRANSFORM_node1" fromField="translation"
toNode= "SCRIPT_link_1_2" toField= "translationA"/>
<ROUTE fromNode="SCRIPT_link_1_2" fromField="spine_changed"
toNode= "EXTRUSION_link_1_2" toField= "set_spine"/>
<ROUTE fromNode="TRANSFORM_node1" fromField="translation"
toNode= "SCRIPT_link_3_1" toField= "translationZ"/>
<ROUTE fromNode="SCRIPT_link_3_1" fromField="spine_changed"
toNode= "EXTRUSION_link_3_1" toField= "set_spine"/>
<!-- link extrusion(s) for node 2 -->
<ROUTE fromNode="TRANSFORM_node2" fromField="translation"
toNode= "SCRIPT_link_2_3" toField= "translationA"/>
<ROUTE fromNode="SCRIPT_link_2_3" fromField="spine_changed"
toNode= "EXTRUSION_link_2_3" toField= "set_spine"/>
<ROUTE fromNode="TRANSFORM_node2" fromField="translation"
toNode= "SCRIPT_link_1_2" toField= "translationZ"/>
<ROUTE fromNode="SCRIPT_link_1_2" fromField="spine_changed"
toNode= "EXTRUSION_link_1_2" toField= "set_spine"/>
<!-- link extrusion(s) for node 3 -->
<ROUTE fromNode="TRANSFORM_node3" fromField="translation"
toNode= "SCRIPT_link_3_1" toField= "translationA"/>
<ROUTE fromNode="SCRIPT_link_3_1" fromField="spine_changed"
toNode= "EXTRUSION_link_3_1" toField= "set_spine"/>
<ROUTE fromNode="TRANSFORM_node3" fromField="translation"
toNode= "SCRIPT_link_2_3" toField= "translationZ"/>
<ROUTE fromNode="SCRIPT_link_2_3" fromField="spine_changed"
toNode= "EXTRUSION_link_2_3" toField= "set_spine"/>
</Scene>
</X3D>
</body>
</html>