Commit d963fff9 authored by frankie's avatar frankie 💬
Browse files

Loading key shapes from collada

parent e8aac4b4
......@@ -14089,6 +14089,10 @@
 
var morphAttribute = morphAttributes[ keys[ 0 ] ];
 
console.log("updateMorphTargets keys " + keys.length );
console.log("updateMorphTargets attribute " + keys[ 0 ]);
console.log( morphAttribute );
if ( morphAttribute !== undefined ) {
 
this.morphTargetInfluences = [];
......@@ -14098,6 +14102,8 @@
 
name = morphAttribute[ m ].name || String( m );
 
console.log("updateMorphTargets name " + name);
this.morphTargetInfluences.push( 0 );
this.morphTargetDictionary[ name ] = m;
 
......@@ -146,55 +146,66 @@ function PantonPouf() {
print( "PantonPouf start loading,<br/>loading display: " + this.config.path_model );
var loader = new THREE.FBXLoader();
loader.caller = this;
loader.path_loaded = this.config.path_model;
loader.load( loader.path_loaded, function ( object ) {
console.log( object.morphTargets );
} );
// var loader = new THREE.ColladaLoader();
// var loader = new THREE.FBXLoader();
// loader.caller = this;
// loader.path_loaded = this.config.path_model;
// loader.load( loader.path_loaded, function ( collada ) {
// loader.load( loader.path_loaded, function ( object ) {
// var sa = loader.caller;
// var conf = sa.config;
// console.log( object.morphTargets );
// } );
// sa.obj3d = collada.scene;
// sa.animations = collada.animations;
var loader = new THREE.ColladaLoader();
loader.caller = this;
loader.path_loaded = this.config.path_model;
// sa.scene.add( sa.obj3d );
loader.load( loader.path_loaded, function ( collada ) {
// console.log( sa.obj3d.morphTargets );
// sa.obj3d.traverse( function ( child ) {
var sa = loader.caller;
var conf = sa.config;
// if ( child.name == conf.mesh ) {
// sa.obj3d_mesh = child;
// console.log( sa.obj3d_mesh );
// }
sa.obj3d = collada.scene;
sa.animations = collada.animations;
// } );
sa.scene.add( sa.obj3d );
// console.log( sa.obj3d_mesh.morphTargets );
sa.obj3d.traverse( function ( child ) {
if ( child.name == conf.mesh ) {
sa.obj3d_mesh = child;
}
// sa.mixer = new THREE.AnimationMixer( sa.obj3d );
// sa.mixer.caller = sa;
// for ( var i = 0; i < sa.animations.length; ++i ) {
// var track = sa.mixer.clipAction( sa.animations[i] );
// track.setEffectiveWeight( 1 );
// track.enabled = true;
// track.just_looped = false;
// }
} );
// sa.ready = true;
console.log( "*********** obj3d_mesh ***********" );
console.log( sa.obj3d_mesh );
// console.log( "************* morphAttributes ***************" );
// console.log( sa.obj3d_mesh.morphAttributes );
// console.log( "************* morphTargets ***************" );
// console.log( sa.obj3d_mesh.geometry["pouf_mesh-mesh"].morphTargets );
// console.log( "************* morphNormals ***************" );
// console.log( sa.obj3d_mesh.geometry["pouf_mesh-mesh"].morphNormals );
// console.log( "****************************" );
// } );
sa.mixer = new THREE.AnimationMixer( sa.obj3d_mesh );
sa.mixer.caller = sa;
var clip = THREE.AnimationClip.CreateFromMorphTargetSequence( 'all_crashes', sa.obj3d_mesh.geometry.morphAttributes['position'], 30 );
sa.obj3d_mesh.morphTargetInfluences[
sa.obj3d_mesh.morphTargetDictionary["crash1"]
] = 1;
console.log( "*********** clip ***********" );
console.log( clip );
var action = sa.mixer.clipAction( clip );
action.setDuration( 10 ).play();
console.log( "*********** action ***********" );
console.log( action );
sa.ready = true;
} );
};
......
......@@ -62,8 +62,7 @@ if ( enable_sysiphus_avatar ) {
var config_pantonpouf = new PantonPoufConfig();
config_pantonpouf.mesh = "pouf";
// config_pantonpouf.path_model = 'models/playdo.dae';
config_pantonpouf.path_model = 'models/soft-cube.fbx';
config_pantonpouf.path_model = 'models/playdo.dae';
// *********************************
// ************ GLOBALS ************
......
......@@ -745,8 +745,10 @@ THREE.ColladaLoader.prototype = {
break;
case 'morph':
var c = child.getAttribute( 'source' );
data.id = parseId( child.getAttribute( 'source' ) );
console.warn( 'THREE.ColladaLoader: Morph target animation not supported yet.' );
data.morphs = parseMorphs( child );
console.warn( 'THREE.ColladaLoader: Morph targets loading is not complete at all...' );
break;
}
......@@ -757,6 +759,38 @@ THREE.ColladaLoader.prototype = {
}
function parseMorphs( xml ) {
var morphs = undefined;
for ( var i = 0, l = xml.childNodes.length; i < l; i++ ) {
var child = xml.childNodes[ i ];
switch ( child.nodeName ) {
case 'source':
for ( var j = 0, m = child.childNodes.length; j < m; j++ ) {
var subchild = child.childNodes[ j ];
// console.log( subchild.nodeName );
switch ( subchild.nodeName ) {
case 'IDREF_array':
morphs = subchild.textContent.split(" ");
default:
break;
}
}
break;
default:
break;
}
}
// console.log( morphs );
return morphs;
}
function parseSkin( xml ) {
var data = {
......@@ -869,6 +903,8 @@ THREE.ColladaLoader.prototype = {
var geometry = library.geometries[ build.id ];
// console.log( build.id );
if ( data.skin !== undefined ) {
build.skin = buildSkin( data.skin );
......@@ -880,6 +916,95 @@ THREE.ColladaLoader.prototype = {
}
if ( data.morphs !== undefined ) {
geometry.morph_data = [];
console.log("buildController, creation of morphTargets for '" + build.id + "'");
for( var i in data.morphs ) {
var key = data.morphs[ i ];
if ( key == build.id ) {
console.log( "skipping " + key );
continue;
}
for( var gid in library.geometries ) {
if ( gid == key ) {
var morph_geometry = library.geometries[ gid ];
var morph = {
id : morph_geometry.id,
name : morph_geometry.name
};
if ( morph_geometry.sources[ gid + "-positions" ] === undefined ) {
// mandatory to have positions to continue creating the morphs
console.log( "failed to transfer geometry id:" + gid + " in morphTarget name:" + morph.name );
break;
} else {
morph.positions = {
name : morph_geometry.name,
array: morph_geometry.sources[ gid + "-positions" ].array,
stride: morph_geometry.sources[ gid + "-positions" ].stride
};
}
if ( morph_geometry.sources[ gid + "-normals" ] === undefined ) {
console.log( "failed to transfer normals id:" + gid + " in morphNormal name:" + morph.name );
} else {
morph.normals = {
name : morph_geometry.name,
array: morph_geometry.sources[ gid + "-normals" ].array,
stride: morph_geometry.sources[ gid + "-normals" ].stride
};
}
if ( morph_geometry.sources[ gid + "-colors-Col" ] === undefined ) {
console.log( "failed to transfer colors id:" + gid + " in morphNormal name:" + morph.name );
} else {
morph.colors = {
name : morph_geometry.name,
array: morph_geometry.sources[ gid + "-colors-Col" ].array,
stride: morph_geometry.sources[ gid + "-colors-Col" ].stride
};
}
geometry.morph_data.push( morph );
console.log( "transfer of '" + gid + "' in morphTarget '" + morph.name + "'" );
delete library.geometries[ gid ];
break;
}
}
}
// console.log( library.geometries );
}
console.log( "buildController > Implement morph targets controller" );
return build;
}
......@@ -1926,12 +2051,15 @@ THREE.ColladaLoader.prototype = {
function parseGeometry( xml ) {
var data = {
id: xml.getAttribute( 'id' ),
name: xml.getAttribute( 'name' ),
sources: {},
vertices: {},
primitives: []
};
// console.log( "parseGeometry: " + data.id + " | " + data.name );
var mesh = getElementsByTagName( xml, 'mesh' )[ 0 ];
// the following tags inside geometry are not supported yet (see https://github.com/mrdoob/three.js/pull/12606): convex_mesh, spline, brep
......@@ -2150,10 +2278,94 @@ THREE.ColladaLoader.prototype = {
build[ type ] = buildGeometryType( primitiveType, sources, vertices );
console.log( "*********** buildGeometry, build[ " + type + " ] ***********" );
console.log( build[ type ].data );
}
if ( build[ "polylist" ] !== undefined && data.morph_data !== undefined ) {
console.log( "** Implementation might be hazardous at this point! **" );
console.log( data );
// getting the first primitive
var primitive = data.primitives[0];
var poly = build[ "polylist" ].data;
var vertex_offset = primitive.inputs.VERTEX.offset;
var normal_offset = primitive.inputs.NORMAL.offset;
var color_offset = primitive.inputs.COLOR.offset;
var total_offset = 9;
poly.morphAttributes = {};
console.log( "faces " + primitive.count );
console.log( "vertices " + ( primitive.count * 3 ) );
poly.morphAttributes.position = [];
poly.morphAttributes.normal = [];
for ( var i in data.morph_data ) {
var dpos = data.morph_data[i].positions;
var dnorms = data.morph_data[i].normals;
var position_array = new Float32Array( primitive.count * 3 );
var normal_array = undefined;
if ( dnorms !== undefined ) {
normal_array = new Float32Array( primitive.count * 3 );
}
for (
var v = 0, id = 0;
v < primitive.count * total_offset;
v += total_offset, ++id
) {
for ( var axis = 0; axis < 3; ++axis ) {
position_array[ id ] = dpos.array[ v + vertex_offset * 3 + axis ];
if ( dnorms !== undefined ) {
normal_array[ id ] = dnorms.array[ v + normal_offset * 3 + axis ];
}
}
}
var mattr_name = data.morph_data[i].name;
var buffattr = new THREE.Float32BufferAttribute(
position_array,
dpos.stride
);
buffattr.name = mattr_name;
poly.morphAttributes.position.push( buffattr );
if ( dnorms !== undefined ) {
buffattr = new THREE.Float32BufferAttribute(
normal_array,
dnorms.stride
);
buffattr.name = mattr_name;
poly.morphAttributes.normal.push( buffattr );
}
// console.log( data.morph_data[i].id );
console.log( "morphAttributes > " + mattr_name );
// console.log( poly.morphAttributes[ mattr_name ] );
}
}
return build;
}
function buildMorphTargets( obj, morphTargets ) {
}
function buildGeometryType( primitives, sources, vertices ) {
......@@ -2291,6 +2503,10 @@ THREE.ColladaLoader.prototype = {
uv.stride = sources[ input.id ].stride;
break;
default:
console.log( "buildGeometryType, case " + name + " ??? " );
break;
}
}
......@@ -2298,12 +2514,15 @@ THREE.ColladaLoader.prototype = {
}
// build geometry
// console.log( "***************** buildGeometryType, geometry *****************" );
// console.log( geometry );
if ( position.array.length > 0 ) geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( position.array, position.stride ) );
if ( normal.array.length > 0 ) geometry.addAttribute( 'normal', new THREE.Float32BufferAttribute( normal.array, normal.stride ) );
if ( color.array.length > 0 ) geometry.addAttribute( 'color', new THREE.Float32BufferAttribute( color.array, color.stride ) );
if ( uv.array.length > 0 ) geometry.addAttribute( 'uv', new THREE.Float32BufferAttribute( uv.array, uv.stride ) );
if ( skinIndex.array.length > 0 ) geometry.addAttribute( 'skinIndex', new THREE.Float32BufferAttribute( skinIndex.array, skinIndex.stride ) );
if ( skinWeight.array.length > 0 ) geometry.addAttribute( 'skinWeight', new THREE.Float32BufferAttribute( skinWeight.array, skinWeight.stride ) );
......@@ -2395,7 +2614,10 @@ THREE.ColladaLoader.prototype = {
function getGeometry( id ) {
return getBuild( library.geometries[ id ], buildGeometry );
var obj = getBuild( library.geometries[ id ], buildGeometry );
console.log( "******** getGeometry " + id + " ********* " );
console.log( obj );
return obj;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment