-
Notifications
You must be signed in to change notification settings - Fork 2
/
of.mesh.pd
79 lines (79 loc) · 5.04 KB
/
of.mesh.pd
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
#N canvas 295 67 985 634 12;
#X obj 15 10 inlet;
#X obj 15 1163 outlet;
#X obj 15 1117 list trim;
#X obj 82 1163 outlet;
#X text 601 817 RI;
#X obj 15 1140 route bang;
#X obj 15 42 ofelia d model-\$0 \; local canvas = ofCanvas(this) \;
local args = canvas:getArgs() \; mesh\$0 \, node\$0 = ofMesh() \, ofNode()
\; local filename \, drawmode \, strokeweight \, mode = args[1] \,
args[2] \, args[3] \, args[4] \; local loaded \, saved \, debug \,
t \, func = nil \, nil \, 0 \; local position \, orientation \, scale
\, lookat = ofVec3f() \, ofVec3f() \, ofVec3f(1 \, 1 \, 1) \, ofVec3f()
\; \; function M.new() \; ofWindow.addListener("setup" \, this) \;
if args[1] == nil then print("[gl.mesh] : No file") else args[1] =
filename end \; if args[2] == nil then drawmode = "fill" end \; if
args[3] == nil then strokeweight = 1 end \; if args[4] == nil then
mode = 0 end \; M.setup() end \; \; function M.free() ofWindow.removeListener("setup"
\, this) end \; function M.setup() if filename ~= nil then M.open(filename)
end end \; function M.prim(a) pfunc = a[1] t = a table.remove(a \,
1) mesh\$0 = _G[pfunc](table.unpack(t)):getMesh() end \; function M.append(a)
afunc = a[1] at = a table.remove(at \, 1) local shape=_G[afunc](table.unpack(at)):getMesh()
\, mesh\$0 mesh\$0:append(shape) end \; function M.clear() mesh\$0:clear()
end \; function M.debug(f) debug = f * 100 end \; function M.open(string)
ofSetDataPathRoot(ofCanvas(this \, 1):getDir()) filename = string \;
if ofWindow.exists then ofDisableArbTex() mesh\$0:clear() loaded =
mesh\$0:load(filename) end \; if loaded then print("loaded " .. filename)
end end \; function M.save(string) if ofWindow.exists then saved =
mesh\$0:save(string) end if saved then print("saved " .. string) end
end \; function M.draw(s) drawmode = s end \; function M.stroke(f)
strokeweight = f end \; function M.normalsize(float) normalsize=float
end \; function M.addnormal(l) mesh\$0:addNormal(ofVec3f(table.unpack(l)):vec3())
end \; function M.setupindicesauto() mesh\$0:setupIndicesAuto() end
\; function M.addtriangle(l) mesh\$0:addTriangle(l[1] \, l[2] \, l[3])
end \; function M.smoothnormals(f) mesh\$0:smoothNormals(f) end \;
function M.addcolor(l) mesh\$0:addColor(ofFloatColor(table.unpack(l)))end
\; function M.addtexcoord(l) mesh\$0:addTexCoord(ofVec2f(table.unpack(l)):vec2())end
\; function M.addindex(f) mesh\$0:addIndex(f) end \; function M.setindex(l)
mesh\$0:setIndex(table.unpack(l)) end \; function M.addvertex(l) mesh\$0:addVertex(ofPoint(table.unpack(l)):vec3())end
\; function M.addvertices(l) mesh\$0:addVertices(ofVec3f(table.unpack(l)):vec3()
\, #l) end \; function M.setcolor(l) mesh\$0:setColor(ofClamp(l[1]
\, 0 \, mesh\$0:getNumColors()) \, ofFloatColor(l[2] \, l[3] \, l[4]
\, l[5]))end \; function M.texture(f) if f > 0 then mesh\$0:enableTextures()
else mesh\$0:disableTextures() end end \; function M.textcoord(l) mesh\$0:setTexCoord(l[1]
\, l[2]) end \; function M.texturemap(l) mesh\$0:setTexCoord(l[1] \,
l[2] \, l[3] \, l[4]) end \; function M.removevertex(i) mesh\$0:removeVertex(i)
end \; function M.removecolor(i) mesh\$0:removeColor(i) end \; function
M.removenormal(i) mesh\$0:removeNormal(i) end \; function M.removeindex(i)
mesh\$0:removeIndex(i) end \; function M.settexcoord(l) mesh\$0:setTexCoord(ofClamp(l[1]
\, 0 \, mesh\$0:getNumTexCoords()) \, ofVec2f(l[1] \, l[2]):vec2())
end \; function M.removetexcoord(i) mesh\$0:removeTexCoord(i) end \;
function M.mode(a) mode = a end \; function M.clear() mesh\$0:clear()
end function M.clearcolors() mesh\$0:clearColors() end function M.clearindices()
mesh\$0:clearIndices() end function M.cleartexcoords() mesh\$0:clearTexCoords()
end \; function M.clearvertices() mesh\$0:clearVertices() end \; function
M.position(l) position:set (table.unpack(l)) node\$0:setPosition(position:vec3())
end \; function M.orientation(l) orientation:set (table.unpack(l))
node\$0:setOrientation(orientation:vec3()) end \; function M.scale(l)
scale:set (table.unpack(l)) node\$0:setScale(scale:vec3()) end \; function
M.lookat(l) lookat:set (table.unpack(l)) node\$0:lookAt(lookat:vec3())
end \; function M.get() return ofTable (mesh\$0:getNumVertices() \,
mesh\$0:getNumColors() \, mesh\$0:getNumIndices() \, mesh\$0:getNumNormals()
\, mesh\$0:getNumTexCoords() \, mesh\$0:hasColors() \, mesh\$0:hasTexCoords()
\, mesh\$0:hasNormals() \, mesh\$0:hasVertices() \, mesh\$0:hasIndices())end
\; function M.texture(f) if f > 0 then mesh\$0:enableTextures() else
mesh\$0:disableTextures() end end \; function M.texturemap(l) mesh\$0:setTexCoord(l[1]
\, l[2] \, l[3] \, l[4]) end \; \; function M.bang() \; mesh\$0:setMode(mode)
\; ofSetLineWidth(strokeweight) \; node\$0:transformGL() \; ofScale(10)
\; if drawmode == "fill" then mesh\$0:drawFaces() end \; if drawmode
== "point" then mesh\$0:drawVertices() end \; if drawmode == "line"
then mesh\$0:drawWireframe() end \; if drawmode == "normal" then mesh\$0:enableNormals()
end \; if debug > 0 then ofDrawAxis(debug) end \; node\$0:restoreTransformGL()
\; return(anything) \; end \;;
#X f 140;
#X connect 0 0 6 0;
#X connect 2 0 5 0;
#X connect 5 0 1 0;
#X connect 5 1 3 0;
#X connect 6 0 2 0;