// 添加分组
var group = new THREE.Group();
scene.add(group);
//计算参数,这些参数在多处用到
var segmentHeight = 8;//节高
var segmentCount = 4;////节数
var height = segmentHeight * segmentCount;
var halfHeight = height * 0.5;
var sizing = {
segmentHeight: segmentHeight,
segmentCount: segmentCount,
height: height,
halfHeight: halfHeight
};
//创建骨骼
bones = [];
var prevBone = new THREE.Bone();
bones.push(prevBone);
prevBone.position.y = - sizing.halfHeight;
for (var i = 0; i < sizing.segmentCount; i++) {
var bone = new THREE.Bone();
bone.position.y = sizing.segmentHeight;
bones.push(bone);
prevBone.add(bone);
prevBone = bone;
}
//创建形状
var skeleton = new THREE.Skeleton(bones);
var cylinderGeometry = new THREE.CylinderGeometry(
5, // radiusTop
5, // radiusBottom
sizing.height, // height
8, // radiusSegments
sizing.segmentCount * 3, // heightSegments
false // openEnded
)
var material = new THREE.MeshPhongMaterial({
skinning: true,
color: 0x156289,
emissive: 0xa72534,
side: THREE.DoubleSide,
shading: THREE.FlatShading,
wireframe: true
});
//构建骨骼与网格的关联关系
for (var i = 0; i < cylinderGeometry.vertices.length; i++) {
var vertice = cylinderGeometry.vertices[i];
var y = (vertice.y + sizing.halfHeight);
var skinIndex = Math.floor(y / sizing.segmentHeight);
var skinWeight = (y % sizing.segmentHeight) / sizing.segmentHeight;
cylinderGeometry.skinIndices.push(new THREE.Vector4(skinIndex, skinIndex + 1, 0, 0));
cylinderGeometry.skinWeights.push(new THREE.Vector4(1 - skinWeight, skinWeight, 0, 0));
}
var cylend = new THREE.SkinnedMesh(cylinderGeometry, material)
cylend.add(bones[0]);
cylend.bind(skeleton);
scene.add(cylend);
var helper = new THREE.SkeletonHelper(cylend);
helper.material.linewidth = 1000;
scene.add(helper);
scene.add(cylend);
Threejs深入理解(一)骨骼动画
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 【前言】 通过前两篇的骨骼系统的基础学习,已经熟知关节建立的方法了。虽然,还有一些细节比如坐标、指向、包括...
- 20140912凯史太空学院第1次健康教学骨骼1(下) Eugene整理 凯史:关键是,当一切刚刚开始的时候,第一...
- 【导言】 很多吧友都着急了,询问什么时间研究骨骼系统? 我想问你的建模功夫过关了吗?你的“动画曲线”调整完全掌握了...