@@ -6486,10 +6486,74 @@ function Creature(load_data)
6486
6486
this . boundary_indices = [ ] ;
6487
6487
this . boundary_min = vec2 . create ( ) ;
6488
6488
this . boundary_max = vec2 . create ( ) ;
6489
+ this . anchor_point_map = { } ;
6490
+ this . anchor_points_active = false ;
6489
6491
6490
6492
this . LoadFromData ( load_data ) ;
6491
6493
} ;
6492
6494
6495
+ // experimental - must enable - disabled by default
6496
+ Creature . prototype . SetAnchorPointEnabled = function ( value ) {
6497
+ this . anchor_points_active = value ;
6498
+ } ;
6499
+
6500
+ Creature . prototype . GetPixelScaling = function ( desired_x , desired_y )
6501
+ {
6502
+ // compute pixel scaling relative to mesh scaling
6503
+ this . ComputeBoundaryMinMax ( ) ;
6504
+
6505
+ var mesh_size_x = this . boundary_max [ 0 ] - this . boundary_min [ 0 ] ;
6506
+ var mesh_size_y = this . boundary_max [ 1 ] - this . boundary_min [ 1 ] ;
6507
+
6508
+ var scale_x = 1.0 / mesh_size_x * desired_x ;
6509
+ var scale_y = 1.0 / mesh_size_y * desired_y ;
6510
+
6511
+ return [ scale_x , scale_y ] ;
6512
+ } ;
6513
+
6514
+ Creature . prototype . SetAnchorPoint = function ( x , y , anim_clip_name_in ) {
6515
+ if ( ! anim_clip_name_in ) {
6516
+ anim_clip_name_in = 'default' ;
6517
+ }
6518
+
6519
+ this . ComputeBoundaryMinMax ( ) ;
6520
+
6521
+ var mesh_size_x = this . boundary_max [ 0 ] - this . boundary_min [ 0 ] ;
6522
+ var mesh_size_y = this . boundary_max [ 1 ] - this . boundary_min [ 1 ] ;
6523
+
6524
+ var target_size_x = this . boundary_max [ 0 ] ;
6525
+ var target_size_y = this . boundary_max [ 1 ] ;
6526
+
6527
+ if ( x !== 0 ) {
6528
+ target_size_x = this . boundary_max [ 0 ] - ( mesh_size_x * ( x ) ) ;
6529
+ }
6530
+
6531
+ if ( y !== 0 ) {
6532
+ target_size_y = this . boundary_max [ 1 ] - ( mesh_size_y * ( y ) ) ;
6533
+ }
6534
+
6535
+ var anchor_point_base = {
6536
+ AnchorPoints : [
6537
+ {
6538
+ point : [ target_size_x , target_size_y ] ,
6539
+ anim_clip_name : anim_clip_name_in
6540
+ }
6541
+ ]
6542
+ } ;
6543
+
6544
+ this . anchor_point_map = this . FillAnchorPointMap ( anchor_point_base ) ;
6545
+ } ;
6546
+
6547
+ Creature . prototype . GetAnchorPoint = function ( anim_clip_name_in )
6548
+ {
6549
+ if ( anim_clip_name_in in this . anchor_point_map )
6550
+ {
6551
+ return this . anchor_point_map [ anim_clip_name_in ] ;
6552
+ }
6553
+
6554
+ return vec2 . fromValues ( 0 , 0 ) ;
6555
+ } ;
6556
+
6493
6557
// Fills entire mesh with (r,g,b,a) colours
6494
6558
Creature . prototype . FillRenderColours = function ( r , g , b , a )
6495
6559
{
@@ -6652,8 +6716,45 @@ Creature.prototype.LoadFromData = function(load_data)
6652
6716
}
6653
6717
6654
6718
this . render_composition . resetToWorldRestPts ( ) ;
6719
+
6720
+ // Load Anchor Points
6721
+ if ( "anchor_points_items" in load_data )
6722
+ {
6723
+ var anchor_point_base = load_data [ "anchor_points_items" ] ;
6724
+ this . anchor_point_map = this . FillAnchorPointMap ( anchor_point_base ) ;
6725
+ }
6655
6726
} ;
6656
6727
6728
+ Creature . prototype . FillAnchorPointMap = function ( json_obj )
6729
+ {
6730
+ var anchor_data_node = json_obj [ "AnchorPoints" ] ;
6731
+
6732
+ ret_map = { } ;
6733
+ for ( var i = 0 ; i < anchor_data_node . length ; i ++ )
6734
+ {
6735
+ var cur_node = anchor_data_node [ i ] ;
6736
+ var cur_pt = this . ReadVector2JSON ( cur_node , "point" ) ;
6737
+ var cur_name = cur_node [ "anim_clip_name" ] ;
6738
+
6739
+ ret_map [ cur_name ] = cur_pt ;
6740
+ }
6741
+
6742
+ return ret_map ;
6743
+ } ;
6744
+
6745
+
6746
+ Creature . prototype . ReadVector2JSON = function ( data , key )
6747
+ {
6748
+ var raw_array = this . getFloatArray ( data [ key ] ) ;
6749
+ return vec2 . fromValues ( raw_array [ 0 ] , raw_array [ 1 ] ) ;
6750
+ } ;
6751
+
6752
+ Creature . prototype . getFloatArray = function ( raw_data )
6753
+ {
6754
+ return raw_data ;
6755
+ } ;
6756
+
6757
+
6657
6758
// CreatureAnimation
6658
6759
function CreatureAnimation ( load_data , name_in )
6659
6760
{
@@ -6667,6 +6768,28 @@ function CreatureAnimation(load_data, name_in)
6667
6768
this . LoadFromData ( name_in , load_data ) ;
6668
6769
} ;
6669
6770
6771
+ CreatureManager . prototype . AlterBonesByAnchor = function ( bones_map , animation_name_in )
6772
+ {
6773
+ if ( this . target_creature . anchor_points_active == false )
6774
+ {
6775
+ return ;
6776
+ }
6777
+
6778
+ var anchor_point = this . target_creature . GetAnchorPoint ( animation_name_in ) ;
6779
+ for ( var cur_bone_key in bones_map )
6780
+ {
6781
+ var cur_bone = bones_map [ cur_bone_key ] ;
6782
+ var start_pt = cur_bone . getWorldStartPt ( ) ;
6783
+ var end_pt = cur_bone . getWorldEndPt ( ) ;
6784
+
6785
+ start_pt = vec3 . subtract ( start_pt , start_pt , vec3 . fromValues ( anchor_point [ 0 ] , anchor_point [ 1 ] , 0 ) ) ;
6786
+ end_pt = vec3 . subtract ( end_pt , end_pt , vec3 . fromValues ( anchor_point [ 0 ] , anchor_point [ 1 ] , 0 ) ) ;
6787
+
6788
+ cur_bone . setWorldStartPt ( start_pt ) ;
6789
+ cur_bone . setWorldEndPt ( end_pt ) ;
6790
+ }
6791
+ } ;
6792
+
6670
6793
CreatureAnimation . prototype . LoadFromData = function ( name_in , load_data )
6671
6794
{
6672
6795
var json_anim_base = load_data [ "animation" ] ;
@@ -6783,7 +6906,7 @@ CreatureManager.prototype.CreateAllAnimations = function(load_data)
6783
6906
this . CreateAnimation ( load_data , cur_name ) ;
6784
6907
}
6785
6908
6786
- this . SetActiveAnimationName ( all_animation_names . get ( 0 ) ) ;
6909
+ this . SetActiveAnimationName ( all_animation_names [ 0 ] ) ;
6787
6910
} ;
6788
6911
6789
6912
// Add an animation
@@ -7162,6 +7285,8 @@ CreatureManager.prototype.PoseCreature = function(animation_name_in, target_pts)
7162
7285
7163
7286
bone_cache_manager . retrieveValuesAtTime ( this . getRunTime ( ) ,
7164
7287
bones_map ) ;
7288
+
7289
+ this . AlterBonesByAnchor ( bones_map , animation_name_in ) ;
7165
7290
7166
7291
if ( this . bones_override_callback != null )
7167
7292
{
0 commit comments