Code archives/3D Graphics - Mesh/.ASC Mesh Exporter

This code has been declared by its author to be Public Domain code.

Download source code

.ASC Mesh Exporter by Bug Face2004
Extends Chroma's example code to work for Meshes with multiple surfaces. Needs more work doing to it really, but small steps!
Function export_asc(mesh,file$)
	check=CountSurfaces(mesh) 
	If check=0 Then Return 
	
	totalVertices=0
	totalPolygons=0
	
	For surface=1 To CountSurfaces(mesh)
		surf=GetSurface(mesh,surface)
		totalVertices=totalVertices+CountVertices(surf)
		totalPolygons=totalPolygons+CountTriangles(surf)
	Next
	
	surf=GetSurface(mesh,1) 
	
	;start writing the file
	out=WriteFile(file$) 
	WriteLine out,"Ambient light color: Red=0.5 Green=0.5 Blue=0.5"
	WriteLine out,""
	WriteLine out,"Named object: "+Chr$(34)+"untitled"+Chr$(34)
	WriteLine out,"Tri-mesh, Vertices: "+totalVertices+" Faces: "+totalPolygons
	WriteLine out,"Vertex list:"
	
	;Vertices
	For surface=1 To CountSurfaces(mesh)
		surf=GetSurface(mesh,surface)
		For a=0 To CountVertices(surf)-1 
			WriteLine out,"Vertex "+a+": X:"+VertexX(surf,a)+" Y:"+VertexY(surf,a)+" Z:"+VertexZ(surf,a)+";," 
		Next 
	Next
	
	;Faces
	WriteLine out,"Face list:"
	baseVertex=0
	For surface=1 To CountSurfaces(mesh)
		surf=GetSurface(mesh,surface)
		For a=0 To CountTriangles(surf)-1
			WriteLine out,"Face "+a+": A:"+(TriangleVertex(surf,a,0)+baseVertex)+" B:"+(TriangleVertex(surf,a,1)+baseVertex)+" C:"+(TriangleVertex(surf,a,2)+baseVertex)+" AB:1 BC:1 CA:1"
			WriteLine out,"Smoothing: 1"
		Next
		baseVertex=baseVertex+CountVertices(surf)
	Next
	
	CloseFile out
End Function

Comments

Ross C2005
This code doesn't seem to work... :(


Code Archives Forum