Translating a parent container and keeping current camera view #35
Replies: 3 comments 14 replies
-
At this time all positions on a 3d container is in world space by default, maybe I could add an option to change that behaviour for a 3d container? I guess you could create your own class extending for PIXI Container and inside that one to the "screenToWorld" for your 3d object. Otherwise as you said you could use a orthographic camera if that works for you... |
Beta Was this translation helpful? Give feedback.
-
Here is an example how you could create a 2d container with 3d content, this only handles position. You have to figure out scale/rotation if you need it :-) let app = new PIXI.Application({
backgroundColor: 0xdddddd, resizeTo: window, antialias: true
})
document.body.appendChild(app.view)
class Container2D extends PIXI.Container {
constructor() {
super()
this._container3D = super.addChild(new PIXI3D.Container3D())
this.z = 7
}
addChild(displayObject) {
this._container3D.addChild(displayObject)
return displayObject
}
_render() {
PIXI3D.Camera.main.screenToWorld(
this.x, this.y, this.z, this._container3D.position)
}
}
let container2D = app.stage.addChild(new Container2D())
document.onmousemove = (evt) => {
container2D.position.set(evt.x, evt.y)
}
let mesh = container2D.addChild(PIXI3D.Mesh3D.createCube())
let light = Object.assign(new PIXI3D.Light(), {
x: -1,
z: +3,
})
PIXI3D.LightingEnvironment.main.lights.push(light)
let rotation = 0
app.ticker.add(() => {
mesh.rotationQuaternion.setEulerAngles(0, rotation++, 0)
}) |
Beta Was this translation helpful? Give feedback.
-
I have created a component called MeshSprite which might be of use for this scenario. MeshSprite is pretty much a regular PixiJS sprite which can have an 3D object that gets rendered to the sprite's texture. It would be really good if you would find the time to feedback this component. You can find an example how MeshSprite can be used here: https://github.com/jnsmalm/pixi3d/blob/develop/examples/src/mesh-sprite.js. I have not released it yet, so if you want to try it you need to:
You will find the build at dist/pixi3d.js. Please let me know if you have any feedback and if it covers your scenario. |
Beta Was this translation helpful? Give feedback.
-
Good day developer:
Is it possible to move just a parent container and only have the effect of translation on the 3D Object.
Here is an example:
If I modify the topLeft container such as the following:
let topLeft = new PIXI3D.Container3D();
topLeft.x = 600;
topLeft.y = 0;
root.addChild(topLeft);
Its using the 3D coords, anot allowing me to move it in 2D Space, (IE, I just want to translate everything to another point, using the same camera orientation and view.).
If I modify the topLeft container such as the following:
let topLeft = new PIXI3D.Container3D();
topLeft.x = -3;
topLeft.y = 0;
root.addChild(topLeft);
Maybe a visual example will make sense:
Can I go from this
To this:
Using a perspective camera, and just moving around a parent container.
Beta Was this translation helpful? Give feedback.
All reactions