diff options
author | sanine-a <sanine.not@pm.me> | 2020-12-09 00:39:45 -0600 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-12-09 00:39:45 -0600 |
commit | f64bdd048d6d8f338272326c437a86df2990b426 (patch) | |
tree | f5c90338e90c82cf92ca111171a7d93ab0d95486 /demo | |
parent | 218933e98ae869ffc1a6f7e182995a21e8b42c5a (diff) |
refactor: move primitives into lua & streamline mesh creation
Diffstat (limited to 'demo')
-rw-r--r-- | demo/Primitives.lua | 20 | ||||
-rw-r--r-- | demo/SpatialShader.lua | 2 | ||||
-rw-r--r-- | demo/main.lua | 20 |
3 files changed, 32 insertions, 10 deletions
diff --git a/demo/Primitives.lua b/demo/Primitives.lua new file mode 100644 index 0000000..09142a5 --- /dev/null +++ b/demo/Primitives.lua @@ -0,0 +1,20 @@ +local Primitives = {} + +function Primitives.plane(width, height) + return honey.buildMesh{ position = { 0, 0, 0, + width, 0, 0, + 0, height, 0, + width, height, 0 }, + normal = { 0, 0, 1, + 0, 0, 1, + 0, 0, 1, + 0, 0, 1 }, + uv = { 0, 0, + 1, 0, + 0, 1, + 1, 1 }, + faces = { 1, 2, 3, + 4, 2, 1 } } +end + +return Primitives diff --git a/demo/SpatialShader.lua b/demo/SpatialShader.lua index 0c65176..b15859f 100644 --- a/demo/SpatialShader.lua +++ b/demo/SpatialShader.lua @@ -3,7 +3,7 @@ local VertexCode = [[ layout(location = 0) in vec3 position; layout(location = 1) in vec3 normal; -layout(location = 2) in vec2 uv; +layout(location = 4) in vec2 uv; uniform mat4 model; uniform mat4 view; diff --git a/demo/main.lua b/demo/main.lua index 8e8d3d3..6aa5775 100644 --- a/demo/main.lua +++ b/demo/main.lua @@ -1,7 +1,8 @@ local Node = require('Node') local FPSCamera = require('FPSCamera') local SpatialShader = require('SpatialShader') -local ScreenQuad = require('ScreenQuad') +local Primitives = require('Primitives') +-- local ScreenQuad = require('ScreenQuad') local MeshInstance = require('MeshInstance') FPSCamera.movement_speed = 5 @@ -20,25 +21,26 @@ local lightDirection = honey.glm.vec3{1,1,1} lightDirection:normalize() shader:setVec3('directional_lights[0].direction', lightDirection) shader:setVec3('directional_lights[0].color', honey.glm.vec3{0,1,0}) -local meshes = honey.mesh('Suzanne.obj') +local meshes = honey.loadMesh('Suzanne.obj') local suzanne = MeshInstance.new(sceneRoot, honey.glm.vec3{0,0,3}, honey.glm.vec3{0,math.pi,0}, honey.glm.vec3{0.5,1,0.5}, meshes[1], shader) +print(suzanne.mesh) local plane = MeshInstance.new(suzanne, honey.glm.vec3{1,0,0}, honey.glm.vec3{0,0,0}, honey.glm.vec3{1,1,1}, - honey.primitives.plane(4,4), + Primitives.plane(4,4), shader) -local plane2 = MeshInstance.new(suzanne, - honey.glm.vec3{5,0,0}, - honey.glm.vec3{0,math.pi,0}, - honey.glm.vec3{1,1,1}, - honey.primitives.plane(4,4), - shader) +-- local plane2 = MeshInstance.new(suzanne, +-- honey.glm.vec3{5,0,0}, +-- honey.glm.vec3{0,math.pi,0}, +-- honey.glm.vec3{1,1,1}, +-- honey.primitives.plane(4,4), +-- shader) suzanne.update = function(self, dt) self:rotate('y', dt) |