How to display a picture(.png) on one surface of a cube?


#1

i have a model with three Material slot,
index 0 is green
index 1 is white
index 2 is a surface with a picture ( i need modify the picture dynamic!)


#2

First, you need to describe the texture using UV coordinates, then, you need to maintain the texture that is being expressed via those UV coordinates. I am assuming your picture is changing. So if that is the case, you need to update the texture object.


#3

Use :
YourModel->SetMaterial(0 , greenMaterial);
YourModel->SetMaterial(1 , whiteMaterial);
YourModel->SetMaterial(2 , pngPictureMaterial);

Normally your model must have 3 geometries and must have texture coords.
For creating the above mentioned materials see the Urho examples or just copy one of the materials that comes with urho and change it to your needs.
(Or use CoreData/DefaultGrey.xml and change it to white and greenetc)

i need modify the picture dynamic!

How much dynamic ? if it is just few frames , load them all and change the textures using a timer , but if it is a avi file or other video then it is another story. Serach the forum there are couple video players floating around.


#4

Welcome to the forums! :confetti_ball: :slightly_smiling_face:

This thread may help you in the right direction to get the texture painting working:


#5

I have already use SetMaterial(index , Material) ,the index 0 and index 1 is normal .but the index 3 need a picture, i export from blender (Blender to Urho3D Guide)
export texture only support uv coordinate, i need use the picture fill the entire surface.

i need like this
https://tse3.mm.bing.net/th?id=OIP.jyUK6KOSDwwkQF6oo2kncQHaEq&pid=Api

my state is this

how to define a xml which use picture(texture) fill the entire surface.

thank you everyone!


#6

One way is to use two cubes, so a smaller picture cube is inside a larger container cube, except one face is slightly outside the container cube.

Then you don’t have to worry about just putting material on just one side.


#7

Just create a file like this :

<material>
    <technique name="Techniques/Diff.xml" />
    <texture unit="diffuse" name="YourPath/YourTexture.png" />
</material>

#8

it is not work!

my code is:
//test load dynamic
boxObject->SetModel(cache->GetResource<Model>(“Models/majhong/mj.mdl”));
boxObject->SetMaterial(1,cache->GetResource<Material>(“Models/majhong/mj_1.xml”));
boxObject->SetMaterial(2,cache->GetResource<Material>(“Models/majhong/mj_2.xml”));
//load face
boxObject->SetMaterial(0,cache->GetResource<Material>(“Models/majhong/mj_0.xml”));
//boxObject->SetMaterial(0,cache->GetResource<Material>(“Materials/Stone.xml”));
//boxObject->SetMaterial(0,cache->GetResource<Material>(“Materials/Skybox.xml”));

the result is :
mj_0.xml


Stone.xml

Skybox.xml

my picture (41.png) is:


#9

mj_0.xml content:

<material>

<technique name = “Techniques/Diff.xml” />

<texture unit = “diffuse” name = “Textures/41.png” />

</material>


#10

how to describe the texture using UV coordinates? please give me a tools!


#11

The second picture shows that you don’t have UV coords defined properly. It’s like a planar map. The easiest way o set UV coords is to edit them in blender.


#12

i think i need a planar mapping ,but i can not find anything in documents

or perhaps a decal is another way!


#13

For the UVs a simple Cube Projection should work. In Blender, select your piece then enter Edit Mode [Tab] and:

  • Select All [A] (or at least the face that needs texturing)
  • UV Mapping [U]
  • Cube Projection [C]

In the UV/Image Editor you can improve the fit by grabbing, rotating and scaling faces or vertices, just like in the 3D View.