Tanuky

Add Texture to babylon sample project

Recommended Posts

How can I add a Texture to the following sample

https://www.babylonjs-playground.com/#4GBWI5

I tried the following code:

		mat = new BABYLON.StandardMaterial("", scene);
		mat.diffuseTexture = new BABYLON.Texture("textures/texture.jpg", scene);
	//	mat.diffuseColor = new BABYLON.Color3(1, 1, 1);
			//mat.diffuseTexture.hasAlpha = true;
			build.material = mat;

I get the following error:

.WebGL-0x7f8fa201c400]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1

Share this post


Link to post
Share on other sites

Your model does not have UVs and UVs are mandatory when you rely on textures: https://en.wikipedia.org/wiki/UV_mapping

You should create them when you create the positions:

https://www.babylonjs-playground.com/#4GBWI5#183

This is just an example, they should be created in a meaningful way. I just try to highlight the need of UVs here.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.