-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhouse.lua
111 lines (94 loc) · 2.73 KB
/
house.lua
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
require"anima"
local GL = GLcanvas{W=800,viewH=600,aspect=1,vsync=1,profile="CORE"}--DEBUG=true}
GL.use_presets = true
local NM
local camera = Camera(GL,"tps")
camera.NM.vars.dist[0] = 1.5
local edit
local tex
local object
local filters = {glc.GL_NEAREST,glc.GL_LINEAR}
local function make_mesh(...)
local vec2 = mat.vec2
local SP3D = edit.Makers[2]
print("makemesh",#SP3D.HeightEditors,"splines",...)
if #SP3D.HeightEditors == 0 then return end
--print(debug.traceback())
--put all spline points in common structure
local MP = camera:MP()
local points = {}
local epoints = {}
local indexes = {}
for i=1,#SP3D.HeightEditors do
local mesh = SP3D:get_mesh(i)
for j,p in ipairs(mesh.points) do
points[#points+1] = camera:Eye2Viewport(p,MP)
epoints[#points] = p
end
end
if #epoints==0 then return end
local offsetind = 0
for i=1,#SP3D.HeightEditors do
local mesh = SP3D:get_mesh(i)
for j,ind in ipairs(mesh.indexes) do
indexes[#indexes+1] = ind + offsetind
end
offsetind = offsetind + #mesh.points
end
--get tcoords
--first bounding box of screen points
local minx,maxx,miny,maxy = math.huge,-math.huge,math.huge,-math.huge
for i,p in ipairs(points) do
minx = p.x < minx and p.x or minx
maxx = p.x > maxx and p.x or maxx
miny = p.y < miny and p.y or miny
maxy = p.y > maxy and p.y or maxy
end
local width = maxx - minx
local height = maxy - miny
--the map to 0,1
local tcoords = {}
for i,p in ipairs(points) do
local newx = (p.x - minx)/width
local newy = (p.y - miny)/height
tcoords[i] = vec2(newx,newy)
end
local meshE = mesh.mesh({points=epoints, triangles=indexes, tcoords=tcoords})
local MVinv = camera:MV().inv
local meshW = meshE:clone()
meshW:M4(MVinv)
meshW:calc_centroid()
local frameO = edit.planes[1].frame
local frame = mesh.move_frame(frameO,MVinv)
MI.clamp_to_border = false
if NM.gentex then
local init_r = secs_now()
MI:MeshRectify(meshE,nil,filters[NM.filter])
print("mesh rectify in ",secs_now()-init_r)
end
object:setMesh(meshW,MI.texR,frame)
end
NM = GL:Dialog("test",{
{"make_mesh",0,gui.types.button,function() make_mesh() end},
{"draw_image",false,gui.types.toggle},
{"gentex",false,gui.types.toggle},
{"filter",1,guitypes.slider_enum,{"nearest","linear","none"}}
})
edit = require"anima.modeling.rhomboidsM"(GL,camera,make_mesh)
function GL.init()
tex = GL:Texture():Load[[casa.png]]
GL:set_WH(tex.width, tex.height)
MI = require"anima.modeling.mesh_image"(GL,camera,tex,2)
object = require"anima.Object3D"(GL,camera)
GL:preset_load("casa.preset")
end
function GL.draw(t,w,h)
ut.Clear()
if NM.draw_image then
tex:drawcenter()
ut.ClearDepth()
end
edit:draw(t,w,h)
object:draw()
end
GL:start()