Skip to content

Instantly share code, notes, and snippets.

@andreasplesch
Last active November 19, 2017 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasplesch/fcffcce2722eb0a5b9520d8a52ee732e to your computer and use it in GitHub Desktop.
Save andreasplesch/fcffcce2722eb0a5b9520d8a52ee732e to your computer and use it in GitHub Desktop.
x3dom multiview sync with inlined viewpoints
<x3d>
<scene>
<viewpoint DEF='vp'></viewpoint>
<shape>
<appearance>
<material diffuseColor='1 0 0'></material>
</appearance>
<box></box>
</shape>
<transform translation='-3 0 0'>
<shape>
<appearance>
<material diffuseColor='0 1 0'></material>
</appearance>
<cone></cone>
</shape>
</transform>
<transform translation='3 0 0'>
<shape>
<appearance>
<material diffuseColor='0 0 1'></material>
</appearance>
<sphere></sphere>
</shape>
</transform>
</scene>
</x3d>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title>synced X3DOM scenes</title>
<script type='text/javascript' src='https://www.x3dom.org/download/x3dom.js'> </script>
<script type='text/javascript' src='syncViews.js'> </script>
<link rel='stylesheet' type='text/css' href='https://www.x3dom.org/download/x3dom.css'/>
</head>
<body>
<h1>Hello, X3DOM!</h1>
<p>
Two synced scenes with inlined viewpoints.
</p>
<x3d id='left' width='300px' height='400px' style='float:left;'>
<scene>
<inline mapdeftoid='true' namespacename='left' url='"hello.x3d"'></inline>
</scene>
</x3d>
<x3d id='right' width='300px' height='400px' style='float:left;'>
<scene>
<navigationinfo type='none'></navigationinfo>
<background skycolor='"0 0 0" "0.5 0.5 0.5" "0 0 0"' skyAngle='1.57 3.14'></background>
<inline mapdeftoid='true' namespacename='right' url='"hello.x3d"'></inline>
</scene>
</x3d>
</body>
</html>
Copyright (c) 2017 Andreas Plesch, Waltham MA (email: andreasplesch atsign gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
document.onload = function () {
var vpleft, vpright;
document.querySelector('#left inline').onload = function () {
//vpleft = document.querySelector('#left').runtime.viewpoint()._xmlNode;
vpleft = document.getElementById('left__vp');
if (vpright) vpleft.addEventListener('viewpointChanged', syncViews.bind(this, vpright));
};
document.querySelector('#right inline').onload = function () {
//vpright = document.querySelector('#right').runtime.viewpoint()._xmlNode;
vpright = document.getElementById('right__vp');
if (vpleft) vpleft.addEventListener('viewpointChanged', syncViews.bind(this, vpright));
};
}
function syncViews (vp, evt) {
var o = evt.orientation;
var p = evt.position;
/*
// convert to string for attributes
vp.setAttribute('orientation',[o[0].x,o[0].y,o[0].z].join()+" "+o[1]);
vp.setAttribute('position', [p.x,p.y,p.z].join());
*/
//can use directly fields
vp.setFieldValue('orientation', // necessary to convert to quaternion
x3dom.fields.Quaternion.axisAngle (evt.orientation[0], evt.orientation[1])
);
vp.setFieldValue('position', evt.position);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment