Skip to content

Commit

Permalink
Add m_nodes and m_materials attributes, remove ad-hoc functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
yomboprime committed Nov 25, 2015
1 parent f44d593 commit 29ac5e7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
26 changes: 17 additions & 9 deletions ammo.idl
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,17 @@ interface btSoftBodyWorldInfo {
[Value] attribute btVector3 m_gravity;
};

[Prefix="btSoftBody::"]
interface Node {
[Value] attribute btVector3 m_x;
};

[Prefix="btSoftBody::"]
interface tNodeArray {
[Const] long size();
[Const, Ref] Node at(long n);
};

[Prefix="btSoftBody::"]
interface Material {
attribute float m_kLST;
Expand All @@ -699,14 +710,9 @@ interface Material {
};

[Prefix="btSoftBody::"]
interface Node {
[Value] attribute btVector3 m_x;
};

[Prefix="btSoftBody::"]
interface tNodeArray {
interface tMaterialArray {
[Const] long size();
[Const, Ref] Node at(long n);
Material at(long n);
};

[Prefix="btSoftBody::"]
Expand Down Expand Up @@ -742,6 +748,9 @@ interface btSoftBody {
void btSoftBody(btSoftBodyWorldInfo worldInfo);//, long node_count, [Const] btVector3 x, [Const] long m);

[Value] attribute Config m_cfg;
[Value] attribute tNodeArray m_nodes;
[Value] attribute tMaterialArray m_materials;

[Const] boolean checkLink( long node0, long node1);
[Const] boolean checkFace( long node0, long node1, long node2);
Material appendMaterial();
Expand All @@ -752,14 +761,13 @@ interface btSoftBody {
void appendAnchor( long node, btRigidBody body, boolean disableCollisionBetweenLinkedBodies, float influence);
[Const] float getTotalMass();
void setTotalMass( float mass, boolean fromfaces);
void setMass(long node, float mass);
void transform( [Const, Ref] btTransform trs);
void translate( [Const, Ref] btVector3 trs);
void rotate( [Const, Ref] btQuaternion rot);
void scale( [Const, Ref] btVector3 scl);
long generateClusters(long k, optional long maxiterations);
btSoftBody upcast([Const] btCollisionObject colObj);
Node getNode(long i);
void setIterations( long viterations, long piterations );
};
btSoftBody implements btCollisionObject;

Expand Down
17 changes: 8 additions & 9 deletions examples/webgl_demo_softbody_cloth/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@
// Ground
pos.set( 0, - 0.5, 0 );
quat.set( 0, 0, 0, 1 );
var ground = createParalellepiped( 20, 1, 20, 0, pos, quat, new THREE.MeshPhongMaterial( { color: 0xFFFFFF } ) );
var ground = createParalellepiped( 40, 1, 40, 0, pos, quat, new THREE.MeshPhongMaterial( { color: 0xFFFFFF } ) );
ground.castShadow = true;
ground.receiveShadow = true;
textureLoader.load( "../textures/grid.png", function( texture ) {
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set( 20, 20 );
texture.repeat.set( 40, 40 );
ground.material.map = texture;
ground.material.needsUpdate = true;
} );
Expand Down Expand Up @@ -295,11 +295,10 @@
arm.castShadow = true;
arm.receiveShadow = true;

// Glue the cloth extremes to the arm
// Glue the cloth to the arm
var influence = 0.5;
for ( var i = 0; i < clothNumSegmentsZ + 1; i++ ) {
clothSoftBody.appendAnchor( i, arm.userData.physicsBody, false, influence );
}
clothSoftBody.appendAnchor( 0, arm.userData.physicsBody, false, influence );
clothSoftBody.appendAnchor( clothNumSegmentsZ, arm.userData.physicsBody, false, influence );

// Hinge constraint to move the arm
var pivotA = new Ammo.btVector3( 0, pylonHeight * 0.5, 0 );
Expand All @@ -308,7 +307,6 @@
hinge = new Ammo.btHingeConstraint( pylon.userData.physicsBody, arm.userData.physicsBody, pivotA, pivotB, axis, axis, true );
physicsWorld.addConstraint( hinge, true );


}

function createParalellepiped( sx, sy, sz, mass, pos, quat, material ) {
Expand Down Expand Up @@ -431,13 +429,14 @@

// Update cloth
var softBody = cloth.userData.physicsBody;

var clothPositions = cloth.geometry.attributes.position.array;
var numVerts = clothPositions.length / 3;
var nodes = softBody.get_m_nodes();
var indexFloat = 0;
for ( var i = 0; i < numVerts; i ++ ) {

var nodePos = softBody.getNode( i ).get_m_x();
var node = nodes.at( i );
var nodePos = node.get_m_x();
clothPositions[ indexFloat++ ] = nodePos.x();
clothPositions[ indexFloat++ ] = nodePos.y();
clothPositions[ indexFloat++ ] = nodePos.z();
Expand Down
9 changes: 5 additions & 4 deletions examples/webgl_demo_softbody_rope/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@
// Ground
pos.set( 0, - 0.5, 0 );
quat.set( 0, 0, 0, 1 );
var ground = createParalellepiped( 20, 1, 20, 0, pos, quat, new THREE.MeshPhongMaterial( { color: 0xFFFFFF } ) );
var ground = createParalellepiped( 40, 1, 40, 0, pos, quat, new THREE.MeshPhongMaterial( { color: 0xFFFFFF } ) );
ground.castShadow = true;
ground.receiveShadow = true;
textureLoader.load( "../textures/grid.png", function( texture ) {
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set( 20, 20 );
texture.repeat.set( 40, 40 );
ground.material.map = texture;
ground.material.needsUpdate = true;
} );
Expand Down Expand Up @@ -443,13 +443,14 @@

// Update rope
var softBody = rope.userData.physicsBody;

var ropePositions = rope.geometry.attributes.position.array;
var numVerts = ropePositions.length / 3;
var nodes = softBody.get_m_nodes();
var indexFloat = 0;
for ( var i = 0; i < numVerts; i ++ ) {

var nodePos = softBody.getNode( i ).get_m_x();
var node = nodes.at( i );
var nodePos = node.get_m_x();
ropePositions[ indexFloat++ ] = nodePos.x();
ropePositions[ indexFloat++ ] = nodePos.y();
ropePositions[ indexFloat++ ] = nodePos.z();
Expand Down

0 comments on commit 29ac5e7

Please sign in to comment.