我尝试使用trijs示例webgl_buffergeometry_instancing_dynamic,
var vector = new THREE.Vector4();
var m4 = new THREE.Matrix4();
m4 = m4.fromArray(array16);
vector = vector.applyMatrix4(m4);
offsets.setXYZ(i, vector.x, vector.y, vector.z);
矢量设置为偏移量 偏移也在发生,
方向
var vector = new THREE.Vector4();
var m4 = new THREE.Matrix4();
m4 = m4.fromArray(array16);
var rotMatrix = new THREE.Matrix4().extractRotation(m4);
var vector1 = new THREE.Vector4();
vector1.setAxisAngleFromRotationMatrix(rotMatrix).normalize();
orientations.setXYZW(i, vector1.x, vector1.y, vector1.z, vector1.w);
作为属性传递的向量的x,y,z,w
precision mediump float;
precision mediump int;
uniform mat4 modelViewMatrix; // optional
uniform mat4 modelMatrix; // optional
uniform mat4 projectionMatrix;// optional
attribute vec3 position;
attribute vec4 customColor;
attribute vec3 offset;
attribute vec4 orientation;
varying vec4 vColor;
varying vec4 worldPosition;
void main() {
vec3 vPosition = position;
vColor = customColor;
vec3 vcV = cross(orientation.xyz, vPosition);
vec3 nPosition = vcV * (2.0 * orientation.w ) + (cross(orientation.xyz, vcV) * 2.0 + vPosition);
nPosition += offset.xyz;
worldPosition = modelMatrix * vec4(nPosition, 1.0);
gl_Position = projectionMatrix * modelViewMatrix * vec4( nPosition , 1.0);
}
这个方向是这里的问题区域我附上了我的着色器代码以供参考
请指导我.. 在此先感谢。