Jump to content

DynamicTexture with not power of 2 size not covering width/height


Recommended Posts

Hi Everyone,

I'm looking into this

mesh = BABYLON.MeshBuilder.CreatePlane("mesh", {
  width: 10,
  height: 10,
  sideOrientation: BABYLON.Mesh.DOUBLESIDE
}, scene);

mesh.material = new BABYLON.StandardMaterial(null, scene);
texture = new BABYLON.DynamicTexture("texture", {
  width: 10,
  height: 10
}, scene, false, BABYLON.Texture.NEAREST_SAMPLINGMODE);

mesh.material.diffuseTexture = texture;

context = texture.getContext();
context.fillStyle = '#F00';
context.fillRect(0, 0, 100, 100);

context.fillStyle = '#00F';
context.fillRect(0, 0, 15, 5);

// Trying to fix it like ( WIP )

mesh.material.diffuseTexture.uScale = 10 / mesh.material.diffuseTexture._canvas.width;
mesh.material.diffuseTexture.vScale = 10 / mesh.material.diffuseTexture._canvas.height;

On the internal the framework is forcing the texture to be power of 2 which is ok, but my problem is that the new canvas size is 16x16 instead of 10x10 but the way UV are mapped makes that the 10x10 size will only cover a portion of the plane instead of the full width/height. 

Some references on the code.

DynamicTexture constructor








Link to comment
Share on other sites

Hi All , I got a fix

texture.uScale = 10 / texture._canvas.width;
texture.vScale = 10 / texture._canvas.height;
// when drawing with the canvas context the top left corner should be (0,0)        
texture.vOffset = 1 - texture.vScale;

texture.uScale -= 0.001; // fix some texture bleeding
texture.vScale -= 0.001; // fix some texture bleeding


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.

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.


  • Recently Browsing   0 members

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