Skip to content

Commit f36c9c5

Browse files
authored
Merge pull request #13885 from ferrolho/dev
Adds physics model parser to ColladaLoader.js
2 parents 5a1fb62 + af174c5 commit f36c9c5

File tree

1 file changed

+79
-1
lines changed

1 file changed

+79
-1
lines changed

examples/js/loaders/ColladaLoader.js

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2686,6 +2686,82 @@ THREE.ColladaLoader.prototype = {
26862686

26872687
}
26882688

2689+
// physics
2690+
2691+
function parsePhysicsModel( xml ) {
2692+
2693+
var data = {
2694+
name: xml.getAttribute( 'name' ) || '',
2695+
rigidBodies: {}
2696+
};
2697+
2698+
for ( var i = 0; i < xml.childNodes.length; i ++ ) {
2699+
2700+
var child = xml.childNodes[ i ];
2701+
2702+
if ( child.nodeType !== 1 ) continue;
2703+
2704+
switch ( child.nodeName ) {
2705+
2706+
case 'rigid_body':
2707+
data.rigidBodies[ child.getAttribute( 'name' ) ] = {};
2708+
parsePhysicsRigidBody( child, data.rigidBodies[ child.getAttribute( 'name' ) ] );
2709+
break;
2710+
2711+
}
2712+
2713+
}
2714+
2715+
library.physicsModels[ xml.getAttribute( 'id' ) ] = data;
2716+
2717+
}
2718+
2719+
function parsePhysicsRigidBody( xml, data ) {
2720+
2721+
for ( var i = 0; i < xml.childNodes.length; i ++ ) {
2722+
2723+
var child = xml.childNodes[ i ];
2724+
2725+
if ( child.nodeType !== 1 ) continue;
2726+
2727+
switch ( child.nodeName ) {
2728+
2729+
case 'technique_common':
2730+
parsePhysicsTechniqueCommon( child, data );
2731+
break;
2732+
2733+
}
2734+
2735+
}
2736+
2737+
}
2738+
2739+
function parsePhysicsTechniqueCommon( xml, data ) {
2740+
2741+
for ( var i = 0; i < xml.childNodes.length; i ++ ) {
2742+
2743+
var child = xml.childNodes[ i ];
2744+
2745+
if ( child.nodeType !== 1 ) continue;
2746+
2747+
switch ( child.nodeName ) {
2748+
2749+
case 'inertia':
2750+
data.inertia = parseFloats( child.textContent );
2751+
break;
2752+
2753+
case 'mass':
2754+
data.mass = parseFloats( child.textContent )[0];
2755+
break;
2756+
2757+
}
2758+
2759+
}
2760+
2761+
}
2762+
2763+
// scene
2764+
26892765
function parseKinematicsScene( xml ) {
26902766

26912767
var data = {
@@ -3282,7 +3358,7 @@ THREE.ColladaLoader.prototype = {
32823358
// and weights defined for it. But we still have to add the bone to the sorted bone list in order to
32833359
// ensure a correct animation of the model.
32843360

3285-
boneInverse = new THREE.Matrix4();
3361+
boneInverse = new THREE.Matrix4();
32863362

32873363
}
32883364

@@ -3684,6 +3760,7 @@ THREE.ColladaLoader.prototype = {
36843760
nodes: {},
36853761
visualScenes: {},
36863762
kinematicsModels: {},
3763+
physicsModels: {},
36873764
kinematicsScenes: {}
36883765
};
36893766

@@ -3699,6 +3776,7 @@ THREE.ColladaLoader.prototype = {
36993776
parseLibrary( collada, 'library_nodes', 'node', parseNode );
37003777
parseLibrary( collada, 'library_visual_scenes', 'visual_scene', parseVisualScene );
37013778
parseLibrary( collada, 'library_kinematics_models', 'kinematics_model', parseKinematicsModel );
3779+
parseLibrary( collada, 'library_physics_models', 'physics_model', parsePhysicsModel );
37023780
parseLibrary( collada, 'scene', 'instance_kinematics_scene', parseKinematicsScene );
37033781

37043782
buildLibrary( library.animations, buildAnimation );

0 commit comments

Comments
 (0)