Cannot read property 'createStaticConvexHull' of undefined?

So why am I getting ‘Uncaught TypeError: Cannot read property ‘createStaticConvexHull’ of undefined’ when I clearly have included the ‘AmmoUtils.js’ file in the project & call it like this?

var body = Ammo.Utils.createStaticConvexHull( points, x, y, z, yaw, 0, 0 );

These are my function{s} :

function setupStaticObjects ( )

{

    var loadBatch = [
        { name: 'container', url:'models/environment/29palms/shippingcontainer.js' },
	    { name: 'collision', url:'models/environment/29palms/collision_shippingcontainer.js' },
	    { name: 'barrel', url:'models/environment/29palms/barrel.js' }
    ];

    THREEx.Utils.batchLoadJSON( loadBatch, function( results ) {

		var crateGeom = results['container'].geometry;
		var barrelGeom = results['barrel'].geometry;
		var crateCollision = results['collision'].geometry;
		var crateMat = results['container'].materials[ 0 ];
		var barrelMat = results['barrel'].materials[ 0 ];

		var angle = Math.PI / 2;
		var angle = 2*Math.PI;
		var degrees = 360;

		var getAngle = function ( degrees ) {
	        var angle = 2 * Math.PI;
		    return angle * ( degrees / 360 );
		};

		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 50, 100, 50, getAngle(10));
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 50, 100, 250, getAngle(90));
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, -200, 90, 200, getAngle(90));
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, -200, 96, 160, getAngle(90));
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, -200, 100, 120, getAngle(90));
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, -200, 100, 80, getAngle(90));
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, -50, 50, 40, getAngle(0));
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 100, 100, 50 );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 150, 100, 50 );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 200, 100, 50 );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 280, 110, 50, getAngle(45));
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 180, 110, -150 );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 280, 110, -150, getAngle(90) );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 300, 110, -120, getAngle(90) );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 400, 110, -100, getAngle(0) );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 140, 110, -150 );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 90, 115, -150 );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, 0, 115, -170 );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, -50, 115, -190 );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, -70, 100, 30 );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, -120, 100, 60 );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, -160, 100, 55 );
		setupStaticMeshObject( crateGeom, crateMat, crateCollision, -250, 100, 10 );

		var barrelHeight = terrainMesh.geometry.getTerrainHeight( -50, 50 );
		barrelMesh = setupStaticCylinderObject( barrelGeom, barrelMat, -50, barrelHeight, 50 );

    });

}

function setupStaticMeshObject( renderGeometry, renderMaterial, collisionGeometry, x, y, z, yaw )

{

    yaw = ( yaw != undefined ) ? yaw: 0;

	var renderMesh = new THREE.Mesh( renderGeometry, renderMaterial );
	renderMesh.castShadow = true;
    renderMesh.receiveShadow = true;
	renderMesh.position.set( x, y, z );
	renderMesh.rotation.y = yaw;
    scene.add( renderMesh );

    var points = [];

    for ( var i = 0; i < collisionGeometry.vertices.length; ++i ) {

    points.push( collisionGeometry.vertices[ i ].x );
	points.push( collisionGeometry.vertices[ i ].y );
	points.push( collisionGeometry.vertices[ i ].z );

    }

	var body = Ammo.Utils.createStaticConvexHull( points, x, y, z, yaw, 0, 0 );
	body.type = "crate";
	physicsWorld.addRigidBody( body );

}

Hey my dude. Clearly you do not have Ammo.Utils, that property is undefined. Why is that? I don’t know to be honest :slight_smile:

I suggest you try asking on ammo.js GitHub :grey_question:. You can also look into that fabled AmmoUtils.js file to see if it actually sets the property that you are looking for. :mag:

As a side note - if you are loading AmmoUtils.js before loading Ammo.js itself - you might see that kind of behaviour, since (probably) Ammo.js would create global Ammo variable, overwriting whatever AmmoUtils creates. Basically, make sure you load Ammo before you load AmmoUtils.

Have fun with ammo :gun:

2 Likes

Thank you for trying to help, I appreciate that. But I am most-certainly calling AmmoUtils.js. I have posted the code into a pastebin which can be found here:

https://pastebin.com/BcBkCJDM

Thank you!

No worries, what about my other suggestions, have you tried those?

Yes I did. Also, I am loading Ammo.js before AmmoUtils.js. I’ve tried stackoverflow. It’s too strict on the way it wants you to post.

I had a look at the file you posted, it looks fine. I’m guessing the problem is in how you load it. Without knowing how you do it - I won’t be able to help further.

I’ll post a link to a demo I made.

From a search I’ve done in google, I think AmmoUtils i too old and it uses a previous version of Ammo. The current version is not compatible because it is loaded asynchronously.

praise the google

3 Likes

I will be posting the demo, shortly.

@Usnul : Here is the demo :

http://babylontesting.epizy.com/Three.js/WebFPS/

EDIT 1 :

Go to http://babylontesting.epizy.com/Three.js/WebFPS/js/mainframes/mainframe.js to see the Source.

EDIT 2 :

Line 228 is what you want to focus on.

my suggestion, check the type of geometry just to make sure it’s not a buffer geometry

Just checked. it is not buffer geometry.

EDIT 1 : Did a second check just to make sure, digging a little deeper.

EDIT 2 : Nope, no buffer geometry anywhere in the code OR in the models.

1 Like

So i figured out that the Ammo.js you were using is not updated, and I also removed the promises
so here is the live remake: https://silver-wormhole.glitch.me/
edit / fork here: https://glitch.com/edit/#!/silver-wormhole

remix before editing so you can have a backup

NB: I can’t find your terrain mesh lol, and i suggest you start using gltf loader as it’ s more updated and webgl friendly :wink:

cheers!

Hi, @waverider404: Thank you SO kindly! :slight_smile: I will take a look at the source now.

One problem though, the files linked to my site return an error : Failed to load resource: net::ERR_CERT_AUTHORITY_INVALID , I have a feeling this has to do with CORs. you may want to disable CORs on your code to fix this. :slight_smile:

Also, why is the camera / objects shaking & why can’t the camera move with keys? I thought I had an FPS controller setup for that.

1 Like

Yeah i was hoping you can get the scripts to load, i was quite busy while trying to rebuild the entire code. Is it working now?

@waverider404: Yes, but the camera / objects are shaking for some reason.

yeah i made the camera track the crate position while it’s falling, you can comment it out, it’s around the SetupStaticConvexHull function

EDIT : Nvm, found it

@waverider404: Ok, so now that the shaking problem is gone, why is my character not using sliding collision when moving up against the container objects?

EDIT : Also, can I use regular ammo.js instead of ammo.small_1.js?