three.js模板
<!DOCTYPE html
>
<html lang
="en">
<head
>
<meta charset
="UTF-8">
<title
>three
.js模板
</title
>
<style
>
body
{
margin
: 0;
overflow
: hidden
;
}
</style
>
<!--引入three
.js三维引擎
-->
<script src
="../../js/three.js"></script
>
<script src
="../../js/OrbitControls.js"></script
>
<!-- <script src
="./three.js"></script
> -->
</head
>
<body
>
<script type
="text/javascript">
var scene
,camera
,renderer
,
light
,group
;
init();
function init(){
initScene();
initCamera();
initRenender();
initLight();
initOthers();
setWindown();
setEventsMouse();
setKeyEvents();
initaxisHelper();
Box();
}
function initScene(){
scene
= new THREE.Scene();
}
function initCamera(){
camera
= new THREE.PerspectiveCamera(60, window
.innerWidth
/ window
.innerHeight
, 1, 1000);
camera
.position
.set(292, 109, 268);
camera
.lookAt(scene
.position
);
}
function initRenender(){
renderer
= new THREE.WebGLRenderer();
renderer
.setClearColor(0xb9d3ff, 1);
renderer
.setSize(window
.innerWidth
, window
.innerHeight
);
}
function initOthers(){
document
.body
.appendChild(renderer
.domElement
);
}
function Box() {
var geometry
= new THREE.BoxGeometry(100, 100, 100);
var material
= new THREE.MeshLambertMaterial({
color
: 0x0000ff
});
var mesh
= new THREE.Mesh(geometry
, material
);
scene
.add(mesh
);
}
function setWindown(){
window
.addEventListener('resize', function(){
var width
= window
.innerWidth
;
var height
= window
.innerHeight
;
renderer
.setSize(width
,height
);
camera
.aspect
= width
/height
;
camera
.updateProjectionMatrix();
});
}
function setEventsMouse(){
window
.addEventListener( 'click', function(e
){
if(e
.button
===0){
console
.log("点击了鼠标左键");
}
} );
window
.addEventListener( 'contextmenu', function(e
){
if(e
.button
===2){
console
.log("点击了鼠标右键");
}
} );
window
.addEventListener( 'mousemove', function(e
){
console
.log('x:'+e
.x
);
console
.log('y:'+e
.y
);
} );
}
function setKeyEvents(){
window
.addEventListener('keydown',function(e
){
console
.log(e
);
});
}
function initaxisHelper() {
var axisHelper
= new THREE.AxisHelper(250);
scene
.add(axisHelper
);
}
function initLight(){
light
= new THREE.Light(0xFFFFFF,1.0);
scene
.add(light
);
}
var update=function(){
}
function render() {
renderer
.render(scene
, camera
);
}
var loop=function() {
requestAnimationFrame(loop
);
update();
render();
}
loop();
</script
>
</body
>
</html
>
转载请注明原文地址:https://tech.qufami.com/read-11267.html