Jump to content

Canvas as Texture available in Babylon?


arcanine
 Share

Recommended Posts

Hello,

 

I've got a basic incomplete game in threejs but would like to port it to babylon for some of the more game specific functionality

one of the first features is that every item in the game has randomised textures, I'd dynamically draw a canvas then apply it to the mesh

 

Is this possible in Babylon?  If so what classes/methods/documentation do I need to be looking at to achieve this? 

Link to comment
Share on other sites

Hi,

 

Welcome to the forum!

 

The dynamic texture is exactly what you need - 

http://doc.babylonjs.com/page.php?p=24709

http://blogs.msdn.com/b/eternalcoding/archive/2013/08/12/creating-a-3d-chart-for-your-windows-8-1-app-using-babylon-js.aspx

 

The function getContext gives you the canvas to draw on. Just don't forget to update (that's also the name of the function) after making changes to the canvas :-) That was my mistake.

You can also give a canvas element as the "options" variable, it will be set automatically as the texture's canvas.. 

Link to comment
Share on other sites

Yeah, the documentation can be sometimes misleading. But the community is working on it :-)

That's the benefit of open source projects - you can actually see what the variables do. Take a look here - https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Materials/textures/babylon.dynamicTexture.ts

"options" can be either the canvas size (width and height), a canvas object (an object with a getContext function) or a json object with width and height as parameter:

var options = 512; //ORvar options = { width : 512, height: 1024 }; //ORvar options = document.getElementById("canvasId");

So, anything goes, it is all up to you how you use it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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