-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
175 lines (141 loc) · 4.2 KB
/
main.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
-- load ffi
ffi = require "ffi"
new = ffi.new
layers = {}
current_layer = new("int[1]",0)
dimen_texture = new("int[2]",{1024,1024})
--load 3DreamEngine
dream = require("3DreamEngine")
--load inspect
inspect = require('inspect')
--optionally set settings
imgui = require "imgui.love"
class = require 'middleclass'
classes = require 'classes'
faicons = require 'fonts.fAwesome5'
render_texs = {
albedo = nil,
RMA = nil,
normal = nil,
normal_data = nil,
emission = nil
}
--load gui
local gui = require "gui"
function table.moveCell(table,inn,outt)
local new_t = {}
for i = 1,#table do
if i ~= inn then
new_t[#new_t+1] = table[i]
end
if i == outt then
new_t[#new_t+1] = table[inn]
end
end
return new_t
end
function resizeImageData(data,width,height)
local img = love.graphics.newImage(data)
local canvas = love.graphics.newCanvas(width, height)
local old_width,old_height = data:getDimensions()
love.graphics.push("all")
local wasCanvas = love.graphics.getCanvas()
love.graphics.setCanvas(canvas)
love.graphics.clear()
love.graphics.draw(img,0,0,0,width/old_width,height/old_height)
love.graphics.pop()
love.graphics.setCanvas(wasCanvas)
return canvas:newImageData()
end
local instance
love.load = function(table)
instance = imgui.love_load{use_imgui_docking = true, use_imgui_viewport = false}
love.window.maximize()
imgui.GetIO().Fonts:AddFontDefault()
local config = imgui.ImFontConfig()
config.MergeMode = true
config.PixelSnapH = true
config.SizePixels = 14.0;
config.FontDataOwnedByAtlas = false
config.GlyphOffset.y = 1.0 -- смещение на 1 пиксеыот вниз
local fa_glyph_ranges = new("ImWchar[3]",{ faicons.min_range, faicons.max_range, 0 })
-- icon
local faicon = imgui.GetIO().Fonts:AddFontFromMemoryCompressedBase85TTF(faicons.get_font_data_base85(), config.SizePixels, config, fa_glyph_ranges)
layers[#layers+1] = classes.material:new()
end
--settings
local camZoom = 5
local camAngle = {0,0}
local sunPos = {100,100,100}
time = 0
lights = dream:newLight(0, 0, 0, 1.0, 0.75, 0.5)
lights.shadow = dream:newShadow("point")
lights.shadow.size = 0.1
--dream.defaultReflection = cimg:load("sky.cimg")
dream.sky_as_reflection = true
dream.defaultShaderType = "PBR"
--inits (applies settings)
dream.alphaBlendMode = "alpha"
dream:init()
--loads a object (optional with args)
yourObject = dream:loadObject("object", {splitMaterials = true, export3do = false, skip3do = true})
print(inspect(yourObject))
local v = 0
love.draw = function()
dream:setDaytime(gui.world_settings.dayTime[0])
dream:setWeather(0.25, 1.0 - 0.25)
--update lights
dream:resetLight()
dream:resetLight()
dream.cam:reset()
local cx = (camZoom*math.sin(math.rad(camAngle[1]))*math.cos(math.rad(camAngle[2])))
local cy = (camZoom*math.cos(math.rad(camAngle[1]))*math.cos(math.rad(camAngle[2])))
local cz = (camZoom*math.sin(math.rad(camAngle[2])))
--dream:addNewLight(sunPos[1],sunPos[2],sunPos[3], 1, 1, 1, 20, "sun")
dream.cam:translate(cx,cz,-cy)
--dream:addNewLight(-cx,-cz,cy, 1, 1, 1, 15)
dream.cam:rotateY(math.rad(-camAngle[1]))
dream.cam:rotateX(math.rad(-camAngle[2]))
--prepare for rendering
dream:prepare()
--rotate and draw and offset
dream:draw(yourObject)
--render
dream:present(not gui.world_settings.sky[0])
instance:NewFrame()
instance.MainDockSpace()
gui.draw()
instance:Render()
end
function love.mousemoved(x, y, dx, dy)
if love.mouse.isDown(3) then
camAngle[1] = camAngle[1] + dx
camAngle[2] = camAngle[2] - dy
end
end
function love.wheelmoved(x, y)
camZoom = camZoom + y*0.8
end
function love.update(dt)
gui.world_settings.dayTime[0] = gui.world_settings.dayTime[0] + dt * 0.05 * gui.world_settings.speedDay[0]
if gui.world_settings.dayTime[0] > 1 then gui.world_settings.dayTime[0] = 0 end
dream:update()
end
function love.keyreleased(key, scancode)
if key == 'escape' then
love.event.quit(0)
end
instance.update_key(scancode, false)
end
function love.resize()
dream:init()
end
love.keypressed = function(key,scancode,isrepeat)
instance.update_key(scancode, true)
end
love.textinput = function(text)
instance.textinput(text)
end
love.quit = function()
instance:destroy()
end