LightMesh with "created" entities

Blitz3D Forums/Blitz3D Programming/LightMesh with "created" entities

Mousey(Posted 2003) [#1]
I can't get LightMesh to work with a cube (or any entity) that is made using the CreateMesh/Surface etc. commands. Any ideas on what I'm doing wrong? By the way, the function is NOT mine - I found it on the forum somewhere and am just using it here as an example.

Graphics3D 640,480,16,2
camera = CreateCamera()

Function CreateCube6sfc()
	m=CreateMesh()
	sfc=CreateSurface(m)
	AddVertex sfc,-1,1,-1,0,0 : AddVertex sfc,1,1,-1,1,0
	AddVertex sfc,1,-1,-1,1,1 : AddVertex sfc,-1,-1,-1,0,1
	VertexNormal sfc,0,0,0,-1 : VertexNormal sfc,1,0,0,-1
	VertexNormal sfc,2,0,0,-1 : VertexNormal sfc,3,0,0,-1
	AddTriangle sfc,0,1,2 : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,-1,1,-1,0,0 : AddVertex sfc,-1,1,1,1,0
	AddVertex sfc,1,1,1,1,1   : AddVertex sfc,1,1,-1,0,1
	VertexNormal sfc,0,0,1,0 : VertexNormal sfc,1,0,1,0
	VertexNormal sfc,2,0,1,0 : VertexNormal sfc,3,0,1,0
	AddTriangle sfc,0,1,2 : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,-1,1,1,0,0  : AddVertex sfc,-1,-1,1,1,0
	AddVertex sfc,1,-1,1,1,1  : AddVertex sfc,1,1,1,0,1
	VertexNormal sfc,0,0,0,1 : VertexNormal sfc,1,0,0,1
	VertexNormal sfc,2,0,0,1 : VertexNormal sfc,3,0,0,1
	AddTriangle sfc,0,1,2 : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,-1,-1,-1,0,0 : AddVertex sfc,1,-1,-1,1,0
	AddVertex sfc,1,-1,1,1,1   : AddVertex sfc,-1,-1,1,0,1
	VertexNormal sfc,0,0,-1,0 : VertexNormal sfc,1,0,-1,0
	VertexNormal sfc,2,0,-1,0 : VertexNormal sfc,3,0,-1,0
	AddTriangle sfc,0,1,2  : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,-1,1,1,0,0   : AddVertex sfc,-1,1,-1,1,0
	AddVertex sfc,-1,-1,-1,1,1 : AddVertex sfc,-1,-1,1,0,1
	VertexNormal sfc,0,-1,0,0 : VertexNormal sfc,1,-1,0,0
	VertexNormal sfc,2,-1,0,0 : VertexNormal sfc,3,-1,0,0
	AddTriangle sfc,0,1,2  : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,1,1,-1,0,0  : AddVertex sfc,1,1,1,1,0
	AddVertex sfc,1,-1,1,1,1  : AddVertex sfc,1,-1,-1,0,1
	VertexNormal sfc,0,1,0,0 : VertexNormal sfc,1,1,0,0
	VertexNormal sfc,2,1,0,0 : VertexNormal sfc,3,1,0,0
	AddTriangle sfc,0,1,2 : AddTriangle sfc,2,3,0
	UpdateNormals m
	Return m
End Function

mycube = CreateCube6sfc()

EntityFX mycube,2
; light it red - but doesn't work
LightMesh mycube,255,0,0
PositionEntity mycube,0,0,5


While Not KeyDown(1)
TurnEntity mycube,0,1,0
UpdateWorld
RenderWorld
Flip 
Wend
FreeEntity mycube
End


Any help or insight would be much appreciated! Also, an explanation as to how LightMesh actually works (when it does work...) would be great.


Stickman(Posted 2003) [#2]
Try setting the default vertex colors first, somthing like 30,30,30.
Blitz by default sets the vertex colors to there ranges max 255,255,255.
Your also going to have to set the lights position,or move the mesh,as for using MoveEntity() will not work in this situation,An entity and a mesh are not to be mistaken as one of the same.


Mousey(Posted 2003) [#3]
Great stuff! Adding the following code below each of the "VertexNormal" commands makes LightMesh work:

VertexColor sfc,0,30,30,30 : VertexColor sfc,1,30,30,30
VertexColor sfc,2,30,30,30 : VertexColor sfc,3,30,30,30


Thanks for the help Stickman. However, there is one thing that I don't understand:


Your also going to have to set the lights position,or move the mesh,as for using MoveEntity() will not work in this situation,An entity and a mesh are not to be mistaken as one of the same.



I realise that I can set the LightMesh position (and range), but don't get your comment about MoveEntity() not working in this situation. When I use MoveEntity(mycube) in the above listing, it seems to work fine. Am I missing your point? What is the difference between an entity and a mesh in the context of this cube? I understand that, for example, a sprite entity is not a mesh, and also know the difference between the PositionMesh and PositionEntity commands.


John Blackledge(Posted 2003) [#4]
By default I set all my entities to:
EntityColor whatever,128,128,128
- That's the only way I can get them to have a more natural looking light and shade using Light 2 as sunlight.