<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[GMan's Mods & Stuff — Add a vertex to a mesh]]></title>
	<link rel="self" href="https://gprogs.com/extern.php?action=feed&amp;tid=254&amp;type=atom" />
	<updated>2007-07-25T12:14:38Z</updated>
	<generator>PunBB</generator>
	<id>https://gprogs.com/viewtopic.php?id=254</id>
		<entry>
			<title type="html"><![CDATA[Re: Add a vertex to a mesh]]></title>
			<link rel="alternate" href="https://gprogs.com/viewtopic.php?pid=1058#p1058" />
			<content type="html"><![CDATA[<p>thank you very much for taking the time to post this ninjarat!&nbsp; i havent tried it out but its looks good.&nbsp; </p><p>as ninjarat mentioned, take a peek at the surface functionality of iB3D for some examples of how to get at and manipulate mesh data.</p><p>the one thing i wanted to throw out for everyone (and you probably already saw it in my code) is that animated meshes in Irrlicht are not updatable.&nbsp; only static meshes or SMesh based meshes can be altered.</p>]]></content>
			<author>
				<name><![CDATA[gman]]></name>
				<uri>https://gprogs.com/profile.php?id=2</uri>
			</author>
			<updated>2007-07-25T12:14:38Z</updated>
			<id>https://gprogs.com/viewtopic.php?pid=1058#p1058</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Add a vertex to a mesh]]></title>
			<link rel="alternate" href="https://gprogs.com/viewtopic.php?pid=1057#p1057" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>&#039;constants to distinguish between mesh buffer modes
Const MESHBUFFER_STANDARD=0
Const MESHBUFFER_LIGHTMAP=1
Const MESHBUFFER_TANGENTS=2

&#039;this is an editable mesh container class.  it holds an irrlicht
&#039;static SMesh and performs simple manipulations on it.  planning
&#039;an animated mesh one too.  seperately or integrated, I have not
&#039;yet decided.
Type TMeshContainer
    Field mesh:SMesh
    
    Function create:TMeshContainer(mesh:SMesh)
        irrmesh:TMeshContainer=New TMeshContainer
        irrmesh.mesh=mesh
        Return irrmesh
    End Function
    
    Method CreateSurface:TSurfaceContainer(buffermode=MESHBUFFER_STANDARD)
        surface:TSurfaceContainer=TSurfaceContainer.create(buffermode)
        mesh.addMeshBuffer surface.buffer
        Return surface
    End Method
    
    Method CountSurfaces()
        Return mesh.getMeshBufferCount()
    End Method
    
    Method GetSurface:TSurfaceContainer(index)
        surface:TSurfaceContainer=New TSurfaceContainer
        surface.buffer=SMeshBuffer(mesh.getMeshBuffer(index))
        Return surface
    End Method
    
    Method GetWidth()
        Return mesh.getBoundingBox().getExtent().getX()
    End Method
    
    Method GetHeight()
        Return mesh.getBoundingBox().getExtent().getY()
    End Method
    
    Method GetDepth()
        Return mesh.getBoundingBox().getExtent().getZ()
    End Method
    
    Method SetScale(sx#,sy#,sz#)
        TIrrContainer.IrrMeshManip.scaleMesh ..
         mesh,Vector3df.createFromVals(sx,sy,sz)
    End Method
    
    Method FlipNormals()
        TIrrContainer.IrrMeshManip.flipSurfaces mesh
    End Method
    
    Method Normalize()
        TIrrContainer.IrrMeshManip.recalculateNormals mesh
    End Method
End Type


&#039;this is a container for a surface, which is simply a mesh vertex buffer
&#039;and a format and access mode.  different formats are faster than others
&#039;in specific operations but not others.  it depends on what you&#039;re doing
&#039;what vertex format is best.  I&#039;m partial to the standard format
Type TSurfaceContainer
    Field buffer:IMeshBuffer
    Field bufmode
    
    Function create:TSurfaceContainer(buffermode=MESHBUFFER_STANDARD)
        surface:TSurfaceContainer=New TSurfaceContainer
        surface.bufmode=buffermode
        Select buffermode
            Case MESHBUFFER_STANDARD  surface.buffer=SMeshBuffer.create()
            Case MESHBUFFER_LIGHTMAP  surface.buffer=SMeshBufferLightMap.create()
            Case MESHBUFFER_TANGENTS  surface.buffer=SMeshBufferTangents.create()
        End Select
    End Function
    
    Method AddVertex(x#,y#,z#,nx#=0,ny#=0,nz#=0,u#=0,v#=0,color:TColor=Null,alpha=255)
        If color=Null Then color=CreateColor(COLORTYPE_RGB,1,1,1)
        
        vert:S3DVertex=S3DVertex.createFromVals(x,y,z,nx,ny,nz,..
         _SCOLOR(alpha,..
         color.Red()*255,color.Green()*255,color.Blue()*255),u,v)
        
        buffer.getVertices().push_back vert
        Return CountVertices()-1
    End Method
    
    Method AddTriangle(v0:Short,v1:Short,v2:Short)
        indicies:Array_u16=buffer.getIndices()
        indicies.push_back v0
        indicies.push_back v1
        indicies.push_back v2
    End Method
    
    Method CountVertices()
        Return buffer.getVertexCount()
    End Method
    
    Method GetVertex:Vertex(index)
        Return Vertex(buffer.getVertices().elementAt(index))
    End Method
    
    Method SetVertexCoords(index,px#,py#,pz#)
        vert:Vertex=GetVertex(index)
        vert.setPos Vector3df.createFromVals(px,py,pz)
    End Method
    
    Method SetVertexNormal(index,nx#,ny#,nz#)
        vert:Vertex=GetVertex(index)
        vert.setNormal Vector3df.createFromVals(nx,ny,nz)
    End Method
    
    Method SetSurfaceColor(color:TColor=Null,alpha=255)
        If color=Null Then color=CreateColor(COLORTYPE_RGB,1,1,1)
        For index=0 To CountVertices()-1
            vert:Vertex=GetVertex(index)
            vert.SetColor _SCOLOR(alpha,..
             color.Red()*255,color.Green()*255,color.Blue()*255)
        Next
    End Method
    
    Method SetVertexColor(index,color:TColor=Null,alpha=255)
        If color=Null Then color=CreateColor(COLORTYPE_RGB,1,1,1)
        
        vert:Vertex=GetVertex(index)
        vert.SetColor _SCOLOR(alpha,..
         color.Red()*255,color.Green()*255,color.Blue()*255)
    End Method
    
    Method SetVertexTextureCoords(index,u#,v#)
        vert:Vertex=GetVertex(index)
        vert.setTCoords(Vector2df.createFromVals(u,v))
    End Method
    
    Method GetVertexColor:TColor(index)
        vertcolor:SColor=GetVertex(index).GetColor()
        Return CreateColor(COLORTYPE_RGB,..
         Float(vertcolor.getRed())/255#,..
         Float(vertcolor.getGreen())/255#,..
         Float(vertcolor.getBlue())/255#)
    End Method
    
    Method GetVertexAlpha#(index)
        Return GetVertex(index).GetColor().GetAlpha()
    End Method
    
    Method GetVertexPosX#(index)
        Return GetVertex(index).getPos().getX()
    End Method
    
    Method GetVertexPosY#(index)
        Return GetVertex(index).getPos().getY()
    End Method
    
    Method GetVertexPosZ#(index)
        Return GetVertex(index).getPos().getZ()
    End Method
    
    Method GetVertexNormX#(index)
        Return GetVertex(index).getNormal().getX()
    End Method
    
    Method GetVertexNormY#(index)
        Return GetVertex(index).getNormal().getY()
    End Method
    
    Method GetVertexNormZ#(index)
        Return GetVertex(index).getNormal().getZ()
    End Method
    
    Method GetVertexTexU#(index)
        Return GetVertex(index).getTCoords().getX()
    End Method
    
    Method GetVertexTexV#(index)
        Return GetVertex(index).getTCoords().getY()
    End Method
End Type</code></pre></div>]]></content>
			<author>
				<name><![CDATA[ninjarat]]></name>
				<uri>https://gprogs.com/profile.php?id=207</uri>
			</author>
			<updated>2007-07-24T23:58:33Z</updated>
			<id>https://gprogs.com/viewtopic.php?pid=1057#p1057</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Add a vertex to a mesh]]></title>
			<link rel="alternate" href="https://gprogs.com/viewtopic.php?pid=1056#p1056" />
			<content type="html"><![CDATA[<p>Is there any way to add a vertex to a mesh ?<br />I tried it with the Vertices-Array from IMeshBuffer, but after adding a Vertex to the array,<br />the mesh is almost the same as before and no new Vertex is there.<br />Why? Can anybody help me?</p>]]></content>
			<author>
				<name><![CDATA[porcus]]></name>
				<uri>https://gprogs.com/profile.php?id=127</uri>
			</author>
			<updated>2007-07-24T20:57:07Z</updated>
			<id>https://gprogs.com/viewtopic.php?pid=1056#p1056</id>
		</entry>
</feed>
