Skip to content

Commit

Permalink
Fully functional Real-time Morph Targets + Owl Head Turning Sample Pr…
Browse files Browse the repository at this point in the history
…oject
  • Loading branch information
kestrelm committed Feb 22, 2018
1 parent ac693e0 commit 13cc3f0
Show file tree
Hide file tree
Showing 26 changed files with 624 additions and 18 deletions.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,49 @@ You can also add your own **Custom Skin Swap** at runtime by calling:
This adds a new custom **Skin Swap** with the specified name and item list into the system. Similarly, you can remove a **Skin Swap** by calling **remove_skinswap(name)**. To disable **Skin Swap** and return back to normal playback mode, call:

self.disable_skinswap()


### 5. Morph Targets

Real-time Morph Targets enable you to achieve some sophistcated effecs, including the ability to have user-controllable front facing characters that will turn their Heads/eyes towards a desired target point. Please read up on [Morph Targets](https://www.kestrelmoon.com/creaturedocs/Animation/Morph_Targets_For_GameEngines.html) to learn how to setup **Morph Targets** in the Creature Animation Tool first before continuing.

**Morph Targets** data are stored in the **MetaData** file so make sure you have connected/setup the **MetaData** slot of the **CreatureGodot** node before you start.

To activate **Morph Targets**, do the following:

self.set_morph_targets_active(true)

Then at each update step, make sure you point your morph targets to a target point with a source base point and radius:

self.set_morph_targets_pt(target_pos, src_pos, radius)

The full demo sample ( **An Owl Head turning character, Artwork by David Revoy, CC-BY-SA**) has an Owl Character that will look at a target tracker polygon. The full simple example looks like this:

extends CreatureGodot

func _ready():
set_process(true)
self.set_morph_targets_active(true)
pass

func _process(delta):
var poly = get_node("../Polygon2D")
self.set_morph_targets_pt(poly.global_position, self.global_position - Vector2(-10, 200), 10.0)
self.update_animation(delta)
func _input(event):
var poly = get_node("../Polygon2D")
if(event is InputEventKey):
if(event.scancode == KEY_A):
poly.position.x -= 10
elif(event.scancode == KEY_D):
poly.position.x += 10
elif(event.scancode == KEY_W):
poly.position.y -= 10
elif(event.scancode == KEY_S):
poly.position.y += 10

Here, we have a polygon node object that is driven by the W, A, S, D keys. The owl character which is of **CreatureGodot** node type uses **Morph Targets** to perform a head-turning action tracking the position of the polygon. Play around with the provided sample to learn more about this powerful functionality.

### Animation Functions
**set_mirror_y(flag_in)** - Sets a boolean to flip the character along the Y axis
Expand Down
16 changes: 8 additions & 8 deletions creaturegodot3/Godot3Demo/CreatureGodot.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ light_mode = 0
[node name="Node2D" type="Node2D"]

material = SubResource( 1 )
position = Vector2( 592.443, 350.698 )
position = Vector2( 588.833, 349.796 )
scale = Vector2( 10.9637, 11.0336 )
_sections_unfolded = [ "Material", "Transform" ]

[node name="CreatureGodotHorseman" type="CreatureGodot" parent="."]
[node name="CreatureGodotHorseman" type="CreatureGodot" parent="." index="0"]

position = Vector2( -2.41241, 1.08478 )
scale = Vector2( 2.27676, 2.35959 )
Expand All @@ -39,9 +39,9 @@ texture/texture = ExtResource( 1 )
script = ExtResource( 2 )
_sections_unfolded = [ "texture" ]

[node name="CreatureGodotSwap" type="CreatureGodot" parent="."]
[node name="CreatureGodotSwap" type="CreatureGodot" parent="." index="1"]

position = Vector2( 18.8114, -0.479858 )
position = Vector2( 18.7371, -0.479858 )
scale = Vector2( 2.99933, 2.73204 )
anim_name = "default"
anim_frame = 0.0
Expand All @@ -55,7 +55,7 @@ texture/texture = ExtResource( 3 )
script = ExtResource( 4 )
_sections_unfolded = [ "texture" ]

[node name="CreatureGodotFox" type="CreatureGodot" parent="."]
[node name="CreatureGodotFox" type="CreatureGodot" parent="." index="2"]

position = Vector2( -25.5196, 5.66517 )
scale = Vector2( 1.48269, 1.51808 )
Expand All @@ -71,7 +71,7 @@ texture/texture = ExtResource( 5 )
script = ExtResource( 6 )
_sections_unfolded = [ "texture" ]

[node name="CreatureGodotBat" type="CreatureGodot" parent="."]
[node name="CreatureGodotBat" type="CreatureGodot" parent="." index="3"]

position = Vector2( -32.2712, -9.23989 )
scale = Vector2( 1.14568, 1.21867 )
Expand All @@ -87,7 +87,7 @@ texture/texture = ExtResource( 7 )
script = ExtResource( 8 )
_sections_unfolded = [ "texture" ]

[node name="TextureRect" type="TextureRect" parent="."]
[node name="TextureRect" type="TextureRect" parent="." index="4"]

anchor_left = 0.0
anchor_top = 0.0
Expand All @@ -100,8 +100,8 @@ margin_bottom = 22.0
grow_horizontal = 0
grow_vertical = 0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
texture = ExtResource( 9 )
Expand Down
Binary file modified creaturegodot3/Godot3Demo/CreatureGodotHorse.vs
Binary file not shown.
Binary file added creaturegodot3/Godot3Demo/Roboto-Regular.ttf
Binary file not shown.
8 changes: 8 additions & 0 deletions creaturegodot3/Godot3Demo/bat.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ importer="texture"
type="StreamTexture"
path="res://.import/bat.png-8c5f11e0110a5921c6efd8f18e634996.stex"

[deps]

source_file="res://bat.png"
source_md5="f47b89ff17b8d04a84f8956a5be14027"

dest_files=[ "res://.import/bat.png-8c5f11e0110a5921c6efd8f18e634996.stex" ]
dest_md5="4b51b0087f5ba239f0767df84efa0e0c"

[params]

compress/mode=0
Expand Down
4 changes: 3 additions & 1 deletion creaturegodot3/Godot3Demo/default_env.tres
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ ssao_intensity2 = 1.0
ssao_bias = 0.01
ssao_light_affect = 0.0
ssao_color = Color( 0, 0, 0, 1 )
ssao_blur = true
ssao_quality = 0
ssao_blur = 1
ssao_edge_sharpness = 4.0
dof_blur_far_enabled = false
dof_blur_far_distance = 10.0
dof_blur_far_transition = 5.0
Expand Down
19 changes: 19 additions & 0 deletions creaturegodot3/Godot3Demo/export_presets.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[preset.0]

custom_features=""
exclude_filter=""
export_filter="all_resources"
include_filter="*.json, *.mdata"
name="Windows Desktop"
patch_list=PoolStringArray( )
platform="Windows Desktop"
runnable=true

[preset.0.options]

binary_format/64_bits=true
custom_template/debug=""
custom_template/release=""
texture_format/etc=false
texture_format/etc2=false
texture_format/s3tc=true
8 changes: 8 additions & 0 deletions creaturegodot3/Godot3Demo/fox.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ importer="texture"
type="StreamTexture"
path="res://.import/fox.png-9d81b9bd85810e07c626f6b5830ddd11.stex"

[deps]

source_file="res://fox.png"
source_md5="e7b9f917b3227036427e04d4ac9e342b"

dest_files=[ "res://.import/fox.png-9d81b9bd85810e07c626f6b5830ddd11.stex" ]
dest_md5="ae61323867dfb9c15f78a682a32ef050"

[params]

compress/mode=0
Expand Down
8 changes: 8 additions & 0 deletions creaturegodot3/Godot3Demo/horseman.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ importer="texture"
type="StreamTexture"
path="res://.import/horseman.png-98b7704c75351a5f80042c2c29bb915b.stex"

[deps]

source_file="res://horseman.png"
source_md5="cef7cd507e3e42e3ec4e5312d4550e2d"

dest_files=[ "res://.import/horseman.png-98b7704c75351a5f80042c2c29bb915b.stex" ]
dest_md5="9a4eed289bc4e678cde9c68c916d2e9f"

[params]

compress/mode=0
Expand Down
8 changes: 8 additions & 0 deletions creaturegodot3/Godot3Demo/icon.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"

[deps]

source_file="res://icon.png"
source_md5="ae7e641067601e2184afcade49abd283"

dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
dest_md5="84511021bbc8c9d37c7f0f4d181de883"

[params]

compress/mode=0
Expand Down
25 changes: 25 additions & 0 deletions creaturegodot3/Godot3Demo/morphTest.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extends CreatureGodot

func _ready():
set_process(true)
self.set_morph_targets_active(true)
pass

func _process(delta):
var poly = get_node("../Polygon2D")
self.set_morph_targets_pt(poly.global_position, self.global_position - Vector2(-10, 200), 10.0)

self.update_animation(delta)

func _input(event):
var poly = get_node("../Polygon2D")
if(event is InputEventKey):
if(event.scancode == KEY_A):
poly.position.x -= 10
elif(event.scancode == KEY_D):
poly.position.x += 10
elif(event.scancode == KEY_W):
poly.position.y -= 10
elif(event.scancode == KEY_S):
poly.position.y += 10

131 changes: 131 additions & 0 deletions creaturegodot3/Godot3Demo/morphTest.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://owlMorph_character_img.png" type="Texture" id=1]
[ext_resource path="res://morphTest.gd" type="Script" id=2]
[ext_resource path="res://robotoFont2.tres" type="DynamicFont" id=3]
[ext_resource path="res://robotoFont.tres" type="DynamicFont" id=4]

[node name="Node2D" type="Node2D" index="0"]

[node name="CreatureGodot" type="CreatureGodot" parent="." index="0"]

position = Vector2( 544.092, 512.927 )
scale = Vector2( 50, 50 )
anim_name = "default"
anim_frame = 0.0
anim_speed = 2.0
asset_filename = "res://owlMorph_character_data.json"
metadata_filename = "res://owlMorph_character_meta.mdata"
mirror_y = false
color = Color( 1, 1, 1, 1 )
offset = Vector2( 0, 0 )
texture/texture = ExtResource( 1 )
script = ExtResource( 2 )
_sections_unfolded = [ "Transform", "texture" ]

[node name="Polygon2D" type="Polygon2D" parent="." index="1"]

position = Vector2( 565.158, 235.703 )
scale = Vector2( 0.1276, 0.1025 )
polygon = PoolVector2Array( -1.159, 9.7355, 95.7115, 101.596, -16.1907, 163.392, -54.6049, 79.8832 )
uv = PoolVector2Array( )
color = Color( 1, 0.890625, 0, 1 )
vertex_colors = PoolColorArray( )
offset = Vector2( 0, 0 )
antialiased = true
texture = null
texture_offset = Vector2( 0, 0 )
texture_scale = Vector2( 1, 1 )
texture_rotation_degrees = 0.0
invert_enable = false
invert_border = 100.0

[node name="Label2" type="Label" parent="." index="2"]

anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 610.0
margin_top = 19.0
margin_right = 1003.0
margin_bottom = 99.0
rect_pivot_offset = Vector2( 0, 0 )
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
custom_fonts/font = ExtResource( 3 )
custom_colors/font_color = Color( 1, 0.84375, 0, 1 )
custom_colors/font_color_shadow = Color( 0, 0, 0, 1 )
text = "W, A, S, D Keys move Head Tracker Polygon"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Rect", "custom_colors", "custom_fonts" ]

[node name="Label3" type="Label" parent="." index="3"]

anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 646.0
margin_top = 47.0
margin_right = 970.0
margin_bottom = 79.0
rect_pivot_offset = Vector2( 0, 0 )
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
custom_fonts/font = ExtResource( 3 )
custom_colors/font_color = Color( 1, 0.84375, 0, 1 )
custom_colors/font_color_shadow = Color( 0, 0, 0, 1 )
text = "Owl Head Turns + Tracks Polyygon"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Rect", "custom_colors", "custom_fonts" ]

[node name="ColorRect" type="ColorRect" parent="." index="4"]

anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 506.0
margin_right = 1028.0
margin_bottom = 581.0
rect_pivot_offset = Vector2( 0, 0 )
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
color = Color( 0.0664063, 0.0542145, 0.0542145, 0.392157 )

[node name="Label" type="Label" parent="." index="5"]

anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 131.0
margin_top = 514.0
margin_right = 1220.0
margin_bottom = 737.0
rect_pivot_offset = Vector2( 0, 0 )
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
custom_fonts/font = ExtResource( 4 )
custom_colors/font_color = Color( 0.890625, 0.890625, 0.890625, 1 )
custom_colors/font_color_shadow = Color( 0, 0, 0, 1 )
text = "Creature Real-time Morph Targets Demo"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Rect", "custom_colors", "custom_fonts" ]


1 change: 1 addition & 0 deletions creaturegodot3/Godot3Demo/owlMorph_character_data.json

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions creaturegodot3/Godot3Demo/owlMorph_character_img.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/owlMorph_character_img.png-164d16786b507d055c83ca953317b0e2.stex"

[deps]

source_file="res://owlMorph_character_img.png"
source_md5="c10e8a580960e6e1b39821039355bcff"

dest_files=[ "res://.import/owlMorph_character_img.png-164d16786b507d055c83ca953317b0e2.stex" ]
dest_md5="62e31d8c747ddc1656cebb13923e7a7d"

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Loading

0 comments on commit 13cc3f0

Please sign in to comment.