function main() {
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight,0.1,1000);
camera.position.set(-80,60,80);
camera.lookAt(scene.position);
//坐标
var axes = new THREE.AxisHelper(10);
scene.add(axes);
//
var renderer = new THREE.WebGLRenderer();
renderer.setClearColor('#a68da2');
renderer.setSize(window.innerWidth,window.innerHeight);
renderer.shadowMapEnabled = true;
//基本颜色
var color = new THREE.Color(0xCCCCCC);
//随机颜色数组 每次使用时候调用一次
function randomColor() {
var rColor = new Float32Array( [Math.random(),Math.random(),Math.random()]);
return rColor;
}
//材质
var geoMaterial1 = new THREE.MeshBasicMaterial({
color:0xFFFFFF*Math.random(),wireframe:true
});
var geoMaterial2 = new THREE.MeshLambertMaterial({
color:color.fromArray(randomColor())
});
var geoMaterial3 = new THREE.MeshLambertMaterial({
color:0xDDDDDD
});
//平面
var planeGeometry = new THREE.PlaneGeometry(120,120);
var plane = new THREE.Mesh(planeGeometry,geoMaterial3);
plane.rotation.x = -0.5*Math.PI;
plane.position.set(20,0,-20);
plane.receiveShadow = true;
scene.add(plane);
//立方体线框
var cubeGeometry = new THREE.BoxGeometry(16,16,16);
var cube = new THREE.Mesh(cubeGeometry,geoMaterial1);
cube.position.set(0,28,0);
scene.add(cube);
//立方体
var cube2 = new THREE.Mesh(cubeGeometry,geoMaterial2);
cube2.position.set(0,8,0);
cube2.castShadow = true;
scene.add(cube2);
//球体
var sphereGeometry = new THREE.SphereGeometry(6,20,20);
var sphereMaterial = new THREE.MeshLambertMaterial({
color:color.fromArray(randomColor())
})
var sphere = new THREE.Mesh(sphereGeometry,sphereMaterial);
sphere.position.set(0,26,0);
sphere.castShadow = true;
scene.add(sphere);
var ambientLight = new THREE.AmbientLight(0x666666);
scene.add(ambientLight);
var SpotLight = new THREE.SpotLight(0xFFFFFF);
SpotLight.position.set(-60,60,-60);
SpotLight.castShadow = true;
scene.add(SpotLight);
document.body.appendChild(renderer.domElement);
renderer.render(scene,camera);
function run() {
cube.rotation.y -= 0.1;
cube.rotation.x -= 0.1;
cube.rotation.z -= 0.1;
cube2.rotation.y += 0.1;
renderer.render(scene,camera);
setTimeout(run,100);
}
run();
}
main();
</script>
01three.js基本组件
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 组成Three.js场景的基本组件 《创建场景》 场景中的基本组件:相机、光源和几何体 THREE.Scene()...
- HTML 学习笔记 May 9,2017 js运行原理、js开发工具介绍、js程序(hello)、js基本语法、j...
- 最近比较忙,公司有项目要求要搞WebAR,各种google后,得到结果是ARToolkit库加Three.js库,...
- 在本章和后面的章节中,将通过具体的Demo来介绍相关内容。 Demo只介绍大体的用法。一些细节的东西,都在代码注释...