-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPhysMeshViewer.txt
81 lines (69 loc) · 2.59 KB
/
PhysMeshViewer.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
--@name PhysMeshViewer
--@author
--@shared
local holos = {}
if SERVER then
local e = chip():isWeldedTo()
local holos = {}
local stream = bit.stringstream()
local nholos = e:getPhysicsObjectCount()
stream:writeInt32(nholos)
for i=0, nholos-1 do
local phys = e:getPhysicsObjectNum(i)
local convexes = phys:getMeshConvexes()
stream:writeInt32(#convexes)
for k, v in pairs(convexes) do
local holo = holograms.create(phys:getPos(), phys:getAngles(), "models/Combine_Helicopter/helicopter_bomb01.mdl")
holo:setMaterial("models/wireframe")
holo.bone = phys
stream:writeInt16(holo:entIndex())
stream:writeInt32(#v)
for o=1, #v do
local pos = v[o].pos
stream:writeFloat(pos[1])
stream:writeFloat(pos[2])
stream:writeFloat(pos[3])
end
holos[#holos+1] = holo
end
end
stream = stream:getString()
hook.add("think","",function()
for k, v in pairs(holos) do
v:setPos(v.bone:getPos())
v:setAngles(v.bone:getAngles())
end
end)
hook.add("net","",function(name,len,pl)
net.start("")
net.writeStream(stream)
net.send(pl)
end)
else
net.start("")
net.send()
hook.add("net","",function(n)
net.readStream(function(data)
local stream = bit.stringstream(data)
for i=1, stream:readUInt32() do
for o=1, stream:readUInt32() do
local e = entity(stream:readUInt16())
local mins, maxs = Vector(math.huge), Vector(-math.huge)
local m = {}
for p=1, stream:readUInt32() do
local pos = Vector(stream:readFloat(), stream:readFloat(), stream:readFloat())
m[p] = {pos = pos}
if pos[1] < mins[1] then mins[1] = pos[1] end
if pos[2] < mins[2] then mins[2] = pos[2] end
if pos[3] < mins[3] then mins[3] = pos[3] end
if pos[1] > maxs[1] then maxs[1] = pos[1] end
if pos[2] > maxs[2] then maxs[2] = pos[2] end
if pos[3] > maxs[3] then maxs[3] = pos[3] end
end
e:setMesh(mesh.createFromTable(m))
e:setRenderBounds(mins, maxs)
end
end
end)
end)
end