Jump to content

Mixing in 3D elements


richpixel
 Share

Recommended Posts

I know that Phaser is a 2D engine but I'm wondering if there might be some way to render 3D into a Sprite or DisplayObject?

 

Our game would benefit from having a simple 3D element (a texture mapped wheel). It wouldn't work to do canned spritesheet animations for this case. Are the popular engines threejs and Babylon flexible enough to render into a Bitmap - or some other object that I can use as a texture for a Phaser sprite? Or perhaps some other way? Does Phaser offer a way to do a bitmap fill of a polygon that is drawn with a Graphics object?

 

Thanks

 

Link to comment
Share on other sites

Basically like this:

this.canvas = Phaser.Canvas.create(this.game.width, this.game.height, '', true);this.context = this.canvas.getContext('2d');this.baseTexture = new PIXI.BaseTexture(this.canvas);this.texture = new PIXI.Texture(this.baseTexture);this.textureFrame = new Phaser.Frame(0, 0, 0, this.game.width, this.game.height, 'debug', game.rnd.uuid());this.sprite = this.game.add.sprite(0, 0, this.texture, this.textureFrame);

Now draw whatever you like to the local context. In WebGL mode you'll need to push the updated context to the GPU:

PIXI.updateWebGLTexture(this.baseTexture, this.game.renderer.gl);

The 2nd parameter ought to be the renderSession really, but the above will work if just one render session is in effect.

Link to comment
Share on other sites

  • 3 months later...
  • 4 months later...
  • 1 year later...

I know it's kinda rich of me to say, but I strongly suggest programming the effect yourself. It's a great learning experience if you have the time.

Here's a fantastic basic tutorial for a super fast quasi-3d effect (Even though it's in Scratch, the math applicable anywhere): https://scratch.mit.edu/projects/25977969/

Here's a much more thorough 3d graphics programming tutorial series (using Pseudo-code): http://gamedevelopment.tutsplus.com/tutorials/lets-build-a-3d-graphics-engine-points-vectors-and-basic-concepts--gamedev-8143

And finally, this video series by Computerphile is a fantastic introductory walkthrough on the whole 3d rendering process: 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...