Open atonamy opened 8 years ago
Hello,
The cube appears textured as UV are defined when CubeGeometry
is created.
However, right now, TeapotGeometry
does not provide UV.
https://github.com/aerys/minko/blob/dev/framework/src/minko/geometry/TeapotGeometry.cpp
To have a teapot properly textured you should export a teapot model from your favorite 3D modeling software with UV defined and load it via our assimp
plugin.
Thanks, I see.
So how to create UV programmatically? And how to check if loaded model contains UV or not?
it doesn't work. No texture. Why?
In the example, rendering is done using the Basic.effect
.
As you can see in Basic.fragment.glsl, the diffuse map is sampled only if the VERTEX_UV
macro is defined.
As you can see in Basic.effect, each pass extends the "base-streaming-pass" pass (of the BaseStreamingTemplate.effect
) which extends the "base-pass" of the BaseTemplate.effect which binds the VERTEX_UV
macro to the geometry[${geometryUuid}].uv
data property:
https://github.com/aerys/minko/blob/master/framework/asset/effect/BaseTemplate.effect#L29
So if your geometry does not provide the "uv" data property, then the VERTEX_UV
macro is not defined and the diffuse map is not sampled. This is the right behavior since you can't sample a texture without texture coordinates.
You can learn more about effect pass inheritance here.
You can learn more about data property bindings here.
So how to create UV programmatically?
Look at other *Geometry class implementations. It's very easy:
And how to check if loaded model contains UV or not?
User the Geometry::hasVertexAttribute()
method to check if the corresponding vertex attribute exists. UVs should be declared as the "uv" vertex attribute:
if (geom->hasVertexAttribute("uv"))
{
// geometry has UVs...
}
Here we have example how to load textures https://github.com/aerys/minko/blob/master/tutorial/15-loading-and-using-textures/src/main.cpp
but if we replace
geometry::CubeGeometry::create(sceneManager->assets()->context())
togeometry::TeapotGeometry::create(sceneManager->assets()->context())
and a bit scalecube->component<Transform>()->matrix(cube->component<Transform>()->matrix() * scale(vec3(.15f)));
it doesn't work. No texture. Why?