CopyMesh and AddMesh problems

Blitz3D Forums/Blitz3D Beginners Area/CopyMesh and AddMesh problems

Gillissie(Posted 2006) [#1]
I have found that if you use CopyMesh or AddMesh on a source mesh that has a manually-added texture, the manually added texture doesn't get copied onto the new mesh.

However, if the source mesh was loaded using LoadMesh, and had a texture loaded as part of it, then that texture WILL get copied with CopyMesh and AddMesh.

This is causing problem with creating a dynamic texture for an entity that needs to be added to a mesh.

Graphics3D 1024,768

; Create the required camera and light
Global hCamera = CreateCamera()
Global hLight = CreateLight()
RotateEntity hLight,30,45,0

; Create a cube that will be used as the "master" cube for all other cubes to be copied from.
Global hPrototype = CreateCube()	;LoadMesh("yourtexturedmodel.x")
PositionEntity hPrototype,0,0,3	; put it in the back
hTex = CreateTexture(256,256)
SetBuffer TextureBuffer(hTex)
ClsColor 255,0,0
Cls
Text 0,0,"HERE IS TEXT"
SetBuffer BackBuffer()
EntityTexture hPrototype,hTex
FreeTexture hTex

; Create a mesh that will be assembled with parts.
Global hFullMesh = CreateMesh()
PositionEntity hFullMesh,2,0,0

; Create a new mesh from the prototype mesh.
Global hPart = CopyMesh(hPrototype)
PositionEntity hPart,-2,0,0

AddMesh hPart,hFullMesh


PositionEntity hCamera,0,3,-5
RotateEntity hCamera,30,0,0

Color 255,255,255

While Not KeyHit(1)
	TurnEntity hPrototype,0,.5,0
	TurnEntity hPart,0,.5,0
	TurnEntity hFullMesh,0,.5,0

	UpdateWorld
	RenderWorld

	Text 512,200,"Prototype",True
	Text 128,250,"CopyMesh() from Prototype",True
	Text 900,250,"AddMesh from copied mesh.",True

	Flip

	
Wend

FreeEntity hFullMesh
FreeEntity hPart


End



DJWoodgate(Posted 2006) [#2]
You are texturing the entity instead of the mesh. Use Paintmesh with a brush instead of entitytexture.
From memory something like:
Brush=CreateBrush(): BrushTexture brush,texture: PaintMesh mesh,brush


Gillissie(Posted 2006) [#3]
Holy crap, that worked! Although, it seems like when you copy a mesh that it should copy the textures with it, even if applied at the entity level. After all, CopyMesh IS a "deep" copy.


DJWoodgate(Posted 2006) [#4]
The documentation leaves something to be desired when it comes to clarifying the differences between brushes applied to entities and meshes and how they interact. Although I have a rough understanding, the devil is in the detail. Anway an entity brush can not really be applied to a mesh when it is copied, since there may be many entities for a given mesh and they may all have different brush properties. This two level brush system does give you more flexibility though.


jfk EO-11110(Posted 2006) [#5]
I think that's where CopyEntity makes sense.


Sir Gak(Posted 2006) [#6]
Umm, I thought a mesh IS an entity, at least, one of several kinds of Entity How then does painting/texturing an Entity not work on the Mesh? Like my sig says: "When in doubt, find out"


jfk EO-11110(Posted 2006) [#7]
an entity is more like a generic attribute-hull for a mesh. When you copy the mesh, the hull is ignored.