Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Test
- function ENT:MakeCube(pos,ang,length,width,height)
- pos=pos or Vector()
- length=length or 1
- width=width or 1
- height=height or 1
- -- http://wiki.unity3d.com/index.php/ProceduralPrimitives
- local p0 = Vector(-length*0.5,-width*0.5,height*0.5)+pos
- local p1 = Vector(length*0.5,-width*0.5,height*0.5)+pos
- local p2 = Vector(length*0.5,-width*0.5,-height*0.5)+pos
- local p3 = Vector(-length*0.5,-width*0.5,-height*0.5)+pos
- p0:Rotate(ang)
- p1:Rotate(ang)
- p2:Rotate(ang)
- p3:Rotate(ang)
- local p4 = Vector(-length*0.5,width*0.5,height*0.5)+pos
- local p5 = Vector(length*0.5,width*0.5,height*0.5)+pos
- local p6 = Vector(length*0.5,width*0.5,-height*0.5)+pos
- local p7 = Vector(-length*0.5,width*0.5,-height*0.5)+pos
- p4:Rotate(ang)
- p5:Rotate(ang)
- p6:Rotate(ang)
- p7:Rotate(ang)
- local vertices = {
- -- Left
- p0, p1, p2,
- p2, p3, p0,
- -- Back
- p7, p4, p0,
- p7, p0, p3,
- -- Top
- p4, p5, p1,
- p4, p1, p0,
- -- Bottom
- p3, p6, p7,
- p3, p2, p6,
- -- Front
- p5, p6, p2,
- p5, p2, p1,
- -- Right
- p6, p5, p7,
- p5, p4, p7,
- };
- local up = Vector(0,0,1)
- local down = Vector(0,0,-1)
- local front = Vector(1,0,0)
- local back = Vector(-1,0,0)
- local left = Vector(0,-1,0)
- local right = Vector(0,1,0)
- local normales = {
- -- Left
- left, left, left, left, left, left,
- -- Back
- back, back, back, back, back, back,
- -- Top
- up, up, up, up, up, up,
- -- Bottom
- down, down, down, down, down, down,
- -- Front
- front, front, front, front, front, front,
- -- Right
- right, right, right, right, right, right,
- };
- local _00 = {0,0}
- local _10 = {1,0}
- local _01 = {0,1}
- local _11 = {1,1}
- local uvs = {
- -- Left
- _10, _00, _01, _01, _11, _10,
- -- Back
- _11, _10, _00, _11, _00, _01,
- -- Top
- _00, _01, _11, _00, _11, _10,
- -- Bottom
- _00, _11, _10, _00, _01, _11,
- -- Front
- _00, _01, _11, _00, _11, _10,
- -- Right
- _01, _00, _11, _00, _10, _11,
- }
- local verts = {}
- for i=1,6*6 do
- table.insert(verts,{pos = vertices[i], normal = normales[i], u = uvs[i][1], v = uvs[i][2] })
- end
- return verts,vertices
- end
- ENT:AddHook("Initialize","test",function(self)
- local width=500
- local height=1000
- local size=100
- self:SetRenderMode(RENDERMODE_TRANSALPHA)
- self:SetColor(Color(255,255,255,1))
- local sections={
- {self:MakeCube(Vector(0,-width/2,height/2),Angle(0,0,0),size,size,height)},
- {self:MakeCube(Vector(0,0,height+(size/2)),Angle(0,0,0),size,width+size,size)},
- {self:MakeCube(Vector(0,width/2,height/2),Angle(0,0,0),size,size,height)},
- }
- if CLIENT then
- self:SetRenderBounds(Vector(0,-(width/2)-(size/2),0),Vector(0,(width/2)+(size/2),height))
- self.meshes = {}
- for k,v in pairs(sections) do
- local newmesh=Mesh()
- newmesh:BuildFromTriangles(v[1])
- table.insert(self.meshes,newmesh)
- end
- end
- local meshes={}
- for k,v in pairs(sections) do
- table.insert(meshes,v[2])
- end
- self:PhysicsInitMultiConvex(meshes)
- self:EnableCustomCollisions(true)
- self.phys = self:GetPhysicsObject()
- if not IsValid(self.phys) then
- self:Remove()
- return
- end
- self.phys:SetMass(5000)
- self.phys:Wake()
- end)
- local rendermat=Material("models/props_wasteland/wood_fence01a")
- ENT:AddHook("Draw","test",function(self)
- self:DrawModel()
- mat = Matrix()
- mat:Translate( self:GetPos() )
- mat:Rotate(self:GetAngles())
- mat:Scale( Vector( 1, 1, 1 ) )
- render.SetMaterial(rendermat)
- cam.PushModelMatrix(mat)
- for k,v in pairs(self.meshes) do
- v:Draw()
- end
- cam.PopModelMatrix()
- end)
- -- https://facepunch.com/showthread.php?t=1459677
- ENT:AddHook("Think","test",function(self)
- if CLIENT and IsValid(self.phys) then
- self.phys:EnableMotion(false)
- self.phys:SetPos(self:GetPos())
- self.phys:SetAngles(self:GetAngles())
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment