Models with multiple textures

170 views
Skip to first unread message

terkhen

unread,
Oct 27, 2011, 5:59:57 AM10/27/11
to PhiloGL
I'm interested on defining a model that uses different textures.
Sadly, the description of the "texCoords" option of the O3D
constructor is not complete at the API documentation (it seems cut in
half). What is the correct syntax for the "textures" and "texCoords"
option for defining multiple textures and using them in a given model?

Thanks in advance.

Nicolas Garcia Belmonte

unread,
Oct 27, 2011, 5:20:00 PM10/27/11
to phi...@googlegroups.com
Hi,

Thanks for the heads up, I just fixed it in the master branch.

If you were to define a model with multiple textures these can all be
attached to the same texCoords or you can also have different
texCoords for each texture.

In the first case you would just have something like:

new O3D.Model({
textures: ['textureName1', 'textureName2'],
texCoords: [float, float, float, float, ....]
});

In the second case you would have something like:

new O3D.Model({
textures: ['textureName1', 'textureName2'],
texCoords: {
'textureName1': [float, float, float, float, ....],
'textureName2': [float, float, float, ...]
}
});

You'll have to write your own custom shaders to use more than one
texture per object though, it should be easy though. You can just base
them of the default shaders here:

https://github.com/philogb/philogl/blob/master/src/shaders.js#L14

The only difference is that you can add a new texCoord:

attribute vec2 texCoord2;

and a new sampler:

uniform sampler2D sampler2;

that will correspond to textureName2.

Please let me know if you have any other questions :)

Nicolas.

--
Nicolas Garcia Belmonte - http://philogb.github.com/

terkhen

unread,
Oct 28, 2011, 5:37:20 AM10/28/11
to PhiloGL
Thanksyou for your answer. I'm sorry, but I think that I did not
explain what I wanted to do clearly. I have a single model, and
different parts of it use different textures. Therefore, I need a way
to specify which texture to use for each vertex (none, texture1,
texture2, ...) and the texture coords to use for each case. Is it
possible to do this?

The model I want to display is a sketch up model converted to ply and
then converted to the format used by the PhiloGL.O3D.Model
constructor. I need a way to construct a model that uses different
texture files for each part of the model, and after that draw the
model correctly.

Nicolas Garcia Belmonte

unread,
Oct 28, 2011, 12:11:47 PM10/28/11
to phi...@googlegroups.com
Hi There,

I actually currently working on this, but unfortunately this is not
supported by the framework yet.

Three.js has good support for this though:

http://github.com/mrdoob/three.js

You can find a spec for the model to be used with the framework to
load more complex models:

https://github.com/mrdoob/three.js/wiki/JSON-Model-format-2.0

I hope this helps, and sorry about that!

--

Reply all
Reply to author
Forward
0 new messages