Making of copy of a entity

Blitz3D Forums/Blitz3D Programming/Making of copy of a entity

Ziltch(Posted 2003) [#1]
Does any one have ideas on how to make a complete copy of a mesh entity?
CopyEntity is more like CloneEntity in that the mesh info is shared.
CopyMesh does not copy info like textures, surface colors, etc.

I wonder if any of the 'hacked Blitz info' could help ;?


poopla(Posted 2003) [#2]
Why not simply rebuild the surface by surface, vert by vert, etc?


Beaker(Posted 2003) [#3]
You could use CopyMesh() and then take a look at all the brush info of the original using the new GetSurfaceBrush() etc commands to re-paint the new mesh.


Ziltch(Posted 2003) [#4]
I have tried copymesh but have not got GetSurfaceBrush() to work yet.

I am doing it copying vert by vert, as copymesh is not predictable. It seems to get confused with cylinders

graphics3d 400,300,0,2

cyl1=createcylinder(5,1)
print " surfaces in cylinder "+countsurfaces(cyl1)
cyl2=copymesh(cyl1)
print " surfaces after copymesh " +countsurfaces(cyl2)


This prints;

surfaces in cylinder 2
surfaces after copymesh 1

If you do the same thing with a loaded mesh it keeps multiple surfaces correctly.

Does anyone have, or think they can write a function to create a exact copy of any type of mesh entity?

I thought this would be easy!!!


Ziltch(Posted 2003) [#5]
This is as close as I have got with creating a true mesh entity copy.

Textures must applied via brushes for them to copy.

Function CopyMeshEntity(mesh,parent=0)

  local surf,scount,count,tricount
  local sbrush,newsurf,crner,vcrner,vert
  
  NewMesh = createmesh(parent)
;  NewMesh = copymesh(mesh)
  if parent = 0 then entityparent NewMesh,getparent(mesh)
  EntBrush=GetEntityBrush(Mesh)
  paintentity NewMesh,EntBrush
  For scount = 1 To  countsurfaces(Mesh)
    surf=GetSurface(Mesh,scount)
    NewBrush=GetSurfaceBrush(surf)
    ;NewSurf = GetSurface(NewMesh,scount); If copymesh is used
    NewSurf = createsurface(NewMesh,NewBrush)

;CopyMesh Replacement
    for count = 0 to counttriangles(surf)-1
      for crner = 0 to 2
        vcrner = TriangleVertex(surf,count,crner)
        vert=addvertex(NewSurf,vertexx(surf,vcrner),vertexy(surf,vcrner),vertexz(surf,vcrner),vertexu(surf,vcrner),vertexv(surf,vcrner))
        vertexcolor NewSurf,vert,vertexred(surf,vcrner),vertexgreen(surf,vcrner),vertexblue(surf,vcrner)
      next
      AddTriangle (NewSurf,vert-2,vert-1,vert)
    next

  freebrush Newbrush
;  if EntBrush>1 then freebrush Entbrush
  next

  return NewMesh
end function


Not perfect but it does what I need for now!


Beaker(Posted 2003) [#6]
Why aren't you freeing EntBrush?


Ziltch(Posted 2003) [#7]
The Entity Brush "EntBrush" contains the same brush handle as the Surface brush "NewBrush".
So Freeing the Entity Brush came up with a error as the Surface brush had already been freed! I do not understand the logic of this !

The handles from many of the new commands do not seem right. Both of these commands are reported to create a new brush, but it does not seem to be the case.