入门THREEJS遇到的问题求大佬解惑 引入OrbitControls.js后报 原因是浏览器不能识别require然后看到这个贴子https://blog.csdn.net/wml00000/article/details/84181227用这个browserify方法翻译了一遍OrbitControls.js 还是不能动咋整啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>简单Demo</title> <script src='./three.js'></script> <!-- <script src='./OrbitControls.js'></script> --> <script src="./dist/dist.js"></script> <style> * { margin: 0; padding: 0 } html, body { width: 100%; height: 100%; overflow: hidden; } #canvas { width: 100%; height: 100%; } </style></head><body> <div id="canvas"> </div> <script> var threeObj = { scene: null, camera: null, cube: null, renderer: null, controls: null, width: document.documentElement.clientWidth, height: document.documentElement.clientHeight, initScene: function () { //添加坐标系 var ax = new THREE.AxesHelper(100); this.scene = new THREE.Scene(); //全局雾化 this.scene.fog = new THREE.Fog(0xffffff, 0.015, 1000) this.scene.add(ax); }, initCamera: function () { this.camera = new THREE.PerspectiveCamera(60, this.width / this.height, 0.1, 1000); this.camera.position.set(100, 100, 100); this.camera.lookAt(0, 0, 0); }, initRenderer: function () { this.renderer = new THREE.WebGLRenderer({ antialias: true }) this.renderer.setSize(this.width, this.height); this.renderer.setClearColor(0xD1BEBE); document.getElementById('canvas').appendChild(this.renderer.domElement); }, initLight: function () { var light = new THREE.DirectionalLight(0x695DEE); light.position.set(100, 0, 10); this.scene.add(light); }, initGeometry: function () { var geometry = new THREE.CubeGeometry(25, 55, 20, 3, 3, 3); //使用Phong光照模型的材质,适合镜面、金属等 var material = new THREE.MeshPhongMaterial({ color: 0xF2415E, wireframe: true }); this.cube = new THREE.Mesh(geometry, material); this.scene.add(this.cube); }, initControl: function () { var controls = new THREE.OrbitControls(this.camera, this.renderer.domElement); // 使用阻尼,指定是否有惯性 controls.enableDamping = true; // 动态阻尼系数 就是鼠标拖拽旋转灵敏度,阻尼越小越灵敏 controls.dampingFactor = 0.25; // 是否可以缩放 controls.enableZoom = true; //是否自动旋转 controls.autoRotate = false; //设置相机距离原点的最近距离 controls.minDistance = 10; //设置相机距离原点的最远距离 controls.maxDistance = 600; //是否开启右键拖拽 controls.enablePan = true; this.controls = controls; }, render: function () { //这里不能直接用this.render,第二次调用自身时,this就变成了window //requestAnimationFrame的this是window对象,如同setTimeout,setinterval requestAnimationFrame(this.render.bind(this)); this.cube.rotation.y += 0.01; this.controls.update(); this.renderer.render(this.scene, this.camera); }, init: function () { window.onresize = onWindowResize; this.initScene(); this.initCamera(); this.initRenderer(); this.initLight(); this.initGeometry(); this.initControl(); this.render(); }, } function onWindowResize() { threeObj.camera.aspect = document.documentElement.clientWidth / document.documentElement.clientHeight; threeObj.camera.updateProjectionMatrix(); threeObj.renderer.setSize(threeObj.width, threeObj.height); threeObj.renderer.render(threeObj.scene, threeObj.camera); } threeObj.init(); </script></body></html> 求助,初学者的错误, JS中使用cookie保存相关值,为什么在下列情况下保存不了呢 超链接点击颜色变化 大家帮我看看这段JS播放器的代码?看看能不能修改。。。 火狐下的下拉列表问题 下拉菜单当鼠标经过的时候如何能显示提示信息? 关于JS中String.fromCharCode返回值问题,js新手 关于在网页上实现打印功能的问题 导航栏状态变化的问题。 为什么不能写<script /> MathJax如何将latex 输出 为MathML 求教--网站-一个页面链接多个腾讯视频现同时播放特别乱+吵,可否设置轮播或点击再播?
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<title>简单Demo</title>
<script src='./three.js'></script>
<!-- <script src='./OrbitControls.js'></script> -->
<script src="./dist/dist.js"></script>
<style>
* {
margin: 0;
padding: 0
} html,
body {
width: 100%;
height: 100%;
overflow: hidden;
} #canvas {
width: 100%;
height: 100%;
}
</style>
</head><body>
<div id="canvas">
</div>
<script>
var threeObj = {
scene: null,
camera: null,
cube: null,
renderer: null,
controls: null,
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
initScene: function () {
//添加坐标系
var ax = new THREE.AxesHelper(100);
this.scene = new THREE.Scene();
//全局雾化
this.scene.fog = new THREE.Fog(0xffffff, 0.015, 1000)
this.scene.add(ax);
},
initCamera: function () {
this.camera = new THREE.PerspectiveCamera(60, this.width / this.height, 0.1, 1000);
this.camera.position.set(100, 100, 100);
this.camera.lookAt(0, 0, 0);
},
initRenderer: function () {
this.renderer = new THREE.WebGLRenderer({
antialias: true
})
this.renderer.setSize(this.width, this.height);
this.renderer.setClearColor(0xD1BEBE);
document.getElementById('canvas').appendChild(this.renderer.domElement);
},
initLight: function () {
var light = new THREE.DirectionalLight(0x695DEE);
light.position.set(100, 0, 10);
this.scene.add(light);
},
initGeometry: function () {
var geometry = new THREE.CubeGeometry(25, 55, 20, 3, 3, 3);
//使用Phong光照模型的材质,适合镜面、金属等
var material = new THREE.MeshPhongMaterial({
color: 0xF2415E,
wireframe: true
});
this.cube = new THREE.Mesh(geometry, material);
this.scene.add(this.cube);
},
initControl: function () {
var controls = new THREE.OrbitControls(this.camera, this.renderer.domElement);
// 使用阻尼,指定是否有惯性
controls.enableDamping = true;
// 动态阻尼系数 就是鼠标拖拽旋转灵敏度,阻尼越小越灵敏
controls.dampingFactor = 0.25;
// 是否可以缩放
controls.enableZoom = true;
//是否自动旋转
controls.autoRotate = false;
//设置相机距离原点的最近距离
controls.minDistance = 10;
//设置相机距离原点的最远距离
controls.maxDistance = 600;
//是否开启右键拖拽
controls.enablePan = true;
this.controls = controls;
},
render: function () {
//这里不能直接用this.render,第二次调用自身时,this就变成了window
//requestAnimationFrame的this是window对象,如同setTimeout,setinterval
requestAnimationFrame(this.render.bind(this));
this.cube.rotation.y += 0.01;
this.controls.update();
this.renderer.render(this.scene, this.camera);
},
init: function () {
window.onresize = onWindowResize;
this.initScene();
this.initCamera();
this.initRenderer();
this.initLight();
this.initGeometry();
this.initControl();
this.render();
},
} function onWindowResize() {
threeObj.camera.aspect = document.documentElement.clientWidth / document.documentElement.clientHeight;
threeObj.camera.updateProjectionMatrix();
threeObj.renderer.setSize(threeObj.width, threeObj.height);
threeObj.renderer.render(threeObj.scene, threeObj.camera);
}
threeObj.init();
</script>
</body></html>