Skip to content

Commit

Permalink
Working lightmap using lightmapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lannan committed Oct 29, 2022
1 parent 7a400f7 commit 32292fd
Show file tree
Hide file tree
Showing 36 changed files with 979 additions and 13 deletions.
Binary file modified blender/addons/defender.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion blender/addons/defender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"name": "Defender",
"description": "Sync a Blender Scene directly to Defold resources",
"author": "dlannan",
"version": (1, 2, 0),
"version": (1, 3, 0),
"blender": (2, 80, 0),
"location": "3D View > Defold",
"warning": "", # used for warning icon and text in addons panel
Expand Down
20 changes: 10 additions & 10 deletions blender/addons/defender/defoldsync/defoldCmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,6 @@ def sceneMeshes(context, fhandle, temppath, texture_path, config):
# material names are cleaned here
mat.name = re.sub(r'[^\w]', ' ', mat.name)

lightmap_enable = False
if(mat.name.endswith("_LightMap")):
lightmap_enable = True

thisobj["matname"] = mat.name

#if( len(obj.material_slots) > 0 ):
# mat = obj.material_slots[0].material
# if mat and mat.node_tree:
Expand All @@ -439,6 +433,12 @@ def sceneMeshes(context, fhandle, temppath, texture_path, config):
print("[ ERROR ] : Uknown material type used.")
ErrorLine( config, " Unknown material type used.", str(mat.name), "ERROR")

lightmap_enable = False
if(mat.name.endswith("_LightMap")):
lightmap_enable = True

thisobj["matname"] = mat.name

if(len(textures) > 0):
thisobj["textures"] = textures

Expand Down Expand Up @@ -476,10 +476,10 @@ def sceneMeshes(context, fhandle, temppath, texture_path, config):
"uv": { "x": uv.x, "y": uv.y }
}

if( len(me.uv_layers) > 1 and (config.sync_mat_uv2 == True or lightmap_enable) ):
uvs = [uv for uv in me.uv_layers if uv != me.uv_layers.active]
uv = uvs[0].data[face.loops[ti]].uv
tridata["uv2"] = { "x": uv.x, "y": uv.y }
if( len(me.uv_layers) > 1 and ((config.sync_mat_uv2 == True) or (lightmap_enable == True)) ):
uvs = [uv for uv in obj.data.uv_layers if uv.active_render != True]
uv1 = uvs[0].data[face.loops[ti]].uv
tridata["uv2"] = { "x": uv1.x, "y": uv1.y }

thistri.append( tridata )

Expand Down
6 changes: 5 additions & 1 deletion blender/addons/defender/defoldsync/generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ table.count = function( tbl )
return count
end

string.endswith = function( str, ending )
return ending == "" or str:sub(-#ending) == ending
end

------------------------------------------------------------------------------------------------------------

local PATH_SEPARATOR = "/"
Expand Down Expand Up @@ -809,7 +813,7 @@ local function genmaterial( material_path, vpname, fpname, matname, pbrmaterial
matstr = matstr:gsub("MATERIAL_LIGHT_VECTOR", light_vector)

local mp = gendata.config.sync_mat_params
local mat_params = '\tx: '..mp.x..'\n\ty: '..mp.y..'\n\tz: '..mp.z..'\n\tw: 1.0'
local mat_params = '\tx: '..mp.x..'\n\ty: '..mp.y..'\n\tz: '..mp.z..'\n\tw: 0.1'
matstr = matstr:gsub("MATERIAL_PARAMS", mat_params)

makefile( material_path..matname, matstr)
Expand Down
175 changes: 175 additions & 0 deletions defold/lightmap-test/Collection.collection
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
name: "COLLECTION_NAME"
scale_along_z: 0

embedded_instances {
id: "Camera"
data: "embedded_components {\n"
" id: \"camera\"\n"
" type: \"camera\"\n"
" data: \"aspect_ratio: 1.0\\n"
" fov: 0.7854\\n"
" near_z: 0.1\\n"
" far_z: 1000.0\\n"
" auto_aspect_ratio: 0\\n"
"\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"

position {
x:7.3588914871216
y:-6.9257907867432
z:4.958309173584
}
rotation {
x:0.48353603482246
y:0.20870360732079
z:0.3368715941906
w:0.78048270940781
}
scale3 {
x:1
y:1
z:1
}
}

embedded_instances {
id: "Light"
data: ""

position {
x:4.0762453079224
y:1.0054539442062
z:5.9038619995117
}
rotation {
x:0.16907575726509
y:0.27217137813568
z:0.75588035583496
w:0.57094752788544
}
scale3 {
x:1
y:1
z:1
}
}

instances {
id: "Cube"
prototype: "/lightmap-test/gameobjects/Cube.go"

position {
x:-0.85902905464172
y:-0.77217829227448
z:2.1032619476318
}
rotation {
x:0
y:0
z:0
w:1
}
scale3 {
x:1
y:1
z:1
}
}

instances {
id: "Cube.001"
prototype: "/lightmap-test/gameobjects/Cube.001.go"

position {
x:0.69179463386536
y:0.19307661056519
z:1.4182910919189
}
rotation {
x:0
y:0
z:0
w:1
}
scale3 {
x:1
y:1
z:1
}
}

instances {
id: "Plane.002"
prototype: "/lightmap-test/gameobjects/Plane.002.go"

position {
x:-7.2279834747314
y:0
z:0.94748467206955
}
rotation {
x:0
y:0
z:0
w:1
}
scale3 {
x:1
y:1
z:1
}
}

embedded_instances {
id: "__root"
children: "Camera"
children: "Light"
children: "Cube"
children: "Cube.001"
children: "Plane.002"

data: "components {\n"
" id: \"Collection\"\n"
" component: \"/lightmap-test/scripts/Collection.script\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"

position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: -0.70710677
y: 0.0
z: 0.0
w: 0.70710677
}

scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
16 changes: 16 additions & 0 deletions defold/lightmap-test/gameobjects/Cube.001.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
components {
id: "Cube.001_mesh"
component: "/lightmap-test/meshes/Cube.001.mesh"
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
}

16 changes: 16 additions & 0 deletions defold/lightmap-test/gameobjects/Cube.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
components {
id: "Cube_mesh"
component: "/lightmap-test/meshes/Cube.mesh"
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
}

16 changes: 16 additions & 0 deletions defold/lightmap-test/gameobjects/Plane.002.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
components {
id: "Plane.002_mesh"
component: "/lightmap-test/meshes/Plane.002.mesh"
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defold/lightmap-test/images/Cube.001_baked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defold/lightmap-test/images/CubeAMRtexture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defold/lightmap-test/images/Cube_baked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defold/lightmap-test/images/Plane.002_baked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defold/lightmap-test/images/concrete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defold/lightmap-test/materials/black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defold/lightmap-test/materials/grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added defold/lightmap-test/materials/normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 32292fd

Please sign in to comment.