Code archives/3D Graphics - Mesh/Combine Surface Verts
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Can be used to optimise code. Combine meshes for a single-surface system etc, Or transform multi-surfaced entities into single surface ones. | |||||
Function CombineSurfaces(SourceSurface,DestinationSurface) Local Iter Local vX# Local vY# Local vZ# Local vU# Local vV# Local vW# Local vA# Local vR Local vG Local vB Local v Local v0 Local v1 Local v2 Local vCount=CountVertices(DestinationSurface) Local Vert For Iter=1 To CountTriangles(SourceSurface) For Vert=0 To 2 v=TriangleVertex(SourceSurface,Iter,Vert) vX=VertexX(SourceSurface,v) vY=VertexY(SourceSurface,v) vZ=VertexZ(SourceSurface,v) vU=VertexU(SourceSurface,v) vV=VertexV(SourceSurface,v) vW=VertexW(SourceSurface,v) vR=VertexRed(SourceSurface,v) vG=VertexGreen(SourceSurface,v) vB=VertexBlue(SourceSurface,v) vA=VertexAlpha(SourceSurface,v) Select (Vert) Case 1: v1=AddVertex(DestinationSurface,vX,vY,vZ,vU,vV,vW) Case 2: v2=AddVertex(DestinationSurface,vX,vY,vZ,vU,vV,vW) Default: v0=AddVertex(DestinationSurface,vX,vY,vZ,vU,vV,vW) End Select vCount=vCount+1 VertexColor DestinationSurface,vCount,vR,vG,vB,vA Next AddTriangle(DestinationSurface,v0,v1,v2) Next End Function |
Comments
| ||
nice, thanks |
| ||
Really have to try this one! Thanks. |
| ||
I didn't test the code but from what I read, this method will break the shared vertices from your source surface into a "3 vertices per triangle" surface. You might probably want to replace the copy part with something like this : - Local OriginNV% = CountVertices (source) -> to register the first index of the destination - for all vertices from source -> copy vertex from source to destination surface - for all triangles from source -> addtriangle from source to destination adding @originNV to all vertex index Local v0% = TriangleVertex(source, t, 0) + originNV local v1% = TriangleVertex(source, t, 1) + originNV local V2% = TriangleVertex(source, t, 2) + originNV For Iter=1 To CountTriangles(SourceSurface) This is wrong. -> Triangle indices go from "0" to "CountTriangles(SourceSurface)-1" ps : you should probably check the vertices and triangles count before adding the surface (else if you reach blitz3d's limits on surface, the program will crash) |
| ||
Also apparently you have forgotten to get then set the vertices normals... |
| ||
Your function should be deprecated as it duplicates vertices too. To copy a surface you might want to copy the vertices first then add the triangles linking the existing vertices. It will preserve the original vertex count. This is an extended method to copy a surface to another preserving source entity transformation. (or not) |
| ||
Thanks, Bobysait - yes, you're right - I really didn't think this through or test it thoroughly enough. I completely forgot about it but appreciate your points. It's a bit late now, but since I've been really making strides with my knowledge on Meshes and surfaces/vertices then I'll have a crack at this tomorrow (later today... it's past midnight)! |
Code Archives Forum