Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed examples. #175

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions examples/webgl_demo/ammo.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
}
</style>

<script src="shared.js"></script>

<script type="text/javascript">
// Main demo code

Expand Down Expand Up @@ -191,4 +189,3 @@ <h2>ammo.js benchmark</h2>
</center>
</body>
</html>

3 changes: 0 additions & 3 deletions examples/webgl_demo/ammo.wasm.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
}
</style>

<script src="shared.js"></script>

<script type="text/javascript">
// Main demo code

Expand Down Expand Up @@ -191,4 +189,3 @@ <h2>ammo.js benchmark</h2>
</center>
</body>
</html>

3 changes: 1 addition & 2 deletions examples/webgl_demo/worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

var Module = { TOTAL_MEMORY: 256*1024*1024 };

importScripts('ammo.js');
importScripts('../../builds/ammo.js');

Ammo().then(function(Ammo) {
var NUM = 0, NUMRANGE = [];
Expand Down Expand Up @@ -168,4 +168,3 @@ Ammo().then(function(Ammo) {
interval = setInterval(mainLoop, 1000/60);
}
});

4 changes: 4 additions & 0 deletions examples/webgl_demo_softbody_cloth/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

<script>

Ammo().then(function(Ammo) {

// Detects webgl
if ( ! Detector.webgl ) {
Detector.addGetWebGLMessage();
Expand Down Expand Up @@ -465,6 +467,8 @@

}

});

</script>

</body>
Expand Down
4 changes: 4 additions & 0 deletions examples/webgl_demo_softbody_rope/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

<script>

Ammo().then(function(Ammo) {

// Detects webgl
if ( ! Detector.webgl ) {
Detector.addGetWebGLMessage();
Expand Down Expand Up @@ -477,6 +479,8 @@

}

});

</script>

</body>
Expand Down
54 changes: 29 additions & 25 deletions examples/webgl_demo_softbody_volume/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

<script>

Ammo().then(function(Ammo) {

// Detects webgl
if ( ! Detector.webgl ) {
Detector.addGetWebGLMessage();
Expand Down Expand Up @@ -190,15 +192,15 @@

// Create soft volumes
var volumeMass = 15;

var sphereGeometry = new THREE.SphereBufferGeometry( 1.5, 40, 25 );
sphereGeometry.translate( 5, 5, 0 );
createSoftVolume( sphereGeometry, volumeMass, 250 );

var boxGeometry = new THREE.BufferGeometry().fromGeometry( new THREE.BoxGeometry( 1, 1, 5, 4, 4, 20 ) );
boxGeometry.translate( -2, 5, 0 );
createSoftVolume( boxGeometry, volumeMass, 120 );

// Ramp
pos.set( 3, 1, 0 );
quat.setFromAxisAngle( new THREE.Vector3( 0, 0, 1 ), 30 * Math.PI / 180 );
Expand All @@ -212,13 +214,13 @@

// Obtain a Geometry
var geometry = new THREE.Geometry().fromBufferGeometry( bufGeometry );

// Merge the vertices so the triangle soup is converted to indexed triangles
var vertsDiff = geometry.mergeVertices();

// Convert again to BufferGeometry, indexed
var indexedBufferGeom = createIndexedBufferGeometryFromGeometry( geometry );

// Create index arrays mapping the indexed vertices to bufGeometry vertices
mapIndices( bufGeometry, indexedBufferGeom );

Expand Down Expand Up @@ -262,22 +264,22 @@

return bufferGeom;
}

function isEqual( x1, y1, z1, x2, y2, z2 ) {
var delta = 0.000001;
return Math.abs( x2 - x1 ) < delta &&
Math.abs( y2 - y1 ) < delta &&
Math.abs( z2 - z1 ) < delta;
}

function mapIndices( bufGeometry, indexedBufferGeom ) {

// Creates ammoVertices, ammoIndices and ammoIndexAssociation in bufGeometry

var vertices = bufGeometry.attributes.position.array;
var idxVertices = indexedBufferGeom.attributes.position.array;
var indices = indexedBufferGeom.index.array;

var numIdxVertices = idxVertices.length / 3;
var numVertices = vertices.length / 3;

Expand All @@ -286,39 +288,39 @@
bufGeometry.ammoIndexAssociation = [];

for ( var i = 0; i < numIdxVertices; i++ ) {

var association = [];
bufGeometry.ammoIndexAssociation.push( association );

var i3 = i * 3;

for ( var j = 0; j < numVertices; j++ ) {
var j3 = j * 3;
if ( isEqual( idxVertices[ i3 ], idxVertices[ i3 + 1 ], idxVertices[ i3 + 2 ],
vertices[ j3 ], vertices[ j3 + 1 ], vertices[ j3 + 2 ] ) ) {
association.push( j3 );
}
}

}

}

function createSoftVolume( bufferGeom, mass, pressure ) {

processGeometry( bufferGeom );

var volume = new THREE.Mesh( bufferGeom, new THREE.MeshPhongMaterial( { color: 0xFFFFFF } ) );
volume.castShadow = true;
volume.receiveShadow = true;
volume.frustumCulled = false;
scene.add( volume );

textureLoader.load( "../textures/colors.png", function( texture ) {
volume.material.map = texture;
volume.material.needsUpdate = true;
} );

// Volume physic object

var volumeSoftBody = softBodyHelpers.CreateFromTriMesh(
Expand Down Expand Up @@ -353,7 +355,7 @@
volumeSoftBody.setActivationState( 4 );

softBodies.push( volume );

}

function createParalellepiped( sx, sy, sz, mass, pos, quat, material ) {
Expand Down Expand Up @@ -404,7 +406,7 @@
function initInput() {

window.addEventListener( 'mousedown', function( event ) {

if ( ! clickRequest ) {

mouseCoords.set(
Expand All @@ -415,7 +417,7 @@
clickRequest = true;

}

}, false );

}
Expand All @@ -425,7 +427,7 @@
if ( clickRequest ) {

raycaster.setFromCamera( mouseCoords, camera );

// Creates a ball
var ballMass = 3;
var ballRadius = 0.4;
Expand Down Expand Up @@ -474,7 +476,7 @@
var deltaTime = clock.getDelta();

updatePhysics( deltaTime );

processClick();

controls.update( deltaTime );
Expand All @@ -499,7 +501,7 @@
var numVerts = association.length;
var nodes = softBody.get_m_nodes();
for ( var j = 0; j < numVerts; j ++ ) {

var node = nodes.at( j );
var nodePos = node.get_m_x();
var x = nodePos.x();
Expand All @@ -524,7 +526,7 @@
volumeNormals[ indexVertex ] = nz;
}
}

geometry.attributes.position.needsUpdate = true;
geometry.attributes.normal.needsUpdate = true;

Expand All @@ -548,6 +550,8 @@

}

});

</script>

</body>
Expand Down
Loading