How do i apply texture to Model(from Blender)?

i want to apply Wrap.repeat to exported Model.

In Blender, I create One Model.

This mode have hierarchy structure like this.

http://i.imgur.com/gNEsj.png

i export this model by Ogre.xml and I import .scene file by JME3.

So, i use ‘loadmodel(this.j3o)’…

[java]

Node object = (Node)assetManager.loadModel(“this.j3o”);

Spatial Body = (Spatial)object.getChild(“body”);

Spatial Head = (Spatial)object.getChild(“head”);

Node Tail = (Node)object.getChild(“tail”);

Spatial ChildTail = (Spatial)object.getChild(“childtail”);

[/java]



Also, i read this post → http://hub.jmonkeyengine.org/groups/import-assets/forum/topic/tile-texture-on-spatial

In this post, they give me some guideline, so i use this code…

[java]

protected void setTextureOfObject(Spatial spatial, String str_Texture, Vector2f vec_TextureScale)

{

Texture tex = assetManager.loadTexture(new TextureKey(str_Texture,false));

tex.setWrap(Texture.WrapMode.Repeat);

Material mat_temp = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat_temp.setTexture(“ColorMap”, tex);

setTextureScale(spatial, new Vector2f(2, 2));

spatial.setMaterial(mat_temp);

}

public void setTextureScale(Spatial spatial, Vector2f vector) {

if (spatial instanceof Node) {

Node findingnode = (Node) spatial;

for (int i = 0; i < findingnode.getQuantity(); i++) {

Spatial child = findingnode.getChild(i);

setTextureScale(child, vector);

}

}else if (spatial instanceof Geometry) {

((Geometry) spatial).getMesh().scaleTextureCoordinates(vector); // Exception Error!!!

}

}

[/java]

i type like this :: setTextureScale(ChildTail, new Vector2f(4,4));

When i use this code … ((Geometry) spatial).getMesh().scaleTextureCoordinates(vector); this create exception error ,

Please, give me advise.

Oh boy! Show the error xD!

@glaucomardano said:
Oh boy! Show the error xD!

I can`t understand what you mean.. ^^
@jjwsd said:
When i use this code ....... ((Geometry) spatial).getMesh().scaleTextureCoordinates(vector); this create exception error ,,,
Please, give me advise.


@glaucomardano said:
Oh boy! Show the error xD!






yes This make an error…

Then How i can apply Wrap.repeat…;;;;

i can`t find any other solution…

I meant we can’t help you without knowing the error that’s causing that. Understand now?

Im sorry ^^...... i m stupid. Sorry. You mean my Error ? or Source Code?

Here is Source Code ^^

http://i.imgur.com/9J37C.png

You mean my Error ? or Source Code?
Here is Source Code


Is this a joke xD? This is not the source code, this is the stack trace xD. This is what I was asking to you. The error is clear, it says your mesh doesn't have any texture coordinates. Are you sure all your geometries have any textured material?

Oh… I`m sorry… typographical error…

@glaucomardano said:
Are you sure all your geometries have any textured material?

The geometries is just one plane.. it just have one material. this can be a problem?
Actually i can`t understand what you say ...

As you said earlier that your model have a head and a tail I thought you had several geometries. But how it’s a plane, does it have any texture at least? Otherwise you’ll have to create the texture coordinates yourself by hand programmatically xD.

@qlaucomardano

When you create some model in Blender… than export and import the model in JME3.

you also create the texture coordinates yourself as your imported model???

No. I wonder why I should create the texture coordinates by hand when the engine does it easily by me xD. When I import my textured models in jME, they already come with their texture coordinates set.

@glaucomardano said:

No. I wonder why I should create the texture coordinates by hand when the engine does it easily by me xD. When I import my textured models in jME, they already come with their texture coordinates set.


i`m really really confused....

i think! → i make one Cube in Blender which have one material, not texture.

then i export this model by Ogre.xml .

And i import this model by JME3 then, Ogre.xml file transform to .j3o file. Right?

i use Eclipse. So i import this .j3o file and cover texture to imported model.

is There anything what i miss??? …

I meant that texture wrapping just work for models with any texture coordinate set. Then if you imported your non textured model into jME, it means it has no texture coordinates at all. So I said that I prefer to import my models with its texture coordinates already set (uv wrapped model) into jME, so I don’t need to do create them by hand or programmatically or the hardest way xD.

@qlaucomardano

Yes, I can catch what you mean ^^ .

I know that method is possible. But… The texture wrapping should be changed by user`s input in Runtime…

@glaucomardano said:
So I said that I prefer to import my models with its texture coordinates already set (uv wrapped model) into jME, so I don't need to do create them *by hand* or *programmatically* or *the hardest way* xD.

if Only 'uv mapping image' should be changed in Runtime, we should create its texture coordinates by programmatically? Right?

Only if the model has no texture coordinates. If you’ve exported your model from blender with textures, it means it already has texture coordinates set, then you don’t need to create it by hand in jME. Otherwise, it hasn’t. Creating texture by hand is a pain.

Thank you ^^ i can handle this thing…

i just wonder how do i change uv image to Model.

Thank you !

http://cgcookie.com/blender/2011/09/14/tip-using-multiple-uv-coordinates/

@qlaucomardano

Thank you ^^

i can handle this problem by yours favor ^^