#new Texture()

1 messages · Page 1 of 1 (latest)

plain sable
#

What would be the easiest way to create a texture of 64x32? Do I really have to pass in all the data? Thank you for the answer in advance!

let texture = new Texture().add(true);```
plain lantern
#

I think the syntax is

  id: "texture",
  width: 64,
  height: 32,
})```
Correct me if I'm wrong, I still need to check this
plain sable
#

Actually, I should create UV template for it as well.

safe fog
#

The important thing when creating a texture is that it is initialized with image data. You can do this via fromFile or fromPath, but if you are creating it from scratch, the best option is fromDataURL:

First, create a HTML canvas, set the size, and draw something on it. Then, get the data URL and use it to create a texture:

let data_url = canvas.toDataURL()
new Texture({name: 'tex'}).fromDataURL(data_url).add()
plain sable
# safe fog The important thing when creating a texture is that it is initialized with image...

I thought that there is a function that specifically generates these textures that I could use in the plugin.

I currently have this code for generating the texture, but it fills it with just red color...

const canvas = document.createElement('canvas');
canvas.width = 64;
canvas.height = 32;

const ctx = canvas.getContext('2d');

ctx.fillStyle = 'red';
ctx.fillRect(0, 0, 64, 32);

// do I really need this?
const dataURL = canvas.toDataURL();
let texture = new Texture({ name: 'cape_texture' }).fromDataURL(dataURL).add(true);
safe fog
#

What is your goal?

plain sable
#

My goal is to create appropriately sized texture and assign it to the model. I would love the texture to have different colors on each face, just as it is when creating a texture from scratch in BB.

plain sable
safe fog
#

So a full on template, but based on the existing UV data?