demo mid
程序员文章站
2022-03-27 13:09:32
...
reshape.js
var scr,scrWidth,scrHeight,scrScene;
var k;
var scrCamera;var scrRenderer;
var light;
function gasket(){
scr=document.getElementById("scr");
scrWidth= scr.clientWidth;
scrHeight= scr.clientHeight;
scrScene=new THREE.Scene();//场景
scrScene.add(torus);
initLight();
// //灯光
// var point=new THREE.PointLight(0xE81515);//浅灰
// point.position.set(400,200,300);
// scrScene.add(point);
// var point1=new THREE.PointLight(0xE81515);//深灰
// point1.position.set(-400,200,300);
// scrScene.add(point1);
// //灯光
// var ambient=new THREE.AmbientLight(0x888888);
// scrScene.add(ambient);
// var ambient=new THREE.AmbientLight(0x888888);//深灰
// scene.add(ambient);
// //点光源
// var point=new THREE.PointLight(0xffffff);
// point.position.set(400,200,300);//点光源位置
// scene.add(point);//点光源添加到场景中
//环境光
// var ambient=new THREE.AmbientLight(0x444444);
// scrScene.add(ambient);
// var direction = new THREE.DirectionalLight(0xE81515);
// scrScene.add(direction);
// scrScene.add(new THREE.AmbientLight(0xE81515));
// light = new THREE.DirectionalLight(0xD9F718);
// light.position.set(100,200,100);
// scrScene.add(light);
//照相机
k=13;
scrCamera=new THREE.OrthographicCamera(-scrWidth/k,scrWidth/k,scrHeight/k,-scrHeight/k,1,1000);
scrCamera.position.set(0,0,400);
scrCamera.lookAt(scrScene.position);
//照相机
//渲染器设置
scrRenderer=new THREE.WebGLRenderer();
scrRenderer.setSize(scrWidth, scrHeight);
scrRenderer.setClearColor(0x3d3d3d,1);//背景色,深灰
scr.appendChild(scrRenderer.domElement);
//渲染器设置
//设置渲染函数
function scrRender(){
//requestAnimationFrame(scrRender);
//controls.update();
scrRenderer.render(scrScene,scrCamera);
}
//执行渲染器
//调用渲染函数
scrRender();
//调用渲染函数
//鼠标缩放滚转零件,轨道控制器OrbitControls
var controls=new THREE.OrbitControls(scrCamera);
controls.addEventListener('change', scrRender);
}
var wor,worHeight,worWidth,worScene;
var geometry,material;
var worRenderer;
var torus,geometry,material,worCamera,worRenderer;
function resh(){
wor=document.getElementById("wor");
worWidth= wor.clientWidth;
worHeight= wor.clientHeight;
geometry = new THREE.TorusGeometry( 10, 3, 16, 100 );
//var gasket=new THREE.ExtrudeGeometry(geometry,extrudeSettings);
material = new THREE.MeshBasicMaterial({
color: 0x6633FF,
transparent:true,
opacity:1,
shininess:20
});//材质对象
torus = new THREE.Mesh( geometry, material );//创建网络模型对象
worScene=new THREE.Scene();//创建场景
worScene.add(torus);
//照相机
k=7;
worCamera=new THREE.OrthographicCamera(-worWidth/k,worWidth/k,worHeight/k,-worHeight/k,1,1000);
//正投影(left,right,top,bottom,near,far)
worCamera.position.set(400,0,400);
worCamera.lookAt(worScene.position);
//照相机
//渲染器设置,必须有
worRenderer=new THREE.WebGLRenderer();
worRenderer.setSize(worWidth, worHeight);
worRenderer.setClearColor(0x3d3d3d,1);//背景色,深灰
wor.appendChild(worRenderer.domElement);//插入canvas对象
//渲染器设置
//设置渲染函数
function worRender(){
//requestAnimationFrame(worRender);
//controls.update();
worRenderer.render(worScene,worCamera);
}
//执行渲染器
//调用渲染函数
worRender();
//调用渲染函数
}
function main(){
resh();
gasket();
initLight();
}
var light;
function initLight() {
scrScene.add(new THREE.AmbientLight(0xE81515));
light = new THREE.DirectionalLight(0xD9F718);
light.position.set(100,200,100);
scrScene.add(light);
}