提交 3fea7a65 编写于 作者: M Mr.doob

TiltLoader: Join strokes by brush type.

上级 72730a56
...@@ -76,6 +76,8 @@ class TiltLoader extends Loader { ...@@ -76,6 +76,8 @@ class TiltLoader extends Loader {
const num_strokes = data.getInt32( 16, true ); const num_strokes = data.getInt32( 16, true );
const brushes = {};
let offset = 20; let offset = 20;
for ( let i = 0; i < num_strokes; i ++ ) { for ( let i = 0; i < num_strokes; i ++ ) {
...@@ -134,14 +136,23 @@ class TiltLoader extends Loader { ...@@ -134,14 +136,23 @@ class TiltLoader extends Loader {
} }
// console.log( positions, quaternions ); if ( brush_index in brushes === false ) {
brushes[ brush_index ] = [];
}
brushes[ brush_index ].push( [ positions, quaternions, brush_size, brush_color ] );
}
for ( const brush_index in brushes ) {
const geometry = new StrokeGeometry( positions, quaternions, brush_size, brush_color ); const geometry = new StrokeGeometry( brushes[ brush_index ] );
const material = getMaterial( metadata.BrushIndex[ brush_index ] ); const material = getMaterial( metadata.BrushIndex[ brush_index ] );
group.add( new Mesh( geometry, material ) ); group.add( new Mesh( geometry, material ) );
} }
return group; return group;
...@@ -152,7 +163,7 @@ class TiltLoader extends Loader { ...@@ -152,7 +163,7 @@ class TiltLoader extends Loader {
class StrokeGeometry extends BufferGeometry { class StrokeGeometry extends BufferGeometry {
constructor( positions, quaternions, size, color ) { constructor( strokes ) {
super(); super();
...@@ -161,10 +172,10 @@ class StrokeGeometry extends BufferGeometry { ...@@ -161,10 +172,10 @@ class StrokeGeometry extends BufferGeometry {
const uvs = []; const uvs = [];
const position = new Vector3(); const position = new Vector3();
const prevPosition = new Vector3().fromArray( positions, 0 ); const prevPosition = new Vector3();
const quaternion = new Quaternion(); const quaternion = new Quaternion();
const prevQuaternion = new Quaternion().fromArray( quaternions, 0 ); const prevQuaternion = new Quaternion();
const vector1 = new Vector3(); const vector1 = new Vector3();
const vector2 = new Vector3(); const vector2 = new Vector3();
...@@ -173,7 +184,18 @@ class StrokeGeometry extends BufferGeometry { ...@@ -173,7 +184,18 @@ class StrokeGeometry extends BufferGeometry {
// size = size / 2; // size = size / 2;
for ( let i = 0, j = 0, l = positions.length; i < l; i += 3, j += 4 ) { for ( const k in strokes ) {
const stroke = strokes[ k ];
const positions = stroke[ 0 ];
const quaternions = stroke[ 1 ];
const size = stroke[ 2 ];
const color = stroke[ 3 ];
prevPosition.fromArray( positions, 0 );
prevQuaternion.fromArray( quaternions, 0 );
for ( let i = 3, j = 4, l = positions.length; i < l; i += 3, j += 4 ) {
position.fromArray( positions, i ); position.fromArray( positions, i );
quaternion.fromArray( quaternions, j ); quaternion.fromArray( quaternions, j );
...@@ -226,6 +248,8 @@ class StrokeGeometry extends BufferGeometry { ...@@ -226,6 +248,8 @@ class StrokeGeometry extends BufferGeometry {
} }
}
this.setAttribute( 'position', new BufferAttribute( new Float32Array( vertices ), 3 ) ); this.setAttribute( 'position', new BufferAttribute( new Float32Array( vertices ), 3 ) );
this.setAttribute( 'color', new BufferAttribute( new Float32Array( colors ), 4 ) ); this.setAttribute( 'color', new BufferAttribute( new Float32Array( colors ), 4 ) );
this.setAttribute( 'uv', new BufferAttribute( new Float32Array( uvs ), 2 ) ); this.setAttribute( 'uv', new BufferAttribute( new Float32Array( uvs ), 2 ) );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册