Help to put brush mesh.

Community Forums/General Help/Help to put brush mesh.

Yue(Posted 2014) [#1]
Hello, I'm trying to put a brush into a mesh, but is not displayed correctly, the texture of brush is the tire footprint of the robot, I'm doing something wrong and it is not.

Local trail = CreateMesh()
	Local Br% = LoadBrush("Data\Modelos\Neuma.jpg")
	
	Local tsurf = CreateSurface(trail,Br%)
	
	Local trail_length = sections
	AddVertex(tsurf,EntityX#(testp1,True),EntityY#(testp1,True),EntityZ#(testp1,True),1,0)
	AddVertex(tsurf,EntityX#(testp2,True),EntityY#(testp2,True),EntityZ#(testp2,True),0,1)
	AddVertex(tsurf,EntityX#(testp3,True),EntityY#(testp3,True),EntityZ#(testp3,True),1,0)
	For a = 0 To trail_length-1
		AddVertex(tsurf,EntityX#(testp1,True),EntityY#(testp1,True),EntityZ#(testp1,True),1,0)
		AddVertex(tsurf,EntityX#(testp2,True),EntityY#(testp2,True),EntityZ#(testp2,True),0,1)
		AddVertex(tsurf,EntityX#(testp3,True),EntityY#(testp3,True),EntityZ#(testp3,True),1,0)
		AddTriangle(tsurf,0+(a*3),1+(a*3),3+(a*3))
		AddTriangle(tsurf,1+(a*3),4+(a*3),3+(a*3))
		AddTriangle(tsurf,1+(a*3),2+(a*3),4+(a*3))
		AddTriangle(tsurf,2+(a*3),5+(a*3),4+(a*3))
		AddTriangle(tsurf,0+(a*3),3+(a*3),5+(a*3))
		AddTriangle(tsurf,0+(a*3),5+(a*3),2+(a*3))
	Next
	b = CountVertices(tsurf)
	For a = 0 To b
		If a < 6
			If a < 3
				VertexColor(tsurf,a,colr,colg,colb,.1)
			Else
				VertexColor(tsurf,a,colr,colg,colb,.5)
			EndIf
		Else
			VertexColor(tsurf,a,colr,colg,colb,1-Float(a)/Float(b))
		EndIf
	Next
	
	
	
	;EntityFX trail,1+2+4+8+32
	EntityFX trail,2+4+8+32
	Return trail




FBEpyon(Posted 2014) [#2]
I don't see the PaintEntity code anywhere here..?


Yue(Posted 2014) [#3]
Local Br% = LoadBrush("Data\Modelos\Neuma.jpg")
	
	Local tsurf = CreateSurface(trail,Br%)


Apparently the texture is loaded but not displayed as it should be, everything looks black.




FBEpyon(Posted 2014) [#4]
http://www.blitzmax.com/b3ddocs/command.php?name=PaintMesh&ref=3d_cat : PaintMesh

http://www.blitzmax.com/b3ddocs/command.php?name=PaintSurface&ref=3d_cat : PaintSurface

You need to Paint the Mesh

I'm not showing that anywhere in the code, the loadbrush only loads it into memory, but you have to tell it what mesh or surface you want to paint.



If it was me I would two different surfaces the each track and then you can assign the brush to each surface using the paintsurface


Yue(Posted 2014) [#5]
Apparently not work, I put the paint in the place you indicate me but does not work. I keep seeing black where the texture should be. Apparently if this loading and pasting but not displayed correctly.




FBEpyon(Posted 2014) [#6]
The uv coords could be off then, but I'm not really sure.. I know a lot of the time I get black because its not mapping or the texture didn't load correctly, and you should get a null error if the texture doesn't exist.

But at the same time if the coords are off then you would just see bad uvs to the texture.. what happens when you remove the 0,1 coords from the addvertex, and then run it.?

**EDIT**

So when I got home I looked at the code a bit more, and I think you need to work on rendering the trails with out all the EntityFX first with just the 3+4 select.

Then try PaintEntity instead of the paint mesh I suggested.. Something isn't rendering correctly, and it might be the disable fog or force alphablend.

Let me know,

FBEpyon


Floyd(Posted 2014) [#7]
The AddTriangle code does not make sense to me.

Try replacing the AddVertex/AddTriangle code with this ( just three vertices and one triangle ). Can you see anything?
	AddVertex(tsurf,EntityX#(testp1,True),EntityY#(testp1,True),EntityZ#(testp1,True) ,1,0)
	AddVertex(tsurf,EntityX#(testp2,True),EntityY#(testp2,True),EntityZ#(testp2,True) ,0,1)
	AddVertex(tsurf,EntityX#(testp3,True),EntityY#(testp3,True),EntityZ#(testp3,True) ,1,0)

	AddTriangle(tsurf,0,1,2)



FBEpyon(Posted 2014) [#8]
Yeh I was looking at that as well.. I can't figure it out as well.. I usally defined my with local variables, and then get rid of them.


Yue(Posted 2014) [#9]
Hi, here code:
http://blitzbasic.com/codearcs/codearcs.php?code=2511


FBEpyon(Posted 2014) [#10]
Okay so that code is not using any types of textures, so you need to make sure that your are rendering the mesh correctly check all your triangles, go into wireframe mode.

Trying to add a brush to this might take a little more work than what you are trying to do, I don't show the texture coords are setup for texturing.

Remove the U,Vs coords from the Addvertex.. then try it


RemiD(Posted 2014) [#11]
Some ideas :
If the surface is in a separate mesh you can use entitytexture to apply the texture but if the surface is in the same mesh but in a different surface, you want to use paintsurface to apply the texture
or
Wrong UV coords for some vertices
or
A not appropriate TextureBlend or EntityBlend or BrushBlend


Yue(Posted 2014) [#12]
I have to say with certainty that I have no idea what I'm doing, I do not understand starting the uv coordinates, the original code does not bring, I think I'll leave it in a coffee color, unless someone helps me.


Brucey(Posted 2014) [#13]
If I were you, I would work on something else and come back to it later. No point wasting time here when you could be doing better things ;-)


Yue(Posted 2014) [#14]
I think I'd leave ... but the goal is not to make a video game, the goal in the foreground is trying to learn how things work, however could start and stop after a while.


FBEpyon(Posted 2014) [#15]
Yue:

I looked at the code over and over again, and I'm certain it has to do with the original way the first code was written, it looks like you are having problems with blends.



The above code is basically taking the surface and applying color and alpha blends to each vertex. If you remove that all together you would have a solid white model if the textures are not applying.

Once you have this you will want to figure out how to apply the UVs to the model, they are based on the 0.0 to 1.0 coords on a texture so if you have a 128x128 and you only want to render 64x64 of the texture (texture atlas) you would then take 64/128 which would give you 0.5 on the x or y. I had a hard time when I first started learning how the UVs work. What I did to help with that is work with a cube with 6 separate quads (meshes/surfaces), and then I worked out the UVs of a 256x256 texture atlas until I found the correct locations.

::Suggested Code::



Let me know,

FBEpyon


Yue(Posted 2014) [#16]
Hi, ultimately the problem is with the UV mesh, the code of vettices is for the footprint desvanceza after a while and this is what I have on screen, but do not understand very well the UV.






Local Brush% = LoadBrush("Data\Modelos\Rueda.png"); Load Brush.
	Local tsurf = CreateSurface(trail,Brush%); Surface applied with brush.
	
	Local trail_length = sections
	AddVertex(tsurf,EntityX#(testp1,True),EntityY#(testp1,True),EntityZ#(testp1,True),0,0) ; Here UV
	AddVertex(tsurf,EntityX#(testp2,True),EntityY#(testp2,True),EntityZ#(testp2,True),1,0) ; Here UV
	AddVertex(tsurf,EntityX#(testp3,True),EntityY#(testp3,True),EntityZ#(testp3,True),0,1) ; Here UV
	For a = 0 To trail_length-1
		AddVertex(tsurf,EntityX#(testp1,True),EntityY#(testp1,True),EntityZ#(testp1,True),0,0) ; Here UV
		AddVertex(tsurf,EntityX#(testp2,True),EntityY#(testp2,True),EntityZ#(testp2,True),1,0) ; Here UV
		AddVertex(tsurf,EntityX#(testp3,True),EntityY#(testp3,True),EntityZ#(testp3,True),0,1) ; Here UV
		AddTriangle(tsurf,0+(a*3),1+(a*3),3+(a*3))
		AddTriangle(tsurf,1+(a*3),4+(a*3),3+(a*3))
		AddTriangle(tsurf,1+(a*3),2+(a*3),4+(a*3))
		AddTriangle(tsurf,2+(a*3),5+(a*3),4+(a*3))
		AddTriangle(tsurf,0+(a*3),3+(a*3),5+(a*3))
		AddTriangle(tsurf,0+(a*3),5+(a*3),2+(a*3))
	Next


Edit:
No EntityFX
;EntityFX trail,1+2+4+8+32




FBEpyon(Posted 2014) [#17]
Well its look good now..

Now I get to do that same thing for my road system..

UVs basically work like percentages, so you are saying that you are @ 0% at either x or y, and the you are wrapping to 100% at x or y.

So if you have a triangle you would have 3 vertexes and you want to places the texture at the center top most point of the triangle you would do 0.5 and 0.5 for the top. If this is not a right angle triangle btw. Then you would do the bottom most left corner at 0.0, 0.0, then you would do right most corner at 1.0, 0.0..

So basically you have 50% of the texture on the top for x and y, then you have 0% of the texture on bottom left, and then 100% on the x, and 0 % on the y for the bottom right corner.

Now I could be thinking about this upside down, but I hope this helps understand it a bit...


Yue(Posted 2014) [#18]
I put the following:



	AddVertex(tsurf,EntityX#(testp1,True),EntityY#(testp1,True),EntityZ#(testp1,True),0,0)
	AddVertex(tsurf,EntityX#(testp2,True),EntityY#(testp2,True),EntityZ#(testp2,True),5,0)
	AddVertex(tsurf,EntityX#(testp3,True),EntityY#(testp3,True),EntityZ#(testp3,True),0,1)
	For a = 0 To trail_length-1
		AddVertex(tsurf,EntityX#(testp1,True),EntityY#(testp1,True),EntityZ#(testp1,True),0,0)
		AddVertex(tsurf,EntityX#(testp2,True),EntityY#(testp2,True),EntityZ#(testp2,True),5,0)
		AddVertex(tsurf,EntityX#(testp3,True),EntityY#(testp3,True),EntityZ#(testp3,True),0,5





How do I get to make them turn brands according to the angle of the tire?


FBEpyon(Posted 2014) [#19]
You will need to use Angles so you would neeed to figure out the that with Sin and Cos


RemiD(Posted 2014) [#20]

How do I get to make them turn brands according to the angle of the tire?


Rotate the texture in your image editing program
or
modify the vertices UV coords

For tires tracks made with meshes, normally the texture should not rotate, because once the UV coords are set properly, the newly created vertices will "modify" the orientation of the track.