var material =newTHREE.MeshBasicMaterial({
color:0xff0000, side:THREE.DoubleSide });var geometry =newTHREE.Geometry();
geometry.vertices.push(newTHREE.Vector3(5,10,0));// vertex 0
geometry.vertices.push(newTHREE.Vector3(5,5,0));// vertex 1
geometry.vertices.push(newTHREE.Vector3(10,5,0));// vertex 2
geometry.faces.push(newTHREE.Face3(0,1,2));// make a trianglevar mesh =newTHREE.Mesh( geometry, material );// create an object
scene.add( mesh );// add object to the scene to make it visible
建造楼梯
var geoBlock =newTHREE.CubeGeometry( width, height, thickness );var blockMesh =newTHREE.Mesh( geoBlock, material );// set the X,Y,Z position
stepMesh.position.x = xPosition;
stepMesh.position.y = yPosition;
stepMesh.position.z = zPosition;
饮酒鸟
// values 32, 16 are longitude and latitude tessellationsvar sphere =newTHREE.Mesh(newTHREE.SphereGeometry( radius,32,16), sphereMaterial );var cylinder =newTHREE.Mesh(newTHREE.CylinderGeometry( radiusTop, radiusBottom, height,32), cylMaterial );
第3课:颜色和材料
设置颜色
var sphereMaterial =newTHREE.MeshLambertMaterial();// three separate floats to set RGB
sphereMaterial.color.r =1.0;
sphereMaterial.color.g =0.0;
sphereMaterial.color.b =0.0;// or use the setRGB method
sphereMaterial.color.setRGB(0.972,0.749,0.141);// or use a hex value, 0x00 to 0xFF (0-255), for each channel
sphereMaterial.color.setHex(0x1280FF);// or initialize your material with the colorvar cylMaterial =newTHREE.MeshLambertMaterial({
color:0xF4F100});
顶点属性
// how to set the three vertex colors for face #0var color1 =newTHREE.Color(0xF08000);// orangevar color2 =newTHREE.Color(0x808000);// olivevar color3 =newTHREE.Color(0x0982FF);// bright blue
geometry.faces[0].vertexColors =[ color1, color2, color3 ];
漫射材料
material =newTHREE.MeshBasicMaterial({
color:0x80fc66, shading:THREE.FlatShading });
material.color.setRGB( red, green, blue );var newRed = material.color.r *0.7;
material.ambient.setRGB(...);
Ka,Kd和HSL
var color =newColor();// hue, saturation, and lightness, all 0-1
color.setHSL(0.117,0.937,0.557);// orange
透明度和Three.js
var movingBoxMaterial =newTHREE.MeshLambertMaterial({
color:0xE53319, opacity:0.7, transparent:true});
// This is always the order of application:
cube.scale.set( xSize, ySize, zSize );
cube.rotation.set( xRotationInRadians, yRotationInRadians, zRotationInRadians );
cube.position.set( xPosition, yPosition, zPosition );
Object3D
var block =newTHREE.Mesh(newTHREE.CubeGeometry(100,4,4), clockHandMaterial );
block.position