Skip to content

Commit

Permalink
Add data textures for trail preview in Defold IDE.
Browse files Browse the repository at this point in the history
  • Loading branch information
aglitchman committed Apr 10, 2019
1 parent 126ca17 commit b63996d
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 6 deletions.
35 changes: 35 additions & 0 deletions demo/assets/graphics/demo.texture_profiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
path_settings {
path: "/hyper_trails/textures/data/**"
profile: "No Prem. Alpha"
}
path_settings {
path: "**"
profile: "Default"
}
profiles {
name: "Default"
platforms {
os: OS_ID_GENERIC
formats {
format: TEXTURE_FORMAT_RGBA
compression_level: BEST
compression_type: COMPRESSION_TYPE_DEFAULT
}
mipmaps: true
max_texture_size: 0
premultiply_alpha: true
}
}
profiles {
name: "No Prem. Alpha"
platforms {
os: OS_ID_GENERIC
formats {
format: TEXTURE_FORMAT_RGBA
compression_level: BEST
compression_type: COMPRESSION_TYPE_DEFAULT
}
mipmaps: false
premultiply_alpha: false
}
}
209 changes: 209 additions & 0 deletions demo/data_texture_preview.collection
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
name: "default"
scale_along_z: 0
embedded_instances {
id: "main"
data: "components {\n"
" id: \"main\"\n"
" component: \"/demo/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"
"}\n"
"embedded_components {\n"
" id: \"bg\"\n"
" type: \"sprite\"\n"
" data: \"tile_set: \\\"/demo/assets/atlases/main.atlas\\\"\\n"
"default_animation: \\\"background\\\"\\n"
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
"blend_mode: BLEND_MODE_ALPHA\\n"
"\"\n"
" position {\n"
" x: 480.0\n"
" y: 270.0\n"
" z: -0.5\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
"embedded_components {\n"
" id: \"text\"\n"
" type: \"label\"\n"
" data: \"size {\\n"
" x: 128.0\\n"
" y: 32.0\\n"
" z: 0.0\\n"
" w: 0.0\\n"
"}\\n"
"scale {\\n"
" x: 1.0\\n"
" y: 1.0\\n"
" z: 1.0\\n"
" w: 0.0\\n"
"}\\n"
"color {\\n"
" x: 1.0\\n"
" y: 1.0\\n"
" z: 1.0\\n"
" w: 1.0\\n"
"}\\n"
"outline {\\n"
" x: 0.0\\n"
" y: 0.4\\n"
" z: 0.8\\n"
" w: 1.0\\n"
"}\\n"
"shadow {\\n"
" x: 0.0\\n"
" y: 0.0\\n"
" z: 0.0\\n"
" w: 1.0\\n"
"}\\n"
"leading: 1.0\\n"
"tracking: 0.0\\n"
"pivot: PIVOT_CENTER\\n"
"blend_mode: BLEND_MODE_ALPHA\\n"
"line_break: false\\n"
"text: \\\"Not for the demo.\\\\n"
"\\\"\\n"
" \\\"Used to save preview texture.\\\\n"
"\\\"\\n"
" \\\"\\\"\\n"
"font: \\\"/demo/assets/fonts/vera_small.font\\\"\\n"
"material: \\\"/builtins/fonts/label.material\\\"\\n"
"\"\n"
" position {\n"
" x: 480.0\n"
" y: 396.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.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
embedded_instances {
id: "object"
data: "components {\n"
" id: \"trail_maker\"\n"
" component: \"/hyper_trails/trail_maker.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"
" properties {\n"
" id: \"segment_length_max\"\n"
" value: \"6.0\"\n"
" type: PROPERTY_TYPE_NUMBER\n"
" }\n"
" properties {\n"
" id: \"segment_length_min\"\n"
" value: \"6.0\"\n"
" type: PROPERTY_TYPE_NUMBER\n"
" }\n"
" properties {\n"
" id: \"fade_tail_alpha\"\n"
" value: \"12.0\"\n"
" type: PROPERTY_TYPE_NUMBER\n"
" }\n"
" properties {\n"
" id: \"shrink_tail_width\"\n"
" value: \"true\"\n"
" type: PROPERTY_TYPE_BOOLEAN\n"
" }\n"
"}\n"
"components {\n"
" id: \"data_texture_preview\"\n"
" component: \"/demo/data_texture_preview.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"
"embedded_components {\n"
" id: \"trail_model\"\n"
" type: \"model\"\n"
" data: \"mesh: \\\"/hyper_trails/models/trail_16.dae\\\"\\n"
"material: \\\"/hyper_trails/materials/trail.material\\\"\\n"
"textures: \\\"/hyper_trails/textures/data/texture0_1.png\\\"\\n"
"textures: \\\"/hyper_trails/textures/white.png\\\"\\n"
"skeleton: \\\"\\\"\\n"
"animations: \\\"\\\"\\n"
"default_animation: \\\"\\\"\\n"
"name: \\\"unnamed\\\"\\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: 379.0
y: 270.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
}
}
30 changes: 30 additions & 0 deletions demo/data_texture_preview.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

