Comments (6)
I will implement the ObjectLoader.
But you should already be able to make it work manually. The ExtendedObject3D already extends all Object3D functionalities.
Maybe you want to share your code?
Edit:
Oh, wait. The ObjectLoader is actually for JSON Object Scenes. I did not know that. I will see what I can do.
from enable3d.
I have implemented the ObjectLoader (e32baa8).
This is how you will be able to do it:
async preload() {
this.load.preload('plane', '/assets/plane.json')
}
async create() {
this.load.object('plane').then((obj: any) => {
// in most cases ExtendedObject3D is not needed
// to be able to add physics, just add a name
obj.name = `object-${obj.id}`
this.scene.add(obj)
})
}
// or without preloading
this.load.object('/assets/plane.json').then((obj: any) => { ... }
// async/await is of course also supported
const obj = await this.load.object('/assets/plane.json')
If you do already have a THREE.ObjectLoader in your project and want to add physics to it, just set the name as in the example above.
Hope this helps :)
from enable3d.
This won't save and load the information specific to Extended objects though (physics body velocity for example), that's more what I'm looking for.
from enable3d.
Well it will not be 100% an ExtendedObject3D, but most of the code of the ExtendedObject3D is only related to animations anyways. When you use this.physics.add.existing(obj)
, the object will receive a physics body. Of course if you use TypeScript, you won't get the fancy IntelliSense. Fortunately, you can add the ExtendedObject3D type to any object you want.
Try this:
(everything, except animations, should work)
// add ExtendedObject3D as the type
this.load.object('plane').then((obj: ExtendedObject3D) => {
// add a name (this is required for physics)
obj.name = `object-${obj.id}`
this.scene.add(obj)
// add a physics body
this.physics.add.existing(obj, { shape: 'convex' })
// use the physics body with IntelliSense
obj.body.applyForceY(5)
})
from enable3d.
Actually, if you look at the examples, I always use the following approach:
// preload the object
this.load.preload('plane', '/assets/plane.json')
// parse the object
this.load.object('plane').then(obj => {
// create the extendedObject3D
const plane = new ExtendedObject3D()
// add the object as a child
plane.add(obj)
// add plane to the scene
this.scene.add(plane)
// add a physics body
this.physics.add.existing(plane, { shape: 'convex' })
// use the physics body with IntelliSense
plane.body.applyForceY(5)
})
from enable3d.
I've solved this by storing the physics body data in userData for each object. It would be nice to have a native loader for saving/loading aspects of a physics body such as shape, velocity, collision flags etc but I can manage doing this manually for now. Thanks for your help.
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)?
- shape='box' Add rigid body, why my rigid body is bigger than the actual object, I don't know what's wrong. HOT 13
- 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.