Meshes

This is solved, check my latest post

I’m probably doing something stupid but:

[lua]
local mat = Material( “models/props_wasteland/wood_fence01a” )
local obj = Mesh()
local verts = {
{ pos = LocalPlayer():GetPos() + Vector( 0, 0, 0 ), u = 0, v = 0 },
{ pos = LocalPlayer():GetPos() + Vector( 100, 0, 0 ), u = 1, v = 0 },
{ pos = LocalPlayer():GetPos() + Vector( 100, 100, 0 ), u = 1, v = 1 }
}

obj:BuildFromTriangles( verts )

hook.Add( “PostDrawOpaqueRenderables”, “IMeshTest”, function()
render.SetMaterial( mat )
obj:Draw()
end )
[/lua]

Isn’t drawing for me, I’ve checked that the hooks are being called correctly, no errors as far as I can tell.
Followed from here, the original example wasn’t working for me either, but I just assumed that the co-ordinates of Vector(0,0,0) made it unreachable for me.

Don’t forget that it draws only one triangle, and you will only be able to see it from specific direction. ( Because culling, unless you use $nocull material )

I knew I’d done something stupid, thanks. You had to look underneath, which I hadn’t bothered to check.

Also solved, thanks again RobotBoy

I’m running with the issue of optimization, currently, I’m using this:

[lua]
cam.PushModelMatrix( matrix );
mesh.Begin( MATERIAL_TRIANGLES, table.Count(model) )
for k, v in pairs(model) do
mesh.Color(200,200,200)
EasyVert(Vector(v[3][1], v[3][2], v[3][3]), vector_up )
EasyVert(Vector(v[2][1], v[2][2], v[2][3]), vector_up )
EasyVert(Vector(v[1][1], v[1][2], v[1][3]), vector_up )
end
mesh.End( )
cam.PopModelMatrix( )
[/lua]

Instead of IMesh’s to draw my object, but this is creating problems, a single teapot grinds my FPS from 150 to 50. I’m thinking this is because I’m essentially rebuilding it all through Lua, is there any way to make use of IMesh, but still use transformations to move the mesh’s location. I can’t seem to find the way of altering the vertexes position once set so that, for example, it follows an entity.

Uh, call obj:Draw() inside a model matrix?

facepalm

Looks like I’ve found one more issue, after painlessly fixing a bunch of bugs, and rewriting my code. I finally got texturing to half work, I’m thinking this is something to do with meshes or how I’m texturing it.

Any ideas?

Textured:

https://dl.dropboxusercontent.com/u/16266581/objtank01.png[/t]

Textured /w Wireframe:
[t]https://dl.dropboxusercontent.com/u/16266581/objtank02.png

Renderer:
http://pastebin.com/MbCD9vKe

Test Code:

[lua]
function ENT:Draw()
if not self.m_Model then
self.m_Model = NewmanModel.New(NEWMAN_WAVEFRONT, NEWMAN_FILE, “objmodels/t90.txt”)
self.m_Model:SetMaterial(“Gun”, Material(“tankObj/Gun.png”))
self.m_Model:SetMaterial(“Main_Body_2”, Material(“tankObj/Main Body 2.png”))
self.m_Model:SetMaterial(“Main_Body”, Material(“tankObj/Main Body.png”))
self.m_Model:SetMaterial(“Turret”, Material(“tankObj/Turret.png”))

	self.m_Model:GetPart("Turret"):SetAngle(0,90,0)
end

self.m_Model:SetAngle(self:GetAngles())
self.m_Model:SetPos(self:GetPos())
self.m_Model:SetScale(100,100,100)
self.m_Model:Draw()

end
[/lua]

Try playing with http://wiki.garrysmod.com/page/render/CullMode, if it doesn’t help, invert all your polygons.