Comments (13)
If it can't detect the shape, it will add 1x1x1 box.
Or you could try to pass shape
while creating the physics.
this.physics.add.existing(object, { shape: "mesh" })
But manually adding a box shape (like you did) is way better for performance.
from enable3d.
Yes, adding a box shape manually, does not take into account the rotation of the object. It just wraps a box as it is.
from enable3d.
Try to just manually switch width and height for now.
from enable3d.
Can you please upload the model?
from enable3d.
There are two models, one with the center point in the center and one with the center point not on the object.
There is another problem if the center point is not the center point of the object, the resulting physical rigid body is at the center point instead of the center point of the object
from enable3d.
Figure 1 shows the model directly creating the physical body
Figure 2 shows the physical body created after rotating the test1 model
const test1 = editor.scene.getObjectByName("test1");
const test2 = editor.scene.getObjectByName("test2");
// test1.rotateX(Math.PI / 2);
physicsManager.createRigidBodyByObject(test1, {
shape: "box",
width: new THREE.Box3()
.setFromObject(test1)
.getSize(new THREE.Vector3()).x,
height: new THREE.Box3()
.setFromObject(test1)
.getSize(new THREE.Vector3()).y,
depth: new THREE.Box3()
.setFromObject(test1)
.getSize(new THREE.Vector3()).z,
});
physicsManager.createRigidBodyByObject(test2, {
shape: "box",
width: new THREE.Box3()
.setFromObject(test2)
.getSize(new THREE.Vector3()).x,
height: new THREE.Box3()
.setFromObject(test2)
.getSize(new THREE.Vector3()).y,
depth: new THREE.Box3()
.setFromObject(test2)
.getSize(new THREE.Vector3()).z,
});
from enable3d.
This works for me:
import { PhysicsLoader, Project, Scene3D, THREE } from 'enable3d'
class MainScene extends Scene3D {
async preload() {
this.load.preload('obj1', '/assets/obj1.glb')
}
async create() {
this.warpSpeed()
this.camera.position.set(2, 2, 4)
this.physics.debug?.enable()
{
const obj1 = (await this.load.gltf('obj1')).scene
const box = new THREE.Box3()
const size = new THREE.Vector3()
const center = new THREE.Vector3()
box.setFromObject(obj1).getSize(size)
box.setFromObject(obj1).getCenter(center)
obj1.traverse(child => {
if (child.isMesh) {
child.material.metalness = 0
child.geometry.translate(-center.x, -center.y, -center.z)
}
})
this.add.existing(obj1)
this.physics.add.existing(obj1, {
shape: 'box',
width: size.x,
height: size.y,
depth: size.z
})
}
}
}
PhysicsLoader('/lib', () => new Project({ scenes: [MainScene] }))
from enable3d.
It doesn't work for me. Is the model you're testing mine?
If obj1.position.set(0,1,0)
then geometry.translate()
will it work?
from enable3d.
Yes, your model.
Yes. I tried it with setting a position and it worked. Just do it after the obj1.traverse
but before you add.physics
.
from enable3d.
Okay、I tried using class MainScene extends Scene3D, rotation and center point in my demo and it worked.
But I'm not using the recommended class MainScene extends Scene3D. I'm using import {AmmoPhysics} from "@enable3d/ammo-physics";
I put the demo in https://github.com/volcanoqq/enable3d-app, can you help me take a look at what's the problem cause。
from enable3d.
I am using the 'box' physics collision with the custom width, height and depth but the bounding box is way bigger than the object see image 2
while when i apply 'mesh' it work fine but it will take system performance. Is there any solution for this problem please help!!
from enable3d.
I am using the 'box' physics collision with the custom width, height and depth but the bounding box is way bigger than the object see image 2 while when i apply 'mesh' it work fine but it will take system performance. Is there any solution for this problem please help!!
Not sure. But you can manually adjust it. (See above)
from enable3d.
I want to make generic code with the performance because I am running this solution on mobile. Mesh is solving the problem right now but it is not the optimized way to achieve for this reason I am using 'Box' collider can you please help me how the manual width, height, depth solve my issue
getBoundingSize: function(object){
const self = this;
let box = new THREE.Box3();
box.setFromObject(object);
let size = new THREE.Vector3();
box.getSize(size);
let center = new THREE.Vector3();
box.getCenter(center);
return size;
}
from enable3d.
Related Issues (20)
- enable3d 0.25 fails to build with esbuild HOT 6
- physicsWorld.getWorldInfo() is not function inside @enable3d/ammo-physics HOT 6
- React JS doesn't support Enable3d HOT 2
- React JS doesn't support Enable3d HOT 2
- AmmoPhysics Error: abort(OOM). HOT 2
- Wrong typings? HOT 2
- The error that "require" cannot be used in rollup packaging occurs! HOT 5
- ObjectLoader does not work when used after preloading model files HOT 10
- Crash Loading 3D Heightmap from PNG Example HOT 3
- Hello, I found a problem. Physical objects shake constantly during falling. How did this problem come about? HOT 2
- svg , other shapes then concave ? HOT 1
- Joystick on typescript in Phaser extension HOT 1
- Hide Powered by Enable3D? HOT 1
- IN @enable3d/phaser-extension Scene3D can not stop or start a scene HOT 3
- Does Enable3D support Inverse Kinematics (IK)?
- I tried to pick-up objects and it didn't work out. HOT 4
- Uncaught RuntimeError: abort(OOM).
- In this example, pressing the A and D buttons has no effect! HOT 1
- THANK YOU FOR CREATING ENABLE3D!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enable3d.