{"id":348,"date":"2008-07-04T18:10:34","date_gmt":"2008-07-04T18:10:34","guid":{"rendered":""},"modified":"2013-02-27T12:23:06","modified_gmt":"2013-02-27T04:23:06","slug":"348","status":"publish","type":"post","link":"https:\/\/1vr.cn\/?p=348","title":{"rendered":"JAVAScript-EAI"},"content":{"rendered":"<p>BlaxxunContact\uff083.07\u4ee5\u4e0a\u7248\u672c\uff09\u4e3aJavaScript\u548cVBScript\u63d0\u4f9b\u4e00\u79cd\u5e94\u7528\u8d77\u6765\u975e\u5e38\u7b80\u5355\u7684\u5916\u90e8\u811a\u672c\u63a5\u53e3\uff0c\u5b83\u5141\u8bb8\u4f60\u4ece\u5df2\u7ecf\u547d\u540d\u7684\u8282\u70b9\u5f53\u4e2d\u8bfb\u5199\u4efb\u610f\u4e00\u4e2a\u57df\u503c\u3002\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u8f93\u5165\u7684\u503c\u88ab\u81ea\u52a8\u7684\u8f6c\u6362\u6210\u9002\u5f53\u7684\u7c7b\u578b\u3002\u5e76\u4e14,VBScript\uff08in Internet Explorer\uff09\u4e0e JavaScript\uff08in Netscape\uff09\u7684\u65b9\u6cd5\u80fd\u591f\u88abVRML Script\u5185\u90e8\u7684Script\u8282\u70b9\u8c03\u7528\u3002<\/p>\n<p>\u6d4f\u89c8\u5668\u53e5\u67c4\uff08<\/p>\n<p>JS\u8c03\u7528\u652f\u6301<br \/>\u4ee5\u4e0b\u662f\u53ef\u7528\u4e8e\u901a\u8fc7JavaScript\u8bbf\u95ee\u7684blaxxun3D\u63a5\u53e3<br \/>setNodeEventIn<br \/>(String nodeName,<br \/>String eventInName,<br \/>String value) \u8bbe\u7f6e\u5df2\u547d\u540d\u7684\u8282\u70b9\u7684\u6307\u5b9a\u4e8b\u4ef6\u5165\u53e3\u503c\uff0c\u5176value\u4f1a\u81ea\u52a8\u8f6c\u6362\u6210\u8be5\u4e8b\u4ef6\u5165\u53e3\u7684\u7c7b\u578b <br \/>getNodeEventOut<br \/>(String nodeName,<br \/>String eventOutName) \u8fd4\u56de\u4e00\u4e2a\u4e8b\u4ef6\u51fa\u53e3\u7684\u503c\uff0c\u5e76\u628a\u8be5\u503c\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\u683c\u5f0f <br \/>OnNextViewpoint( )<br \/>\uff08\u4ec5\u7528\u4e8eIE\u6d4f\u89c8\u5668\uff01\uff09 \u6fc0\u6d3b\u89c6\u70b9\u5806\u6808\u5f53\u4e2d\u7684\u4e0b\u4e00\u4e2a\u89c6\u70b9 <br \/>setNextViewpoint( )<br \/>\uff08\u4ec5\u7528\u4e8eNetscape\u6d4f\u89c8\u5668\uff01\uff09 \u4e0e\u4e0a\u9762\u7684\u51fd\u6570\u529f\u80fd\u76f8\u540c\uff0c\u4f46\u662f\u53ea\u80fd\u7528\u4e8eNetscape\u6d4f\u89c8\u5668 <\/p>\n<p>\u5728VRML\u5f53\u4e2d\u8bbf\u95ee<br \/>\u53ef\u4ee5\u5728VRML\u6587\u4ef6\u5f53\u4e2d\u8bbf\u95eeHTML\u5f53\u4e2d\u4efb\u4f55\u4e00\u4e2aJavaScript\u51fd\u6570\u3002\u628a\u4e0b\u9762\u7684\u8fd9\u4e2a\u8c03\u7528\u65b9\u6cd5\u5e94\u7528\u4e8eAnchor\u8282\u70b9\uff0c\u6216\u8005\u7528Script\u8282\u70b9\u5f53\u4e2d\u7684Browser . loadURL\u65b9\u6cd5\u6765\u6307\u5b9a\u76f8\u5e94\u7684\u51fd\u6570\u65b9\u6cd5\u3002<\/p>\n<p>\u201cjavascript:myJSFunction();\u201d<\/p>\n<p>\u5982\u679c\u6307\u5b9a\u7684\u65b9\u6cd5\u662f\u5b9a\u4e49\u5728\u4e00\u4e2aHTML\u6587\u6863\u7684\u5176\u4ed6\u6846\u67b6\u5f53\u4e2d\uff0c\u5219\u76ee\u6807\u5fc5\u987b\u7528Anchor\u8282\u70b9\u7684parameters\u57df\u6216\u8005\u5728Browser . loadURL\u65b9\u6cd5\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u3002\u8bf7\u53c2\u8003\u4ee5\u4e0b\u4f8b\u5b50\uff1a<\/p>\n<p>Example 1: Calling a JS-Function by an Anchor <br \/>DEF anchor1 Anchor{&nbsp;&nbsp;JavaScript<br \/>url&#8221;javascript:externalFunction();&#8221; <br \/>parameter[&#8220;target=_self&#8221;]&nbsp;&nbsp;<br \/>children[ #some geometry&nbsp;&nbsp; ]<br \/>}<br \/>Example 2: Calling a JS-Function from a Script <br \/>Script{&nbsp;&nbsp;<br \/>field MFString param [&#8220;target=someFrame&#8221;, &#8220;&#8221;]&nbsp;&nbsp;<br \/>eventIn SFTime touch&nbsp;&nbsp;<br \/>url&#8221;vrmlscript:&nbsp;&nbsp;<br \/>function touch()&nbsp;&nbsp;<br \/>{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Browser.loadURL(&#8216;javascript:externalFunction()&#8217;, param);&nbsp;&nbsp;<br \/>}&nbsp;&nbsp;<br \/>&#8220;<br \/>} <\/p>\n<p>\u4e3a\u4e86\u80fd\u591f\u5f71\u54cd3D\u573a\u666f\uff0c\u4f60\u9700\u8981\u83b7\u5f97\u4e00\u4e2aVRML\u6d4f\u89c8\u5668\u7684\u53e5\u67c4\u3002\u53ef\u4ee5\u5229\u7528\u5b9a\u4e49\u5728embed\u6807\u7b7e\u5f53\u4e2d\u7684\u540d\u79f0\u6765\u8bbf\u95ee\u63d2\u4ef6\uff0c\u5404\u81ea\u7684ID\u5b9a\u4e49\u5728Objedt\u6807\u7b7e\u5185\u3002\u8fd9\u4e9b\u53c2\u91cf\u7684\u8be6\u7ec6\u8d44\u6599\u8bf7\u53c2\u8003&#8221;Embedding blaxxunContact&#8221;<\/p>\n<p>blaxxun Contact 3D (release 3.07 or higher) supports an easy-to-use external scripting interface for Javascript and VBScript. It allows to read and write any fields values of named nodes. String input values are converted automatically to the appropriate field types. Additionally VBScript (in Internet Explorer) and Javascript (in Netscape) methods can be called from internal VRMLScript script nodes. <\/p>\n<p>General syntax <\/p>\n<p>void Browser.setNodeEventIn( String nodeName, String eventInName, String value) <\/p>\n<p>set the value for the specified eventIn converting value to the type of the eventIn <br \/>String Browser.getNodeEventOut( String nodeName, String eventOutName) <br \/>returns the value of the eventOut converted to a string <br \/>callback from internal script nodes: <br \/>Netscape Javascript: OnEvent ( String, par1, String par2, String timestamp ) <br \/>Internet Explorer VBscript: &lt;Contact3D_ID&gt;_OnEvent ( String, par1, String par2, String timestamp ) <br \/>the method OnEvent can be called from VRMLScript using the Browser.loadURL() method with 2 parameters (see example) <br \/>HTML Page contents for using the Script EAI with Microsoft and Netscape Browsers <\/p>\n<p>1. Embed the VRML browser and give it a name: <\/p>\n<p>&lt;OBJECT CLASSID=&#8221;CLSID:4B6E3013-6E45-11D0-9309-0020AFE05CC8&#8243; ID= CC3D WIDTH=100% HEIGHT=50%&gt; <\/p>\n<p>&lt;PARAM NAME=&#8221;SRC&#8221; VALUE=&#8221;sample.wrl&#8221;&gt; <\/p>\n<p>&lt;EMBED name= CC3D SRC=&#8221;sample.wrl&#8221; TYPE= &#8220;application\/x-cc3d&#8221; WIDTH=100% HEIGHT=50%&gt; <\/p>\n<p>&lt;\/OBJECT&gt; <\/p>\n<p>2. Sending an event to VRML from JavaScript: <\/p>\n<p>You can send events to VRML from JavaScript using setNodeEventIn, as<br \/>shown below.&nbsp;&nbsp;&nbsp;&nbsp;It requires, as parameters, the VRML target node, the field<br \/>that will be changed, and the value that will be sent.&nbsp;&nbsp;&nbsp;&nbsp;The parameters can<br \/>be set as strings, and will be automatically converted to the correct<br \/>type.<\/p>\n<p>function sendEvent(node, field, value)<br \/>{<br \/>document.Contact 3D.setNodeEventIn(node, field, value)<br \/>}<\/p>\n<p>In the example the sendText function, shown below, uses sendEvent to send<br \/>an event to the ChangeString node in the VRML, and will change the<br \/>field set_string for that node using value.<\/p>\n<p>function sendText(value)<br \/>{<br \/>sendEvent(&#8216;ChangeString&#8217;, &#8216;set_string&#8217;, value);<br \/>}<br \/>3. Calling JavaScript from VRML: <br \/>Here when the touchTime event occurs, set_string is called in the<br \/>script node.&nbsp;&nbsp;&nbsp;&nbsp;The Script method OnEvent() will be called with the specified parameters. <br \/>Of course par1 and par2 can be replaced at runtime by actual parameters.<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;DEF RotationScript Script { <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;field MFString newurl [ &#8220;OnEvent( par1, par2 )&#8221; ]<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;field MFString param [ &#8220;&#8221; &#8220;&#8221; ]<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eventIn&nbsp;&nbsp;&nbsp;&nbsp;SFTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clicked <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eventIn&nbsp;&nbsp;&nbsp;&nbsp;SFTime&nbsp;&nbsp;&nbsp;&nbsp; set_string <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eventOut SFRotation rotation_changed <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url &#8220;vrmlscript: <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function clicked (value, time) { <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;angle = Math.random()*6.283; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rotation_changed = new SFRotation(0,1,0,angle); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function set_string (value, time) { <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Browser.loadURL(newurl,param);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <\/p>\n<p>ROUTE RotSensor.touchTime TO RotationScript.set_string<br \/>and the HTML definition:<br \/>&lt;SCRIPT language=Javascript&gt;<br \/>function OnEvent(par1, par2, time) <br \/>{ document.sform.sfield.value = par1 + par2 + time; }<br \/>&lt;\/SCRIPT&gt;<br \/>4. Use VBScript to activate the OnEvent method with Internet Explorer: <br \/>Internet Explorer doesn&#8217;t allow to call Javascript directly from a C program. Therefore VBScript has to be used to pass the call to Javascript. The name of the sub is &lt;objectid&gt;_OnEvent. <\/p>\n<p> &lt;scriptlanguage=<br \/>VBScript&gt; <br \/>&lt;!&#8211;&nbsp;&nbsp;&nbsp;&nbsp;sub CC3D_OnEvent(par1, par2, time) <br \/>OnEvent par1, par2, time <br \/>end sub<br \/>!&#8211;&gt;<br \/>&lt;\/script&gt;<br \/>Examples <\/p>\n<p>Please check the blaxxun Client SDK.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>BlaxxunContact\uff083.07\u4ee5\u4e0a\u7248\u672c\uff09\u4e3aJavaScript\u548cVBScript\u63d0\u4f9b\u4e00\u79cd\u5e94\u7528\u8d77\u6765\u975e\u5e38\u7b80 &hellip; <a href=\"https:\/\/1vr.cn\/?p=348\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">JAVAScript-EAI<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-348","post","type-post","status-publish","format-standard","hentry","without-featured-image"],"_links":{"self":[{"href":"https:\/\/1vr.cn\/index.php?rest_route=\/wp\/v2\/posts\/348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1vr.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1vr.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1vr.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/1vr.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=348"}],"version-history":[{"count":1,"href":"https:\/\/1vr.cn\/index.php?rest_route=\/wp\/v2\/posts\/348\/revisions"}],"predecessor-version":[{"id":987,"href":"https:\/\/1vr.cn\/index.php?rest_route=\/wp\/v2\/posts\/348\/revisions\/987"}],"wp:attachment":[{"href":"https:\/\/1vr.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1vr.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1vr.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}