Confused with Mesh and Texture Angles

Blitz3D Forums/Blitz3D Programming/Confused with Mesh and Texture Angles

_PJ_(Posted 2010) [#1]
I think I've made things worse by fiddling about, but in short, I'm working on a way to have a planet rotate so that two textures, one for the light-side, another for the 'dark-side' are updated to reflect the planet's rotation with respect to the sun.

Part of the problem, is that the textures need to be aligned correctly, the second aprt of the problem is that the two halves of the planet are formed from a single bit of code.
This CreateHemisphere function basically creates a sphere, then removes half the verts leavig the hemisphere.
This is all well and good for the purpose, but, first I had to add in the U,V,W corords for the mesh so that textures could be applied.

Doing this, though, meant that the two hemispheres both have the same UV mapping as their original sphere meshes (albeit cut in half), so where as the sphere vertex creation begins, say, at the north pole, I would be left with two North hemispheres.

"Just rotate one texture 90 degrees" I thought might solve the problem, but it didn't (at least, not how I tried it) and neither did inverting one hemisphere.

The problem is compunded ecause I need to re-orient the hemispheres anyway in order to have the planet the 'right way up', as well as having the hemispheres congruent to make a sphere.

In making these necessary changes, I've made it considerably more difficult to figure out what to do with the UV coords of the textures.

Sorry, this is really difficult to describe.

The majority of the code is below, of which a lot is also pretty irrelevant. It's mainly just the CreateHemisphere, BuildPlanet and UpdateMeridian funcitons which are relevant.

I hope that somebody is able to identify possible solutions, and I do apologise for the mess :)




