three.js自定义造型示例

本文通过实例详细讲解如何利用three.js库在WebGL中构建和操作自定义的3D几何形状,涵盖了javascript和html5的相关技术,为web三维图形编程提供了深入的理解。
摘要由CSDN通过智能技术生成

 

/
//物体造型关键向量点
var vertices = [
	new THREE.Vector3(-1,0,-1),
	new THREE.Vector3(1,0,-1),
	new THREE.Vector3(1,0,1),
	new THREE.Vector3(-1,0,1),
	new THREE.Vector3(0,2,0)
];
//围合各个向量点形成平面
var faces = [
	new THREE.Face3(0,1,2),
	new THREE.Face3(2,3,0),
	new THREE.Face3(4,3,2),
	new THREE.Face3(1,4,2),
	new THREE.Face3(0,4,1),
	new THREE.Face3(3,4,0)
];
//使用以上点和面创建几何体
var geom = new THREE.Geometry();
geom.vertices = vertices;
geom.faces = faces;
//计算点面法线
geom.computeFaceNormals();
geom.computeVertexNormals();
geom.mergeVertices();
//所有面必须全部设色才能正常显示
for(var i=0;i<geom.faces.length;i++){
	geom.faces[0].color.set(0xffffff);
}
//之后修改某一个面的颜色
geom.faces[0].color.set("red");
geom.faces[1].color.set("orange");
geom.faces[2].color.set("yellow");
geom.faces[3].color.set("green");
geom.faces[4].color.set("blue");
geom.faces[5].color.set("violet");
//设置材质的颜色vertexColors:THREE.FaceColors
var material=new THREE.MeshPhongMaterial({vertexColors:THREE.FaceColors});
var mesh=new THREE.Mesh(geom,material);

mesh.castShadow=true;

mesh.position.x=3;
mesh.position.y=2;
mesh.position.z=3;

scene.add(mesh);

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值