Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions CreatureMeshBone.js
Original file line number Diff line number Diff line change
Expand Up @@ -3165,12 +3165,14 @@ Creature.prototype.LoadFromData = function(load_data)
this.uv_swap_packets = CreatureModuleUtils.FillSwapUVPacketMap(json_uv_swap_base);
}

/*
// Load Anchor Points
if("anchor_points_items" in load_data)
{
var anchor_point_base = load_data["anchor_points_items"];
this.anchor_point_map = CreatureModuleUtils.FillAnchorPointMap(anchor_point_base);
}
*/

};

Expand Down Expand Up @@ -3439,6 +3441,172 @@ CreatureMetaData.prototype.buildSkinSwapIndices = function(swap_name, bone_compo
return skin_swap_indices;
};

// CreatureMetaData
function CreatureMetaData()
{
this.skin_swaps = {};
};

CreatureMetaData.prototype.clear = function()
{
this.skin_swaps = {};
};

CreatureMetaData.prototype.buildSkinSwapIndices = function(swap_name, bone_composition)
{
var skin_swap_indices = null;
if(!(swap_name in this.skin_swaps))
{
skin_swap_indices = [];
return skin_swap_indices;
}

var swap_set = this.skin_swaps[swap_name];
var total_size = 0;
var regions_map = bone_composition.getRegionsMap();
for(var region_name in regions_map)
{
if(region_name in swap_set)
{
var cur_region = regions_map[region_name];
total_size += cur_region.getNumIndices();
}
}

skin_swap_indices = [];
var offset = 0;
for(var region_name in regions_map)
{
if(region_name in swap_set)
{
var cur_region = regions_map[region_name];
for(var j = 0; j < cur_region.getNumIndices(); j++)
{
skin_swap_indices.push(cur_region.getLocalIndex(j));
}

offset += cur_region.getNumIndices();
}
}

return skin_swap_indices;
};

Creature.prototype.SetAnchorPointEnabled = function(value) {
this.anchor_points_active = value;
};

Creature.prototype.GetPixelScaling = function(desired_x, desired_y)
{
// compute pixel scaling relative to mesh scaling
this.ComputeBoundaryMinMax();

var mesh_size_x = this.boundary_max[0] - this.boundary_min[0];
var mesh_size_y = this.boundary_max[1] - this.boundary_min[1];

var scale_x = 1.0 / mesh_size_x * desired_x;
var scale_y = 1.0 / mesh_size_y * desired_y;

return [scale_x, scale_y];
};

Creature.prototype.SetAnchorPoint = function(x, y, anim_clip_name_in) {
if (!anim_clip_name_in) {
anim_clip_name_in = 'default';
}

this.ComputeBoundaryMinMax();

var mesh_size_x = this.boundary_max[0] - this.boundary_min[0];
var mesh_size_y = this.boundary_max[1] - this.boundary_min[1];

var target_size_x = this.boundary_max[0];
var target_size_y = this.boundary_max[1];


if (x >= 0 && x !== null) {
target_size_x = (this.boundary_max[0] - (mesh_size_x * (x)));
}
else if (x < 0) {
target_size_x = -Math.abs(this.boundary_max[0] - (mesh_size_x * (Math.abs(x))));
}
else if (x === null) {
if (this.anchor_point_map && this.anchor_point_map[anim_clip_name_in]) {
target_size_x = this.anchor_point_map[anim_clip_name_in][0];
}
else {
target_size_x = 0;
}
}

if (y >= 0 && y !== null) {
target_size_y = (this.boundary_max[1] - (mesh_size_y * (y)));
}
else if (y < 0) {
target_size_y = -Math.abs(this.boundary_max[1] - (mesh_size_y * (Math.abs(y))));
}
else if (y === null) {
if (this.anchor_point_map && this.anchor_point_map[anim_clip_name_in]) {
target_size_y = this.anchor_point_map[anim_clip_name_in][1];
}
else {
target_size_y = 0;
}
}

var anchor_point_base = {
AnchorPoints: [
{
point: [target_size_x, target_size_y],
anim_clip_name: anim_clip_name_in
}
]
};

this.anchor_point_map = this.FillAnchorPointMap(anchor_point_base);
};


Creature.prototype.FillAnchorPointMap = function(json_obj)
{
var anchor_data_node = json_obj["AnchorPoints"];

ret_map = {};
for (var i = 0; i < anchor_data_node.length; i++)
{
var cur_node = anchor_data_node[i];
var cur_pt = this.ReadVector2JSON(cur_node, "point");
var cur_name = cur_node["anim_clip_name"];

ret_map[cur_name] = cur_pt;
}

return ret_map;
};


Creature.prototype.ReadVector2JSON = function(data, key)
{
var raw_array = this.getFloatArray(data[key]);
return vec2.fromValues(raw_array[0], raw_array[1]);
};

Creature.prototype.getFloatArray = function(raw_data)
{
return raw_data;
};


Creature.prototype.GetAnchorPoint = function(anim_clip_name_in)
{
if(anim_clip_name_in in this.anchor_point_map)
{
return this.anchor_point_map[anim_clip_name_in];
}

return vec2.fromValues(0, 0);
};

// CreatureManager
function CreatureManager(target_creature_in)
{
Expand Down