Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use texture for TeapotGeometry #248

Open
atonamy opened this issue Mar 11, 2016 · 3 comments
Open

Cannot use texture for TeapotGeometry #248

atonamy opened this issue Mar 11, 2016 · 3 comments
Labels

Comments

@atonamy
Copy link

atonamy commented Mar 11, 2016

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())
to
geometry::TeapotGeometry::create(sceneManager->assets()->context())
and a bit scale
cube->component<Transform>()->matrix(cube->component<Transform>()->matrix() * scale(vec3(.15f)));

screen shot 2016-03-11 at 8 32 25 pm

it doesn't work. No texture. Why?

@jpx
Copy link
Member

jpx commented Mar 11, 2016

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.

@atonamy
Copy link
Author

atonamy commented Mar 11, 2016

Thanks, I see.

So how to create UV programmatically? And how to check if loaded model contains UV or not?

@JMLX42
Copy link
Member

JMLX42 commented Mar 13, 2016

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:

  • create a vertex buffer with the corresponding data,
  • make sure it declares the "uv" attribute,
  • add this vertex buffer to your geometry.

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...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants