-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fbe68bd
Showing
14 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Defold Protocol Buffer Text Files (https://github.com/github/linguist/issues/5091) | ||
*.animationset linguist-language=JSON5 | ||
*.atlas linguist-language=JSON5 | ||
*.camera linguist-language=JSON5 | ||
*.collection linguist-language=JSON5 | ||
*.collectionfactory linguist-language=JSON5 | ||
*.collectionproxy linguist-language=JSON5 | ||
*.collisionobject linguist-language=JSON5 | ||
*.cubemap linguist-language=JSON5 | ||
*.display_profiles linguist-language=JSON5 | ||
*.factory linguist-language=JSON5 | ||
*.font linguist-language=JSON5 | ||
*.gamepads linguist-language=JSON5 | ||
*.go linguist-language=JSON5 | ||
*.gui linguist-language=JSON5 | ||
*.input_binding linguist-language=JSON5 | ||
*.label linguist-language=JSON5 | ||
*.material linguist-language=JSON5 | ||
*.mesh linguist-language=JSON5 | ||
*.model linguist-language=JSON5 | ||
*.particlefx linguist-language=JSON5 | ||
*.render linguist-language=JSON5 | ||
*.sound linguist-language=JSON5 | ||
*.sprite linguist-language=JSON5 | ||
*.spinemodel linguist-language=JSON5 | ||
*.spinescene linguist-language=JSON5 | ||
*.texture_profiles linguist-language=JSON5 | ||
*.tilemap linguist-language=JSON5 | ||
*.tilesource linguist-language=JSON5 | ||
|
||
# Defold JSON Files | ||
*.buffer linguist-language=JSON | ||
|
||
# Defold GLSL Shaders | ||
*.fp linguist-language=GLSL | ||
*.vp linguist-language=GLSL | ||
|
||
# Defold Lua Files | ||
*.editor_script linguist-language=Lua | ||
*.render_script linguist-language=Lua | ||
*.script linguist-language=Lua | ||
*.gui_script linguist-language=Lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/.internal | ||
/build | ||
.externalToolBuilders | ||
.DS_Store | ||
Thumbs.db | ||
.lock-wscript | ||
*.pyc | ||
.project | ||
.cproject | ||
builtins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Welcome to Defold | ||
|
||
This project was created from the "basic 3D" project template. | ||
|
||
The settings in ["game.project"](defold://open?path=/game.project) are mostly set to the default values. The render script is a modified version of the default render script with the addition that models are rendered in a separate pass before 2D components such as sprites and tilemaps. The physics type is set to 3D and not 2D. | ||
|
||
The project contains a bootstrap ["main.collection"](defold://open?path=/main/main.collection) that includes a game object with a camera component and a game object with three different models. | ||
|
||
Check out [the documentation pages](https://defold.com/learn) for examples, tutorials, manuals and API docs. | ||
|
||
If you run into trouble, help is available in [our forum](https://forum.defold.com). | ||
|
||
Happy Defolding! | ||
|
||
## Credits | ||
|
||
* Textures by Kenney (https://www.kenney.nl) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mesh: "/builtins/assets/meshes/cube.dae" | ||
material: "/builtins/materials/model.material" | ||
textures: "/assets/images/green.png" | ||
skeleton: "" | ||
animations: "" | ||
default_animation: "" | ||
name: "unnamed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mesh: "/builtins/assets/meshes/quad.dae" | ||
material: "/builtins/materials/model.material" | ||
textures: "/assets/images/brown.png" | ||
skeleton: "" | ||
animations: "" | ||
default_animation: "" | ||
name: "unnamed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mesh: "/builtins/assets/meshes/sphere.dae" | ||
material: "/builtins/materials/model.material" | ||
textures: "/assets/images/brown.png" | ||
skeleton: "" | ||
animations: "" | ||
default_animation: "" | ||
name: "unnamed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[bootstrap] | ||
main_collection = /main/main.collectionc | ||
render = /main/main.renderc | ||
|
||
[script] | ||
shared_state = 1 | ||
|
||
[display] | ||
width = 960 | ||
height = 640 | ||
|
||
[android] | ||
input_method = HiddenInputField | ||
package = com.defold.example.basic3d | ||
|
||
[project] | ||
dependencies = | ||
title = RT_NORMALS_EXAMPLE | ||
|
||
[physics] | ||
type = 3D | ||
|
||
[osx] | ||
bundle_identifier = com.defold.example.basic3d | ||
|
||
[ios] | ||
bundle_identifier = com.defold.example.basic3d | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mouse_trigger { | ||
input: MOUSE_BUTTON_1 | ||
action: "touch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
name: "main" | ||
scale_along_z: 0 | ||
embedded_instances { | ||
id: "main" | ||
data: "components {\n" | ||
" id: \"cube\"\n" | ||
" component: \"/assets/models/cube.model\"\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" | ||
" property_decls {\n" | ||
" }\n" | ||
"}\n" | ||
"components {\n" | ||
" id: \"main\"\n" | ||
" component: \"/main/main.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" | ||
" property_decls {\n" | ||
" }\n" | ||
"}\n" | ||
"components {\n" | ||
" id: \"quad\"\n" | ||
" component: \"/assets/models/quad.model\"\n" | ||
" position {\n" | ||
" x: 3.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" | ||
" property_decls {\n" | ||
" }\n" | ||
"}\n" | ||
"components {\n" | ||
" id: \"sphere\"\n" | ||
" component: \"/assets/models/sphere.model\"\n" | ||
" position {\n" | ||
" x: 1.5\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" | ||
" property_decls {\n" | ||
" }\n" | ||
"}\n" | ||
"" | ||
position { | ||
x: 0.0 | ||
y: 0.0 | ||
z: 0.0 | ||
} | ||
rotation { | ||
x: 0.0 | ||
y: 0.0 | ||
z: 0.0 | ||
w: 1.0 | ||
} | ||
scale3 { | ||
x: 1.0 | ||
y: 1.0 | ||
z: 1.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: 1\\n" | ||
"orthographic_projection: 0\\n" | ||
"orthographic_zoom: 1.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: 0.0 | ||
y: 0.0 | ||
z: 10.0 | ||
} | ||
rotation { | ||
x: 0.0 | ||
y: 0.0 | ||
z: 0.0 | ||
w: 1.0 | ||
} | ||
scale3 { | ||
x: 1.0 | ||
y: 1.0 | ||
z: 1.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
script: "/main/main.render_script" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
-- | ||
-- projection that centers content with maintained aspect ratio and optional zoom | ||
-- | ||
local function fixed_projection(near, far, zoom) | ||
local projected_width = render.get_window_width() / (zoom or 1) | ||
local projected_height = render.get_window_height() / (zoom or 1) | ||
local xoffset = -(projected_width - render.get_width()) / 2 | ||
local yoffset = -(projected_height - render.get_height()) / 2 | ||
return vmath.matrix4_orthographic(xoffset, xoffset + projected_width, yoffset, yoffset + projected_height, near, far) | ||
end | ||
-- | ||
-- projection that centers and fits content with maintained aspect ratio | ||
-- | ||
local function fixed_fit_projection(near, far) | ||
local width = render.get_width() | ||
local height = render.get_height() | ||
local window_width = render.get_window_width() | ||
local window_height = render.get_window_height() | ||
local zoom = math.min(window_width / width, window_height / height) | ||
return fixed_projection(near, far, zoom) | ||
end | ||
-- | ||
-- projection that stretches content | ||
-- | ||
local function stretch_projection(near, far) | ||
return vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), near, far) | ||
end | ||
|
||
local function get_projection(self) | ||
return self.projection_fn(self.near, self.far, self.zoom) | ||
end | ||
|
||
function init(self) | ||
self.tile_pred = render.predicate({"tile"}) | ||
self.gui_pred = render.predicate({"gui"}) | ||
self.text_pred = render.predicate({"text"}) | ||
self.particle_pred = render.predicate({"particle"}) | ||
self.model_pred = render.predicate({"model"}) | ||
|
||
self.clear_color = vmath.vector4(0, 0, 0, 0) | ||
self.clear_color.x = sys.get_config_number("render.clear_color_red", 0) | ||
self.clear_color.y = sys.get_config_number("render.clear_color_green", 0) | ||
self.clear_color.z = sys.get_config_number("render.clear_color_blue", 0) | ||
self.clear_color.w = sys.get_config_number("render.clear_color_alpha", 0) | ||
|
||
self.view = vmath.matrix4() | ||
|
||
-- default is stretch projection. copy from builtins and change for different projection | ||
-- or send a message to the render script to change projection: | ||
-- msg.post("@render:", "use_stretch_projection", { near = -1, far = 1 }) | ||
-- msg.post("@render:", "use_fixed_projection", { near = -1, far = 1, zoom = 2 }) | ||
-- msg.post("@render:", "use_fixed_fit_projection", { near = -1, far = 1 }) | ||
self.near = -1 | ||
self.far = 1 | ||
self.projection_fn = stretch_projection | ||
end | ||
|
||
function update(self) | ||
render.set_depth_mask(true) | ||
render.set_stencil_mask(0xff) | ||
render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0}) | ||
|
||
render.set_viewport(0, 0, render.get_window_width(), render.get_window_height()) | ||
render.set_view(self.view) | ||
render.set_projection(get_projection(self)) | ||
|
||
-- render models | ||
-- | ||
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA) | ||
render.enable_state(render.STATE_CULL_FACE) | ||
render.enable_state(render.STATE_DEPTH_TEST) | ||
render.set_depth_mask(true) | ||
render.draw(self.model_pred) | ||
render.set_depth_mask(false) | ||
render.disable_state(render.STATE_DEPTH_TEST) | ||
render.disable_state(render.STATE_CULL_FACE) | ||
|
||
-- render sprites, label, particles | ||
-- | ||
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA) | ||
render.enable_state(render.STATE_DEPTH_TEST) | ||
render.enable_state(render.STATE_STENCIL_TEST) | ||
render.enable_state(render.STATE_BLEND) | ||
render.draw(self.tile_pred) | ||
render.draw(self.particle_pred) | ||
render.disable_state(render.STATE_STENCIL_TEST) | ||
render.disable_state(render.STATE_DEPTH_TEST) | ||
|
||
-- debug | ||
render.draw_debug3d() | ||
|
||
-- render GUI | ||
-- | ||
render.set_view(vmath.matrix4()) | ||
render.set_projection(vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1)) | ||
|
||
render.enable_state(render.STATE_STENCIL_TEST) | ||
render.draw(self.gui_pred) | ||
render.draw(self.text_pred) | ||
render.disable_state(render.STATE_BLEND) | ||
render.disable_state(render.STATE_STENCIL_TEST) | ||
end | ||
|
||
function on_message(self, message_id, message) | ||
if message_id == hash("clear_color") then | ||
self.clear_color = message.color | ||
elseif message_id == hash("set_view_projection") then | ||
self.view = message.view | ||
self.projection = message.projection | ||
elseif message_id == hash("use_camera_projection") then | ||
self.projection_fn = function() return self.projection or vmath.matrix4() end | ||
elseif message_id == hash("use_stretch_projection") then | ||
self.near = message.near or -1 | ||
self.far = message.far or 1 | ||
self.projection_fn = stretch_projection | ||
elseif message_id == hash("use_fixed_projection") then | ||
self.near = message.near or -1 | ||
self.far = message.far or 1 | ||
self.zoom = message.zoom or 1 | ||
self.projection_fn = fixed_projection | ||
elseif message_id == hash("use_fixed_fit_projection") then | ||
self.near = message.near or -1 | ||
self.far = message.far or 1 | ||
self.projection_fn = fixed_fit_projection | ||
end | ||
end |
Oops, something went wrong.