我开始使用three.js,想知道是否有一个简单的插件可以添加轨迹球功能,这样我就可以看到我在代码中所做的更改是如何影响简单对象的“底面”的。
我试图遵循:
http://mrdoob.github.com/three.js/examples/misc_controls_trackball.html
但是我收到了很多 EventDispatcher 错误。
通过尝试,我的意思是我已经:
- 添加了“TrackballControls.js”
- 添加了“Detector.js”
添加了这段代码:
if ( ! Detector.webgl ) Detector.addGetWebGLMessage(); var controls = new THREE.TrackballControls( camera ); controls.rotateSpeed = 1.0; controls.zoomSpeed = 1.2; controls.panSpeed = 0.8; controls.noZoom = false; controls.noPan = false; controls.staticMoving = true; controls.dynamicDampingFactor = 0.3; controls.keys = [ 65, 83, 68 ]; controls.addEventListener( 'change', render );
我确实注意到示例中使用的 three.js 与 at 中的不同(但不确定是否重要):
http://cdnjs.cloudflare.com/ajax/libs/three.js/r53/three.min.js
任何建议都会非常有帮助,因为我刚刚开始。
感谢您的时间!
更新:我尝试从这里使用最新版本的 Three.js:
https://github.com/mrdoob/three.js/blob/master/build/three.js
我找不到 TrackballControls.js 和 Detector.js 的官方版本,所以我使用了这些版本:
http://threejsdoc.appspot.com/doc/three.js/src.source/extras/controls/TrackballControls.js.html
http://mrdoob.github.com/three.js/examples/js/Detector.js
这是我无法开始工作的代码(它是http://www.aerotwist.com/tutorials/getting-started-with-three-js/和http://mrdoob.github.com/three 的组合。 js/examples/misc_controls_trackball.html并尝试将对象制作成环/圆环):
<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Getting Started with Three.js | Aerotwist</title>
<meta name="description" content="The home of Creative Coder and developer Paul Lewis. Tutorial, experiments and considered opinions found here.">
<meta name="author" content="Paul Lewis">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="Three.js"></script>
<script src="TrackballControls.js"></script>
<script src="Detector.js"></script>
</head>
<style>
#container {
background: #000;
width: 400px;
height: 300px;
}
</style>
<body>
<div id="container"></div>
</body>
<script type="text/javascript">
function animate() {
requestAnimationFrame( animate );
controls.update();
}
function render() {
renderer.render( scene, camera );
}
var WIDTH = 400,
HEIGHT = 300;
// set some camera attributes
var VIEW_ANGLE = 45,
ASPECT = WIDTH / HEIGHT,
NEAR = 0.1,
FAR = 10000;
// get the DOM element to attach to
// - assume we've got jQuery to hand
var $container = $('#container');
// create a WebGL renderer, camera
// and a scene
var renderer = new THREE.WebGLRenderer();
var camera =
new THREE.PerspectiveCamera(
VIEW_ANGLE,
ASPECT,
NEAR,
FAR);
var scene = new THREE.Scene();
// TrackBall code from http://mrdoob.github.com/three.js/examples/misc_controls_trackball.html
var controls = new THREE.TrackballControls( camera );
controls.rotateSpeed = 1.0;
controls.zoomSpeed = 1.2;
controls.panSpeed = 0.8;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
controls.keys = [ 65, 83, 68 ];
//controls.addEventListener( 'change', render ); // this was how it used to be at: http://mrdoob.github.com/three.js/examples/misc_controls_trackball.html
controls.domElement.addEventListener( 'change', render ); // I changed this to fix error message: "controls.addEventListener is not a function"
// --------------------------
// add the camera to the scene
scene.add(camera);
// the camera starts at 0,0,0
// so pull it back
camera.position.z = 300;
// start the renderer
renderer.setSize(WIDTH, HEIGHT);
// attach the render-supplied DOM element
$container.append(renderer.domElement);
// ------------------------
// create the sphere's material
var sphereMaterial =
new THREE.MeshLambertMaterial(
{
color: 0xCC0000
});
// -------------------------------
// ################ try torus
var centerpiece = new THREE.TorusGeometry();
var sphere = new THREE.Mesh(
centerpiece,
sphereMaterial);
// add the sphere to the scene
scene.add(sphere);
// ---------------------------
// create a point light
var pointLight =
new THREE.PointLight(0xFFFFFF);
// set its position
pointLight.position.x = 10;
pointLight.position.y = 50;
pointLight.position.z = 130;
// add to the scene
scene.add(pointLight);
// -------------------------
// draw!
renderer.render(scene, camera);
</script>
每当我单击页面上的任何位置时,都会收到此错误消息:
_eye.copy(...).subSelf is not a function
有任何想法吗?
感谢您的时间!