UVMap on Cube or Sphere geometry?

Is it possible to use a UVMap on geometry created like this:





[java]Box boxshape1 = new Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f);

Geometry cube = new Geometry("My Textured Box", boxshape1);

Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");

Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg");

mat_stl.setTexture("m_ColorMap", tex_ml);

cube.setMaterial(mat_stl);

rootNode.attachChild(cube);[/java]





Or do you have to make the cube in a 3D modelling program and apply the UVMap there?





Thanks in advance!

iown3ru said:
Or do you have to make the cube in a 3D modelling program and apply the UVMap there?


Yes, you have to apply the uv texture coordinates in a 3D modelling program. For more details follow this thread.

That’s rather unfortunate. I would’ve hoped there’s a more efficient method of applying the texture.

There are default texture coordinates applied to the box, basically, if you apply a texture to a box, the texture will render entirely on each face of the box.



You can create your own mesh with custom texture coordinates by code, but of course, it’s easier with a modeling software.

look at this documentation to know how to create custom meshes

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes

So with your method I would be able to keep my code that creates geometries which then other classes call to set textures?

I’m not sure I understand what you mean, but yes.

If you create you mesh with this method, and properly set the texture coordinates, these textures coordinates will be used to map the texture on the mesh.

For that use the very same code you posted on your first post.

Here’s the code to make blocks



[java]public Block(String name, float x, float y, float z)

{

super(name, new Box(Vector3f.ZERO,1,1,1));//does whatever usually happens when a geometry is made

this.name = name;

this.setLocalTranslation(x,y,z);

/Physics/

blockNode = new Node(name); //new node for physics attachment

blockNode.attachChild(this); //attach block to node

CompoundCollisionShape boxShape = CollisionShapeFactory.createMeshCompoundShape(blockNode); //creates box shaped physics

physicsNode = new PhysicsNode(blockNode, boxShape, 0);

this.physicsNode.setLocalTranslation(x, y, z);

}[/java]



Here’s the code that used by other classes to create blocks



[java]public static Block makeBlock (String name, float x, float y, float z, BlockType type)

{

switch (type)

{

case DIRTBLOCK:

return new DirtBlock(name,x,y,z);

default:

return null;

}

}[/java]



Here’s a Dirt Block class



[java]public class DirtBlock extends Block

{

protected static final Texture dirtBlockTex = (assetManager.loadTexture(“Textures/dirtTexture.jpg”));

protected static final Material dirtBlockMat;

static {dirtBlockMat = new Material(assetManager,“Common/MatDefs/Misc/SimpleTextured.j3md”);

dirtBlockMat.setTexture(“m_ColorMap”, dirtBlockTex);}



public DirtBlock(String name, float x, float y, float z)

{

super(name,x,y,z);

this.material = dirtBlockMat.clone();

this.type=BlockType.DIRTBLOCK;

}



}[/java]





Basically what I’m asking, is if I do these custom meshes, would I be able to keep this code intact? And how would I go about rewriting DirtBlock to make it apply the textures to different sides?



Thanks!

I’m searching for a example where a shader map a texture on a cube … I found “Sky.j3md” and “Reflection.j3md”. I think it should be easy to create a .vert and .frag to map a TextureCubeMap on a Box … I tried Sky but then the Texture is inside … Reflection is a little bit closer but there are additional “reflection” code which I don’t need :slight_smile:



Maybe anybody can give me a little hint to create such a “simple” material …



Regards

Andreas

why not lighting.j3md or unshaded.j3md?

Hmm … I’m searching for a material where I can put 6 different textures on each side of a cube … I got a hint in this forum to use a uv-map etc … but I want try this shader think for that :slight_smile:

sure well… you should look more into the reflection shader because it uses an environment cube map. But IMO it’s a bit overkill to texture a cube.

At some point you’ll want to have lightings, normal mappings, specular etc on this box I guess, so you’ll end up reimplementing what’s already there.

ENVMAP … etc.



ok … what’s the best material for my case?



The reflection material have reflection … of course :wink:

I want this material without the reflection … (later with lightings …) what can I do?

Well…the lighting material would be the one to start with, and maybe modify it to support cube map mapping…

I have to read a shader-tutorial for that :smiley: … we will see

Try the one in our wiki :stuck_out_tongue:

Of course! :smiley: