So I added random distributer of Rock like objects using hardwareInstancing and add collision directly on Ammo.
const newTrans = new Ammo.btVector3 ();
newTrans.setX(pos.x);
newTrans.setY(pos.y);
newTrans.setZ(pos.z);
const transformDoIt = new Ammo.btTransform();
transformDoIt.setOrigin(newTrans);
const rbody = new Ammo.btRigidBody ();
rbody.setWorldTransform (transformDoIt);
rbody.setCollisionShape (shape);
dynamicsWorld.addRigidBody(rbody);
rbody.activate(true);
I added collision like this way,
(function(){
var _distanceVec3 = new pc.Vec3();
pc.RigidBodyComponentSystem.prototype.raycastFirstByTag = function (start, end, tag) {
// var closestDistanceSqr = Number.MAX_VALUE;
// var closestResult = null;
// Go through all the entities that intersect with the raycast and
// find the closest one that matches the tag query passed
// var results = this.app.systems.rigidbody.raycastAll(start, end, tag);
let result_Ammo = null;
var ammoRayStart = new Ammo.btVector3();
var ammoRayEnd = new Ammo.btVector3();
ammoRayStart.setValue(start.x, start.y, start.z);
ammoRayEnd.setValue(end.x, end.y, end.z);
var rayCallback = new Ammo.ClosestRayResultCallback(ammoRayStart, ammoRayEnd);
rayCallback.m_collisionFilterGroup = pc.BODYGROUP_DYNAMIC | pc.BODYGROUP_STATIC| pc.BODYGROUP_DEFAULT;
rayCallback.m_collisionFilterMask = pc.BODYGROUP_DYNAMIC | pc.BODYGROUP_STATIC| pc.BODYGROUP_DEFAULT;
this.app.systems.rigidbody.dynamicsWorld.rayTest(ammoRayStart, ammoRayEnd, rayCallback);
if (rayCallback.hasHit()) {
const collisionObj = rayCallback.get_m_collisionObject();
const body = Ammo.castObject(collisionObj, Ammo.btRigidBody);
if (body) {
const point = rayCallback.get_m_hitPointWorld();
const normal = rayCallback.get_m_hitNormalWorld();
result_Ammo = new pc.RaycastResult(
body.entity,
new pc.Vec3(point.x(), point.y(), point.z()),
new pc.Vec3(normal.x(), normal.y(), normal.z())
);
}
}
Ammo.destroy(rayCallback);
// for (var i = 0; i < results.length; ++i) {
// var result = results[i];
// if (result.entity.tags.has(tag)) {
// _distanceVec3.sub2(result.point, start);
// var distanceSqr = _distanceVec3.lengthSq();
// if (distanceSqr < closestDistanceSqr) {
// closestDistanceSqr = distanceSqr;
// closestResult = result;
// }
// }
// }
return result_Ammo;
};
})();
So this is raycast code that i used but it doesn’t return collision I added upper way. Any Solution