效果图:
<FONT face="Arial, Helvetica, sans-serif">
<CENTER>
<OBJECT CLASSID="CLSID:4B6E3013-6E45-11D0-9309-0020AFE05CC8" NAME=CC3D ID=CC3D WIDTH=100% HEIGHT=50%>
<PARAM NAME="SRC" VALUE="sample.wrl">
<EMBED name=CC3D SRC="sample.wrl" TYPE="application/x-cc3d"
WIDTH=100% HEIGHT=50%>
</OBJECT>
</CENTER>
<P><B>事件触发</B><BR>
<TABLE width=140 align=left >
<TR>
<TD width=140>
<TABLE width=140 align=right >
<TR>
<TD>
<A HREF="javascript:sendEvent('BoxColor','set_diffuseColor','0 1 0')" onMouseOver="window.status='set color'; return true;" onMouseOut="window.status=''; return true;">设置漫射色为绿色</a>
<br>
<A HREF="javascript:sendEvent('BoxColor','set_diffuseColor','1 0 0')" onMouseOver="window.status='set color'; return true;" onMouseOut="window.status=''; return true;">设置漫射色为红色</a>
<br>
<A HREF="javascript:sendEvent('BoxSwitch','set_whichChoice','-1')" onMouseOver="window.status='hide'; return true;" onMouseOut="window.status=''; return true;">隐藏</a>
<br>
<A HREF="javascript:sendEvent('BoxSwitch','set_whichChoice','0')" onMouseOver="window.status='show'; return true;" onMouseOut="window.status=''; return true;">显示</a>
<br>
<A HREF="javascript:sendEvent('RotationScript','clicked','12345678')" onMouseOver="window.status='rotate'; return true;" onMouseOut="window.status=''; return true;">旋转</a>
<br>
<A HREF="javascript:getEvent('BoxColor','diffuseColor_changed')" onMouseOver="window.status='get color'; return true;" onMouseOut="window.status=''; return true;">获得物体漫射色</a>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</P>
<P><form NAME=sform ACTION="javascript:sendText(document.sform.sfield.value)" METHOD=POST >
<input type=button onclick=sendText(form.sfield.value) value="输入字符串">
<input type=text name=sfield value="Welcome!ChineseVRFans!" size=26>
</form>
<script language="VBScript">
<!--
sub CC3D_OnEvent(par1, par2, time)
OnEvent par1, par2, time
end sub
-->
</script>
</BODY>
</HTML>
-----------------------------------------------------------
VRML源代码:
#VRML V2.0 utf8
EXTERNPROTO BlaxxunZone [
eventIn MFNode addEvents
eventIn MFNode removeEvents
exposedField MFNode events
][ "shared.wrl#BlaxxunZone", "http://www.blaxxun.com/vrml/protos/shared.wrl#BlaxxunZone" ]
EXTERNPROTO SharedEvent [
exposedField SFString name # for accessing a special event
eventIn SFColor colorFromServer
eventOut SFColor colorToServer
eventIn SFColor set_color
eventOut SFColor color_changed
eventIn SFRotation rotationFromServer
eventOut SFRotation rotationToServer
eventIn SFRotation set_rotation
eventOut SFRotation rotation_changed
eventOut SFString string_changed
eventIn SFString stringFromServer
] [ "shared.wrl#SharedEvent", "http://www.blaxxun.com/vrml/protos/shared.wrl#SharedEvent" ]
DEF SharedZone BlaxxunZone {
events [
DEF SharedColor SharedEvent { name "newColor" }
DEF SharedRotation SharedEvent { name "newRotation" }
]
}
DEF BoxSwitch Switch {
whichChoice 0
choice [
DEF BoxRotation Transform {
children [
Shape { # 红色立方体
appearance Appearance { material DEF BoxColor Material { diffuseColor 1 0 0 } }
geometry Box { }
}
]
}
]
}
# 此球体用来更换颜色
Transform {
translation -4 0 0
children [
Shape {
appearance Appearance { material Material { diffuseColor 0 0 1 } }
geometry Sphere {}
},
DEF ColorSensor TouchSensor {},
DEF ColorScript Script {
eventIn SFTime clicked
eventIn SFString changeColor
eventOut SFColor color_changed
eventOut SFColor color_changed_from_bot
url "vrmlscript:
function clicked (value, time) {
color_changed = new SFColor(Math.random(),Math.random(),Math.random());
}
function changeColor (value, time) {
tempColor = new SFColor(1,0,0);
temp = new SFString(value);
pos1 = 7;
for (i=0; i<3;i++){
temp2 = new SFString(temp.substring(pos1,pos1+1));
if (temp2 == '1')
tempColor[i] = 1;
pos2 = temp.indexOf(' ',pos1);
pos1 = pos2+1;
}
color_changed_from_bot = tempColor;
}
"
}
]
}
# 此锥体用来旋转更换
Transform {
translation 4 0 0
children [
Shape {
appearance Appearance { material Material { diffuseColor 0 0 1 } }
geometry Cone {}
},
DEF RotSensor TouchSensor {},
DEF RotationScript Script {
field MFString newurl [ "OnEvent( par1, par2 )" ]
# field MFString newurl [ "javascript:OnJSEvent( )" ]
field MFString param [ "" "" ]
eventIn SFTime clicked
eventIn SFTime set_string
eventOut SFRotation rotation_changed
url "vrmlscript:
function clicked (value, time) {
angle = Math.random()*6.283;
rotation_changed = new SFRotation(0,1,0,angle);
}
function set_string (value, time) {
newurl[0] = 'OnEvent ( ' + 'your par1 ' + ',' + 'your par2' + ')';
Browser.loadURL (newurl,param);
}
"
}
]
}
Transform {
translation 0 -3 0
children [
DEF ChangeString Text { string "ChangeString" }
]
}
Script
{
url "vrmlscript:
function initialize() {
}"
}
#ROUTE RotSensor.touchTime TO RotationScript.clicked
ROUTE RotSensor.touchTime TO RotationScript.set_string
#ROUTE RotationScript.rotation_changed TO SharedRotation.set_rotation
ROUTE RotationScript.rotation_changed TO BoxRotation.set_rotation
ROUTE SharedRotation.rotation_changed TO BoxRotation.rotation
ROUTE ColorSensor.touchTime TO ColorScript.clicked
ROUTE ColorScript.color_changed TO SharedColor.set_color
ROUTE SharedColor.color_changed TO BoxColor.diffuseColor
ROUTE ColorScript.color_changed_from_bot TO BoxColor.diffuseColor
ROUTE SharedColor.string_changed TO ColorScript.changeColor
联系客服