go.property("_position", vmath.vector3())

local function update_pos(self)
go.set_position(self._position)
end

function init(self)
msg.post(".", "acquire_input_focus")

self._position = go.get_position()

local w2 = sys.get_config("display.width") / 2
go.animate("#data_texture_preview", "_position.x", go.PLAYBACK_ONCE_FORWARD, w2, go.EASING_LINEAR, 1)

update_pos(self)
end

function final(self)
end

function update(self, dt)
update_pos(self)
end

function on_input(self, action_id, action)
if action_id == hash("write") and action.pressed then
write_texture = true
end
end
10 changes: 5 additions & 5 deletions demo/demo_main.collection
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ embedded_instances {
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" z: -0.1\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
Expand Down Expand Up @@ -624,7 +624,7 @@ embedded_instances {
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" z: -0.1\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
Expand Down Expand Up @@ -789,7 +789,7 @@ embedded_instances {
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" z: -0.1\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
Expand Down Expand Up @@ -944,7 +944,7 @@ embedded_instances {
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" z: -0.1\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
Expand Down Expand Up @@ -1048,7 +1048,7 @@ embedded_instances {
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" z: -0.1\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
Expand Down
4 changes: 4 additions & 0 deletions demo/input/game.input_binding
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ key_trigger {
input: KEY_RIGHT
action: "right"
}
key_trigger {
input: KEY_F10
action: "write"
}
mouse_trigger {
input: MOUSE_BUTTON_1
action: "click"
Expand Down
4 changes: 4 additions & 0 deletions game.project
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ high_dpi = 1
[project]
title = hyper_trails
version = 1.0
dependencies = https://github.com/britzl/defold-png/archive/1.2.1.zip

[library]
include_dirs = hyper_trails
Expand All @@ -23,3 +24,6 @@ game_binding = /demo/input/game.input_bindingc
scale = 0.01
gravity_y = -300.0

[graphics]
texture_profiles = /demo/assets/graphics/demo.texture_profiles

2 changes: 1 addition & 1 deletion hyper_trails/materials/trail.material
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ vertex_constants {
name: "uv_opts"
type: CONSTANT_TYPE_USER
value {
x: 0.0
x: 1.0
y: 0.0
z: 1.0
w: 0.0
Expand Down
Binary file modified hyper_trails/textures/data/texture0_1.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 hyper_trails/textures/data/texture0_10.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 modified hyper_trails/textures/data/texture0_2.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 modified hyper_trails/textures/data/texture0_3.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 modified hyper_trails/textures/data/texture0_4.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 modified hyper_trails/textures/data/texture0_5.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 modified hyper_trails/textures/data/texture0_6.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 hyper_trails/textures/data/texture0_7.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 hyper_trails/textures/data/texture0_8.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 hyper_trails/textures/data/texture0_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions hyper_trails/trail_maker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,30 @@ end

function M.update_texture(self)
resource.set_texture(self._resource_path, self._tex_header, self._tex_buffer)

-- DO NOT REMOVE
-- if write_texture then
-- print("Write data.png")
-- local rgba = buffer.get_bytes(self._tex_buffer, hash("rgba"))
-- local bytes = png.encode_rgba(rgba, self._tex_w, self._tex_h)
-- local f = io.open("hyper_trails/textures/data/texture.png", "wb")
-- f:write(bytes)
-- f:flush()
-- f:close()
-- -- + flip vertical!
-- write_texture = false
-- end
end

function on_input(self, action_id, action)
if action_id == hash("profile") and action.pressed then
msg.post("@system:", "toggle_profile")
elseif action_id == hash("physics") and action.pressed then
msg.post("@system:", "toggle_physics_debug")
end
end


function M.update_uv_opts(self)
if self.texture_tiling then
model.set_constant(self.trail_model_url, "uv_opts", vmath.vector4(1, 0, 1, 0))
Expand Down

0 comments on commit b63996d

Please sign in to comment.