精灵(Sprite)
精灵是一个总是面朝着摄像机的平面,通常含有使用一个半透明的纹理。
精灵不会投射任何阴影,即使设置了castShadow = true
也将不会有任何效果。
var spriteMap = new THREE.TextureLoader().load( "sprite.png" );
var spriteMaterial = new THREE.SpriteMaterial( { map: spriteMap, color: 0xffffff } );
var sprite = new THREE.Sprite( spriteMaterial );
scene.add( sprite );
构造器
Sprite( material : Material )
material - (可选值)是SpriteMaterial的一个实例。 默认值是一个白色的SpriteMaterial。
创建一个新的Sprite。
属性
请参阅其基类Object3D来查看共有属性。
# .isSprite : Boolean
用于检查这个类或者其派生类是否为精灵,默认值为true。
你不应当对这个属性进行改变,因为它在内部使用,以用于优化。
# .material : SpriteMaterial
SpriteMaterial的一个实例,定义了这个对象的外观。默认值是一个白色的SpriteMaterial。
# .center : Vector2
这个精灵的锚点,也就是精灵旋转时,围绕着旋转的点。当值为(0.5,0.5)时,对应着这个精灵的中心点;当值为(0,0)时,对应着这个精灵左下角的点。
其默认值是(0.5,0.5)。
方法
请参阅其基类Object3D来查看共有方法。
# .clone () : Sprite
返回当前Sprite对象的一个克隆及其任何后代。
# .copy ( sprite : Sprite ) : Sprite
将前一个Sprite对象的属性复制给当前的这个对象。
# .raycast ( raycaster : Raycaster, intersects : Array ) : null
在投射的光线和精灵之前产生交互。 Raycaster.intersectObject将会调用这个方法。
蒙皮网格(SkinnedMesh)
具有Skeleton(骨架)和bones(骨骼)的网格,可用于给几何体上的顶点添加动画。 其材质必须支持蒙皮,并且已经启用了蒙皮 —— 请阅读MeshStandardMaterial.skinning。
// iOS iframe auto-resize workaround
if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
var scene = document.getElementById( 'scene' );
scene.style.width = getComputedStyle( scene ).width;
scene.style.height = getComputedStyle( scene ).height;
scene.setAttribute( 'scrolling', 'no' );
}
var geometry = new THREE.CylinderBufferGeometry( 5, 5, 5, 5, 15, 5, 30 );
// create the skin indices and skin weights
var position = geometry.attributes.position;
var vertex = new THREE.Vector3();
var skinIndices = [];
var skinWeights = [];
for ( var i = 0; i < position.count; i ++ ) {
vertex.fromBufferAttribute( position, i ); // compute skinIndex and skinWeight based on some configuration data
var y = ( vertex.y + sizing.halfHeight );
var skinIndex = Math.floor( y / sizing.segmentHeight );
var skinWeight = ( y % sizing.segmentHeight ) / sizing.segmentHeight;
skinIndices.push( skinIndex, skinIndex + 1, 0, 0 );
skinWeights.push( 1 - skinWeight, skinWeight, 0, 0 );
}
geometry.addAttribute( 'skinIndex', new THREE.Uint16BufferAttribute( skinIndices, 4 ) );
geometry.addAttribute( 'skinWeight', new THREE.Float32BufferAttribute( skinWeights, 4 ) );
// create skinned mesh and skeleton
var mesh = new THREE.SkinnedMesh( geometry, material );
var skeleton = new THREE.Skeleton( bones );
// see example from THREE.Skeleton
var rootBone = skeleton.bones[ 0 ];
mesh.add( rootBone ); // bind the skeleton to the mesh
mesh.bind( skeleton ); // move the bones and manipulate the model
skeleton.bones[ 0 ].rotation.x = -0.1;
skeleton.bones[ 1 ].rotation.x = 0.2;
构造器
SkinnedMesh( geometry : BufferGeometry, material : Material )
geometry —— 一个BufferGeometry实例。
material —— (可选)一个Material实例,默认值是一个新的MeshBasicMaterial。
属性
请参阅其基类Mesh来查看共有属性。
# .bindMode : string
“attached”(附加)或者“detached”(分离)。“attached”使用SkinnedMesh.matrixWorld 属性作为对骨骼的基本变换矩阵,“detached”则使用SkinnedMesh.bindMatrix。 默认值是“attached”。
# .bindMatrix : Matrix4
该基础矩阵用于绑定骨骼的变换。
# .bindMatrixInverse : Matrix4
该基础矩阵用于重置绑定骨骼的变换。
# .isSkinnedMesh : Boolean
用于检查这个类或者其派生类是否为蒙皮网格,默认值为true。
你不应当对这个属性进行改变,因为它在使用,以用于优化。
# .skeleton : Skeleton
用于表示蒙皮网格中骨骼的层次结构的Skeleton(骨架)。
方法
请参阅其基类Mesh来查看共有方法。
# .bind ( skeleton : Skeleton, bindMatrix : Matrix4 ) : null
skeleton —— 由一棵Bones树创建的Skeleton。
bindMatrix —— 表示骨架基本变换的Matrix4(4x4矩阵)。
将骨架绑定到一个蒙皮网格上。bindMatrix会被保存到.bindMatrix属性中,其逆矩阵.bindMatrixInverse也会被计算出来。
# .clone () : SkinnedMesh
返回当前SkinnedMesh对象的一个克隆及其任何后代。
# .normalizeSkinWeights () : null
标准化蒙皮的权重。
# .pose () : null
这个方法设置了在“休息”状态下蒙皮网格的姿势(重置姿势)。
# .updateMatrixWorld ( force : Boolean ) : null
更新MatrixWorld矩阵。