Texture mapping

Blitz3D Forums/Blitz3D Programming/Texture mapping

Ferret(Posted 2005) [#1]
Hi,

I have 1 mesh and add 15 more meshes to it.
so now i have a mesh with 16 surfaces.

How can i texture this as 1 surface?

Thx


Ross C(Posted 2005) [#2]
You can use the AddMesh command, but you will probably lose the UV co-ords. Unless you copy them across that is.


Ferret(Posted 2005) [#3]
Thx, but this does not answer the question.

I allready added 15 meshes to the first one, but when i aply a texture it seems to tile. I want 1 texture to stretch over all 16 surfaces.


Ross C(Posted 2005) [#4]
Try using the scaletexture commands to stretch it out. It's tiling because the UV co-ords aren't correct. Try either:

Add the meshes together, either in blitz then save it out again, or, add the meshes together in a 3d modelling program, then adjust the UV co-ords outside of blitz.

Or, using scaletexture command to stretch the texture.

:)


Ferret(Posted 2005) [#5]
Ill try to explain it more,

I want to avoid using third party tools, the output should not require any further editing.

Here is a screen:
REMOVED

What you see is made out of 16 meshes/tiles.
I take the first mesh and add the other meshes to it.
So i end up with 1 mesh with 16 surfaces, right??
Now i can manipulate it as one mesh.
Then i load a texture and scale it so that it should stretch and aply it.

As you can see in the screen, the texure starts again on each surface.
The texture scale is ok because you only see a portion on a tile, i just starts again on the next tile.

I must be doing something wrong, but what?


Ross C(Posted 2005) [#6]
If you have used addmesh then you will end up with one surface. You'll need to manually set the UV co-ords then. You can't do much about that really exept adjusting the UV's.

Have you tried using scaletexture?


Ferret(Posted 2005) [#7]
I used the AppMesh() function from the archives, thats why i end up with 16 surfaces.
The texture is 512x512 and i scaled it to that using scaltexture, it works fine on blitz terrains.

I want to edit and export it as 1 mesh but want to have tiles for culling.
If i make it 1 surface, can i still hide tiles out of view?


Dreamora(Posted 2005) [#8]
no


Ferret(Posted 2005) [#9]
I started over from scratch and got what i want exept the texture is not showing up.

Here is what i have so far:
;;Terrain tester ;; Ferret 2005 ;;

Graphics3D 800,600,0,2
SetBuffer BackBuffer()


Global camera = CreateCamera()
CameraRange camera,1.0,10000
MoveEntity camera,1000,1000,1000

Global Camera_VelX# = 0
Global Camera_Velz# = 0
Global camera_velocity# = 1.1
Global camera_speed# = 1
Global Camera_Pitch# = 0
Global Camera_Yaw# = 0

Global WireCheck = False

Global MiTile = F_CreateTerrain()
ScaleEntity mitile,10,10,10
tex = LoadTexture("Map/color.png")
ScaleTexture tex,512,512
EntityTexture Mitile,tex
PointEntity camera,MiTile


While Not KeyHit(1)

	If KeyHit(57)
		WireFrame True	
	EndIf
		
	UpdateGhostCam()
	
	UpdateWorld()
	
	RenderWorld()
	
	Text 10,10,"Space=Wireframe"
	
	Text 10,50,"X: "+EntityX(camera)+"    Y: "+EntityY(camera)+"    Z:"+EntityZ(camera)
		
	Flip

Wend

End

Function F_CreateQuad(FQ_Size#)
	;FQ_Size = FQ_Size +0.1

	F_Mesh = CreateMesh()
		F_Surf = CreateSurface(F_Mesh)
			F_V1 = AddVertex ( F_Surf,0,0,0 )
			F_V2 = AddVertex ( F_Surf,FQ_Size,0,0 )
			F_V3 = AddVertex ( F_Surf,0,0,FQ_Size )
			F_V4 = AddVertex ( F_Surf,FQ_Size,0,FQ_Size )
				F_Tri1 = AddTriangle (F_Surf,F_V1,F_V2,F_V3)
				F_Tri2 = AddTriangle (F_Surf,F_V2,F_V4,F_V3)	
	FlipMesh(F_Mesh)			
	Return(F_Mesh)

End Function

Function F_CreateTerrain(FT_Detail%=64,FT_Size%=1024)
	
	F_Tile = CreateMesh()
		F_XCount = 1
		F_ZCount = 0
		For F_Count = 1 To FT_Detail
			F_Quad = F_CreateQuad(Sqr#(FT_Size)*4)					
			PositionEntity F_Quad,(Sqr#(FT_Size)*4) * (F_XCount-1) ,0,(Sqr#(FT_Size)*4) * (F_ZCount)
							
			F_XCount = F_XCount + 1					
					
			If F_XCount > Sqr#(FT_Detail)
				F_XCount = 1
				F_ZCount = F_ZCount + 1
			EndIf	
									
			EntityParent F_Quad,F_Tile	
			AddMesh F_Quad,F_Tile
		Next	
			
	Return(F_Tile)

End Function





Function UpdateGhostCam()

	Mouse_X_Speed#=MouseXSpeed()*0.5
	Mouse_Y_Speed#=MouseYSpeed()*0.5

	MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
	Camera_Pitch=Camera_Pitch+Mouse_Y_Speed#
	Camera_Yaw=Camera_Yaw+Mouse_X_Speed#


	RotateEntity camera,Camera_Pitch,-Camera_Yaw,0

	If KeyDown(203) Then 
		Camera_VelX=Camera_VelX-camera_speed#
	ElseIf  KeyDown(205)
		Camera_VelX=Camera_VelX+camera_speed#
	EndIf 
	If KeyDown(208) Then 
		Camera_VelZ=Camera_VelZ-camera_speed#
	ElseIf  KeyDown(200)
		Camera_VelZ=Camera_VelZ+camera_speed#
	EndIf
	
	Camera_VelX=Camera_VelX/camera_velocity#
	Camera_VelZ=Camera_VelZ/camera_velocity#
	MoveEntity camera,Camera_VelX,0,Camera_VelZ

	If KeyDown(200) Then
		MoveEntity camera,0,0,camera_speed#
	EndIf

	If KeyDown(208) Then
		MoveEntity camera,0,0,-camera_speed#
	EndIf

	If KeyDown(205) Then
		MoveEntity camera,camera_speed#,0,0
	EndIf

	If KeyDown(203) Then
		MoveEntity camera,-camera_speed#,0,0
	EndIf
	
End Function




Ferret(Posted 2005) [#10]
Grmbl, how do i get the posted code in a codebox??


RGR(Posted 2005) [#11]
Home ... FAQ ... What are the forum codes?

http://www.blitzbasic.com/faq/faq_entry.php?id=2

What is EntityParent F_Quad,F_Tile for?
If you do AddMesh F_Quad,F_Tile in the next line

And the result of Sqr# seems not to be what you expect ...
If you rem the Line EntityParent (see above out) you see lots of tiles overlaying the others...


Ferret(Posted 2005) [#12]
It looks like another big quad is under the terrain, it is the only thing that scales and gets textured.
How do i get rid of it?


RGR(Posted 2005) [#13]
This is the entity you scaleentity mitile,10,10,10
You are not returning what you expect - and thats why its untextured
If you delete Scaletexture tex,512,512 then you see your texture on the big square.
I'd say - your concept of doing the whole thing is wrong. I would not glue meshes together but adding surfaces to that created Mesh. And texture them with Brushes (PaintSurface Surf,brush)


Ross C(Posted 2005) [#14]
If your using function (not related to your problem), use Global variables in the main code :o)


Clyde(Posted 2005) [#15]
Just a suggestion. Would Update Normals not be needed for the texture prob?