Drawn triangles are flickering black. (Using mesh library)
2 replies, posted
Hello! My first post on Facepunch!
I need help, but keep in mind I'm still new to lua in Garry's Mod, but not to programming in general.
Heres my predicament...
I wanted to experiment, and try to create a interface in Garry's Mod that was in 3D space, in this case I was trying to create a resizable inventory.
Since the I wanted the inventory to be resizable (more/less item slots), I had to draw a "dynamic mesh", and I used the mesh and cam libraries to do this.
I managed to get it to work easily, but as the title of this topic states, they're flickering black.
I've searched on Wiki, Google, and Facepunch to see if I could find others with the problem, and there was a couple of people who had already made topics on the issue, but none of those were fixes for the problem (for me at least).
Some people say they don't have the problem at all, which is most likely true, but saying you don't have the problem doesn't help people that do...
I am aware that using an unlit material does stop the flickering, but I would LOVE it to have lighting, if possible.
If there is anyone that could help me solve this problem, I would greatly appreciate it, even if it's done in a completely different way...
Any solution is a good one for me.
Thank you!
Edit:
If you don't have the problem, and you still want to try to help, you could always tell me about some alternate method of achieving my desired result.
I'll try any suggestions, then report back.
This is the workaround I'm using. It's probably not ideal at all and will look terrible if your inventory can move around (because of abrupt changes in lighting), but if your inventory is completely stationary, it should look convincing enough.
[lua]
local renderMat = Material("models/debug/debugwhite")
local lighting_dirs = {
[BOX_BOTTOM]= Vector(0,0,-1);
[BOX_TOP] = Vector(0,0,1);
[BOX_LEFT] = Vector(0,-1,0);
[BOX_RIGHT] = Vector(0,1,0);
[BOX_BACK] = Vector(-1,0,0);
[BOX_FRONT] = Vector(1,0,0);
}
function ENT:Draw()
if self.Mesh then
local pos, ang = self:GetPos(), self:GetAngles()
local M = Matrix()
M:Translate(pos)
M:Rotate(ang)
render.SetMaterial(renderMat)
render.SuppressEngineLighting(true)
for k,v in pairs(lighting_dirs) do
local col = render.ComputeLighting(pos, v)
render.SetModelLighting(k, col.x, col.y, col.z)
end
cam.PushModelMatrix(M)
self.Mesh:Draw()
cam.PopModelMatrix()
render.SuppressEngineLighting(false)
end
end
[/lua]
It basically measures the lighting in 6 directions at the center of your entity, and then applies it to your mesh. Probably not the best way to do it, but it doesn't look half bad.
Thanks for being the only one to reply.
I don't seem to have any problems when I do it like [URL="http://wiki.garrysmod.com/page/Global/Mesh"]this[/URL].
I'll probably still take a look at what that code does exactly.
:)
Sorry, you need to Log In to post a reply to this thread.