threeDart / three.dart

Dart port of three.js
http://threedart.github.com/three.dart/
MIT License
387 stars 100 forks source link

Texture repeat: natural dimensions #156

Open dhasenan opened 9 years ago

dhasenan commented 9 years ago

If I have a tiling texture, it's probably a texture I want to tile an appropriate number of times for whatever length of mesh I assign it to. For instance, I want a brick texture that I can tile across various walls. These walls will vary in height and width, but the texture should be applied at the same scale for all of them.

The API allows me to specify that a particular texture should repeat a specific number of times. Using that, I will create a material and a texture, tell it to repeat X times on the X axis, and apply it to wall 1. It works! Then I apply it to wall 2, which is half the length...and now the texture is horribly squished.

So now I have to look at the geometry of the object I'm working with, usually a cube, and create a new texture and new material for each face, calculating the number of times the texture needs to be repeated for each. This is, needless to say, quite vexatious, not to mention inefficient.

It also doesn't mesh (sic) with the naive notion of a material, which is something you should be able to reuse for many different meshes. As is, you can only reuse a material when rendering identical faces of different meshes, faces that are the same size by happy accident. Unless you want horribly distorted textures.

johsin18 commented 9 years ago

Generally, three.dart is a port of three.js to Dart. Would three.js support your use case? I'm not sure we want to diverge from three.js in terms of API, though every improvement is welcome.

Anyway, I support your opinion that materials should be reusable on multiple objects.

DanielJoyce commented 9 years ago

Given that repeats are specified in opengl on a per-texture level, I don't think there is any way around not creating a new texture everytime you want a different repeat.

I guess you could write a custom shader to handle texture repeats perhaps in this manner, so you don't have to bind a texture for every custom repeat.