Archive 17/01/2023.

Setting Texturemap of Custom Geometry?

ppsychrite

From the Dynamic Geometry Sample at when it makes the 3d triangle it only uses Normal Coordinates and Vertex Coordinates.

What I want to do is make a custom object that can set a texturemap so that wrap around some polys.
(Like this for example: http://i103.photobucket.com/albums/m143/WarKirby/fig1-1.jpg)
Is Urho3d’s custom geometry able to do this?

cadaver

The CustomGeometry component itself can only define single 2-dimensional UV’s, by using DefineTexCoord() function for each vertex.

If you define vertex / index buffers yourself, like the dynamic geometry example “from scratch” part does, you could define your vertex declaration just like you want, for example using multiple UV’s, 3D UV’s etc.

ppsychrite

Thank you! After looking into it, I think the custom geometry class is what I’ll need :grinning:

slapin

I wonder if anybody have the example on what are possibilities with vertex/index buffer.
This topic is not quite documented. I guessed some things around, looked-up some things in AssetImporter,
but that all doesn’t make single picture. What I’m mostly interested in is relation between
Model, Geometry and Vertex/Index buffer. Some combinations do not work, i.e. one can’t have lod vertex buffer separate. There are many such examples. Because of that procedural generation of assets is very painful thing,
as it does have too much of trial and error. There are people who understand this stuff, but they are silent.

For example, I try to split Model in 2 using some criteria, this looks like insane task, as I don’t know too many things,
like how bone transforms are represented, how morphs are represented, the limitations (4 boneindices per vertex), etc.
Another thing is generating model with LODs - what are relations of LOD geometries with normal geometries,
can I have LODs in separate IBs or they should be the same, etc.
So as I see somebody written all this cool stuff and forgot all about it and now somebody else need to guess it all out,
like archaeologists guessed Egypt hieroglyphs before Rosetta stone was found. But there is no Rosetta stone for this case.

ppsychrite

If I get something working with CustomGeometry I’ll get back to you. :wink:

ppsychrite

What’s the correct way of doing it?
(EDIT) It turns out I defined it counter clockwise so it appeared the wrong way. My bad. :stuck_out_tongue:

ppsychrite

After a while I found a good way to do it.
Only problem is the fact that the color is gray for some reason and when you move your camera above it it turns black. :confused:

node = scene_->CreateChild("Triangle");

ur::CustomGeometry *geometry = node->CreateComponent<ur::CustomGeometry>();
geometry->BeginGeometry(0, ur::TRIANGLE_LIST);

geometry->DefineVertex({ 0,0,0 });
geometry->DefineTexCoord({ 1,0 });
geometry->DefineColor({ 255,0,0 });

geometry->DefineVertex({ 10,0,0 });
geometry->DefineTexCoord({ 0,1 });
geometry->DefineColor({ 255,0,0 });

geometry->DefineVertex({ 10,10,0 });
geometry->DefineTexCoord({ 0,0 });
geometry->DefineColor({ 255,0,0 });

geometry->Commit();

After I did that, voila! It loads! http://prntscr.com/fckn0w
Don’t know how to fix the colors though

Modanung

Might be a normals issue. Try DefineNormal.

When using vertex colours, the geometry should have a VCol technique applied to it for the colours to show up.

ppsychrite

What Vector3 value should the Normals be?
Because right now I do
geometry->DefineNormal({0,0,0});
It sets the triangle to black no matter what color I set the vertex to

Modanung

Basically anything but all-zero. :wink:
It should preferably be a normalized vector (hence the name), which means it should have a length of 1. In most cases you’ll want it to be perpendicular to the surface, pointing out. In the DynamicGeometry sample the normals are calculated after the vertex position data is collected.

ppsychrite

Is there a way of getting the normalized vector?
Setting it to ({1,1,1}) for time’s sake doesn’t seem to work either.

Modanung

You can call Normalize or Normalized on a Vector3.

ppsychrite

Even with that it’s still a black triangle. :neutral_face:

node = scene_->CreateChild("Triangle");

ur::CustomGeometry *geometry = node->CreateComponent<ur::CustomGeometry>();
geometry->BeginGeometry(0, ur::TRIANGLE_LIST);

geometry->DefineVertex({ 0,10,0 });
geometry->DefineNormal(GetNormal({ 0,10,0 }));
geometry->DefineColor(ur::Color::GREEN);

geometry->DefineVertex({ 10,0,0 });
geometry->DefineNormal(GetNormal({ 10,0,0 }));
geometry->DefineColor(ur::Color::RED);


geometry->DefineVertex({ 0,0,0 });
geometry->DefineNormal(GetNormal({ 0,0,0 }));
geometry->DefineColor(ur::Color::BLUE);

geometry->Commit();

Function I’m using:

ur::Vector3 GetNormal(ur::Vector3 vector){
ur::Vector3 normal = vector;
normal.Normalize();
return normal;

}
Modanung

Since your triangle is defined within the XY-plane the normal should either be 0,0,1 or 0,0,-1.

ppsychrite

Neither of those vector3s show the color either but if it helps, 0,0,1 makes the vertex black and 0,0,-1 makes the vertex grey.

Modanung

Like I said, for the vertex colours to show you’ll need to assign a material that uses a VCol technique.

ppsychrite

Ah I didn’t know what you mean’t at first.
Assigned material VColUnlit.xml and it worked perfectly!
Thanks man

Modanung

You’re welcome! :slight_smile:

ppsychrite

Also, sorry for changing the subject but I didn’t think it would be a good idea to post tons of threads onto a subforum.

Lighting doesn’t seem to work with it.
Here’s a few rectangles I’ve drawn: http://prntscr.com/fdiheu
There is lighting been shown at them but no shadows show and the edges aren’t visible.
Incase it was just a lighting glitch I also tried red lighting: http://prntscr.com/fdiins
That doesn’t work either.
The normals are calculated correctly, too, I believe so I don’t know the issue

lezak

It’s because You’re using unlit material. I don’t think that there is build in lit material with vertex colors, You have to create new one using one of the VCol techniques

ppsychrite

Oh yeah I’m using VColUnlit.
How would I go around to making VColLit?

lezak

There already are several techniques with VCol in folder “CoreData/Techniques”, just pick one and make new material using this technique.

ppsychrite

One of them worked, thank you.
While there’s some issue where LIGHT_DIRECTIONAL isn’t affecting it but LIGHT_SPOT is, I think I can find a way to fix it.