我希望web中有两个元素是3D模型(这两个元素都是从.x3d文件中生成的),当我旋转时,其中一个元素的变化就像镜子一样。
为了从.x3d文件中获取html代码,我执行以下步骤:
HTML代码示例
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'></meta>
<link rel='stylesheet' type='text/css' href='http://www.x3dom.org/x3dom/release/x3dom.css'></link>
<script type='text/javascript' src='http://www.x3dom.org/x3dom/release/x3dom.js'></script>
</head>
<body>
<x3d id='someUniqueId' showStat='false' showLog='false' x='0px' y='0px' width='400px' height='400px'>
<scene>
<transform rotation='0 1 0 1.57'>
<shape>
<appearance DEF='A'>
<material diffuseColor='0 0.5 0.7'></material>
</appearance>
<box></box>
</shape>
<transform scale='1 5 1' translation='0 -5 0'>
<shape>
<appearance USE='A'></appearance>
<sphere></sphere>
</shape>
</transform>
<transform rotation='0 1 0 1.57' translation='1.5 0 0'>
<transform translation='0 -3 0'>
<shape>
<appearance USE='A'></appearance>
<cylinder height='4' radius='0.5'></cylinder>
</shape>
</transform>
</transform>
<transform rotation='0 -1 0 1.57' translation='-1.5 0 0'></transform>
</transform>
</scene>
</x3d>
</body>
</html>发布于 2017-01-19 10:26:15
如果要在二维模型之间执行镜像效果,则必须创建一个Viewpoint并管理更改侦听器。例如,请参阅下面的代码。JSFiddle Html文件
<body>
<div>
Move on the grey part
</div>
<x3d id='someUniqueId' showStat='false' showLog='false' x='0px' y='0px' width='400px' height='400px'>
<scene>
<Background skyColor=' 0.8 0.8 0.8' bind='true' ></Background>
<Viewpoint bind='true' isActive="true" centerOfRotation='0,0,0'></Viewpoint> <transform rotation='0 1 0 1.57'>
<shape>
<appearance DEF='A'>
<material diffuseColor='0 0.5 0.7'></material>
</appearance>
<box></box>
</shape>
<transform scale='1 5 1' translation='0 -5 0'>
<shape>
<appearance USE='A'></appearance>
<sphere></sphere>
</shape>
</transform>
<transform rotation='0 1 0 1.57' translation='1.5 0 0'>
<transform translation='0 -3 0'>
<shape>
<appearance USE='A'></appearance>
<cylinder height='4' radius='0.5'></cylinder>
</shape>
</transform>
</transform>
<transform rotation='0 -1 0 1.57' translation='-1.5 0 0'></transform>
</transform>
</scene>
</x3d>
<x3d id='someUniqueId2' showStat='false' showLog='false' x='0px' y='0px' width='400px' height='400px'>
<scene>
<transform id="ManageRotation">
<transform rotation='0 1 0 1.57'>
<shape>
<appearance DEF='A'>
<material diffuseColor='0 0.5 0.7'></material>
</appearance>
<box></box>
</shape>
<transform scale='1 5 1' translation='0 -5 0'>
<shape>
<appearance USE='A'></appearance>
<sphere></sphere>
</shape>
</transform>
<transform rotation='0 1 0 1.57' translation='1.5 0 0'>
<transform translation='0 -3 0'>
<shape>
<appearance USE='A'></appearance>
<cylinder height='4' radius='0.5'></cylinder>
</shape>
</transform>
</transform>
<transform rotation='0 -1 0 1.57' translation='-1.5 0 0'></transform>
</transform>
</transform>
</scene>
</x3d>
</body>JavaScript零件
$("Viewpoint","x3d").each(function () {
this.addEventListener('viewpointChanged', function (pEvent) {
var rot = pEvent.orientation;
$("#ManageRotation").each(function () {
this.setAttribute('position', 0 + ' ' + 0 + ' ' + 0);
this.setAttribute('rotation', -1 *rot[0].x + ' ' + rot[0].y + ' ' + rot[0].z + ' ' + rot[1]);
});
}
)
});https://stackoverflow.com/questions/39628876
复制相似问题