jfk EO-11110(Posted 2010) [#2]
As far as I see, your Hemisphere function is useing this line:
If VertexY( OldSurface,OldVertex ) < 0
to add only the vertices on the south side of the sphere. You could add a parameter to the function call:
CreateHemisphere(Segments=32,Parent=False,north=0)

and then add an alternative part in the function:
...
if north=0 then
		If VertexY( OldSurface,OldVertex ) < 0
			VertexCoords OldSurface,OldVertex, VertexX(OldSurface,OldVertex), 0 , VertexZ(OldSurface,OldVertex)
			VertexNormal OldSurface, OldVertex, 0, 0, 0
		EndIf

else
		If VertexY( OldSurface,OldVertex ) >= 0
			VertexCoords OldSurface,OldVertex, VertexX(OldSurface,OldVertex), 0 , VertexZ(OldSurface,OldVertex)
			VertexNormal OldSurface, OldVertex, 0, 0, 0
		EndIf

endif
...

Maybe you also got to tweak the triangle part, with the normals, maybe not, not sure of that.


_PJ_(Posted 2011) [#3]
Okay, thanks for that, jfk that helped me see where the issue was with the fact I'd just made identical hemispheres and mirrored one without considering the relative UVs

Now, though, I'm having trouble with the application of giving the impression the planet is rotating by re-texturing at offset UV coords.

In theory, setting the Clamp UV flags on Load texture should help, but when I change the values in the LoadTexture lines, from 3 to, say 51 or 19, the texture blending seems to get confused.

Global BUMP_TEXTURE=LoadTexture("F:\bb\Blitz\WIP\Solar System\"+PlanetName$+"\bump.png",51)
TextureBlend BUMP_TEXTURE,BUMP_BLEND

Global SKIN_TEXTURE=LoadTexture("F:\bb\Blitz\WIP\Solar System\"+PlanetName$+"\skin.png",51)
TextureBlend SKIN_TEXTURE,SKIN_BLEND

Global SHADOW_TEXTURE=LoadTexture("F:\bb\Blitz\WIP\Solar System\"+PlanetName$+"\shadow.png",3)
TextureBlend SHADOW_TEXTURE,SHADOW_BLEND

Global CLOUDS_TEXTURE=LoadTexture("F:\bb\Blitz\WIP\Solar System\"+PlanetName$+"\clouds.png",3)
TextureBlend CLOUDS_TEXTURE,CLOUDS_BLEND



jfk EO-11110(Posted 2011) [#4]
Could you use PositionTexture instead?


_PJ_(Posted 2011) [#5]
It is using PositionTexture

	PositionTexture CopyBrushDay,UDay#,VDay#
	PositionTexture CopyBrushNight,UNight#,VNight#



jfk EO-11110(Posted 2011) [#6]
Oops. But it sounds rather strange anyway, that the blending mode is messed up by the flags 48! Does that happen on other machines too? And is it really the blending mode? (what exactly means "texture blending confused"?)


_PJ_(Posted 2011) [#7]
Right, yeah it does seem odd, but on further examination, I think the "problem" is down to my code - there'#s a few things that have gotten confused since I started fiddling with this.

I'm gonna start over with a fresh view on what I'm doing and see how that goes. Thanks for looking, jfk - I'm definitely getting a better understanding of how this works :)


_PJ_(Posted 2011) [#8]
Hrm... now I cant get the textures to show at all.

I'm sure it's something with the UV's and my lack of understanding.

Here's an upload of the runnable code and images used:
http://homepage.ntlworld.com/mickyandlaura/BB/SolarSystem/Test.rar

If anyone can shed any light on what's going on, I'd really appreciate it.

Last edited 2011

Last edited 2011


_PJ_(Posted 2011) [#9]
Okay, I went right back to square one, and looked at the creation of the hemisphere code.

It's at this point that the problem begins. Although there is some colour difference, the details of the texture are not visible.

Graphics3D 640,480,32,7

Global LIGHT = CreateLight()
Global CAMERA = CreateCamera() : PositionEntity CAMERA, 0,0,-5
Global TEST1 = MESHhemisphere(32,0)
Global T1=LoadTexture("C:\WINDOWS\Greenstone.bmp")
EntityTexture TEST1,T1

Global TEST2 = MESHhemisphere(32,1)
Global T2=LoadTexture("C:\WINDOWS\Coffee Bean.bmp")
EntityTexture TEST2,T2

;AddMesh TEST2,TEST


While Not KeyHit(1)
	
	TurnEntity TEST1, 0,0.5,0
	TurnEntity TEST2, 0,0.5,0
	
	RenderWorld()
	Flip
	
Wend

Function MESHhemisphere( Segs = 8 ,Pole=1,Parent=0)
	
	Local tmp, mesh, s, v, t, ns, v0, v1, v2, nv0, nv1, nv2
	
	tmp = CreateSphere( Segs )
	s = GetSurface( tmp, 1 )
	
	If (Pole)
		For v = 0 To CountVertices(s)-1
			If VertexY( s, v ) < 0
				VertexCoords s, v, VertexX(s,v), 0 , VertexZ(s,v)
				VertexNormal s, v, 0, 0, 0
			EndIf
		Next
	Else
		For v= 0 To CountVertices(s)-1
			If VertexY( s, v ) > 0
				VertexCoords s, v, VertexX(s,v), 0 , VertexZ(s,v)
				VertexNormal s, v, 0, 0, 0
			EndIf
		Next
	End If
	mesh = CreateMesh()
	ns = CreateSurface( mesh )
	For t = 0 To CountTriangles( s )-1
		v0 = TriangleVertex( s, t, 0 )
		v1 = TriangleVertex( s, t, 1 )
		v2 = TriangleVertex( s, t, 2 )
		If VertexNY( s,v0 ) <> 0 Or VertexNY( s, v1 ) <> 0 Or VertexNY( s, v2) <> 0
			nv0 = AddVertex( ns, VertexX( s, v0 ), VertexY( s, v0 ) , VertexZ( s, v0 ));,Pole*0.5,0,0)
			nv1 = AddVertex( ns, VertexX( s, v1 ), VertexY( s, v1 ) , VertexZ( s, v1 ));,Pole*0.5,0,0)
			nv2 = AddVertex( ns, VertexX( s, v2 ), VertexY( s, v2 ) , VertexZ( s, v2 ));,Pole*0.5,0,0)
			VertexNormal ns, nv0, VertexNX( s, v0 ) , VertexNY( s, v0 ) , VertexNZ( s, v0 )
			VertexNormal ns, nv1, VertexNX( s, v1 ) , VertexNY( s, v1 ) , VertexNZ( s, v1 )
			VertexNormal ns, nv2, VertexNX( s, v2 ) , VertexNY( s, v2 ) , VertexNZ( s, v2 )
			AddTriangle ns, nv0, nv1, nv2
		EndIf
	Next
	
	FreeEntity tmp
	
	;UpdateNormals mesh
	EntityColor mesh,255,255,255
	
	RotateMesh mesh,90+(180*Pole),0,180*Pole
	
	Return mesh
	
End Function



_PJ_(Posted 2011) [#10]
Anyone???


Ross C(Posted 2011) [#11]
I'll have a look see :)


Ross C(Posted 2011) [#12]
I'm unsure what your trying to do here? Are you trying just to map the UV coords of half of the sphere? If so, I can just create two half spheres and map them for you :)

Another EDIT! Why don't you just copy the UV co-ords from the sphere?

Last edited 2011


Ross C(Posted 2011) [#13]
Ok, I have just copied the U and V co-ords from blitz created sphere. Is this what you need?



I think what might help is if you either: Split the sphere down the pole middle, or copy the texture co-ords from around the middle, rather than the poles. Not entirely sure how to do that though. I really don't mind giving you a sphere, mapped properly though!

Last edited 2011


_PJ_(Posted 2011) [#14]
Thanks, Ross that's grea. Just what I needed!
I waswn't sure how to cotpy the UV with VertexU and VertexV commands, but your code shows that perfectly. Thanks so much!

Ultimately, all I was trying to do was create a planet made from two hemispheres, one for the light-side, the other in shadow.

I should be able to crack on with it now, though, so don't worry about the mapped sphere. Your code above is just what I needed!


Ross C(Posted 2011) [#15]
The only problem you'll have though, is the distorion, which will produce, erm distored images at the poles :) Glad to be of help though.