public static void EnableSkinSwap( String swap_name_in, bool active, CreatureManager creature_manager, CreatureAsset creature_asset, ref bool skin_swap_active, ref string skin_swap_name, ref int[] skin_swap_triangles, ref List <int> final_skin_swap_indices) { skin_swap_active = active; if (!skin_swap_active) { skin_swap_name = ""; skin_swap_triangles = null; final_skin_swap_indices = null; } else { skin_swap_name = swap_name_in; if (creature_asset.creature_meta_data != null) { final_skin_swap_indices = new List <int>(); creature_asset.creature_meta_data.buildSkinSwapIndices( skin_swap_name, creature_manager.GetCreature().render_composition, final_skin_swap_indices); skin_swap_triangles = new int[final_skin_swap_indices.Count]; } } }
public void CreateBendPhysics(string anim_clip) { if (bend_physics_data != null) { bend_physics_data.clearPhysicsChain(); bend_physics_data = null; } CreatureManager cur_manager = creature_renderer.creature_manager; if (physics_container != null) { Destroy(physics_container); } cur_manager.RunAtTime(cur_manager.GetActiveAnimationStartTime()); physics_container = new GameObject("CreaturePhysicsContainer"); bend_physics_data = CreatureModule.CreaturePhysicsData.PhysicsUtil.CreateBendPhysicsChain( physics_container, creature_renderer.gameObject, cur_manager.GetCreature().render_composition, anim_clip, creature_renderer.creature_asset.physics_assets); }
public override void initData(CreatureManager creature_manager, CreatureAsset creature_asset) { var cur_char = creature_manager.GetCreature(); m_isValid = false; m_numIndices = cur_char.total_num_indices; }
public void setupMeshModifier(CreatureManager creature_manager) { getPackData(); var cur_char = creature_manager.GetCreature(); int max_indices_num = m_maxIndicesNum + cur_char.total_num_indices; mesh_modifier = new ParticlesMeshModifier( max_indices_num, (m_maxParticlesNum * 4) + cur_char.total_num_pts, this); mesh_modifier.m_maxIndice = max_indices_num; }
/// <summary> ///GetCreature 的测试 ///</summary> public void GetCreatureTestHelper <T>() where T : BaseCreature { CreatureManager <T> target = new CreatureManager <T>(); // TODO: 初始化为适当的值 long iCreatureId = 0; // TODO: 初始化为适当的值 T expected = default(T); // TODO: 初始化为适当的值 T actual; actual = target.GetCreature(iCreatureId); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
public override void update( CreatureManager creature_manager, bool counter_clockwise, ref Vector3[] vertices, ref Vector3[] normals, ref Vector4[] tangents, ref Color32[] colors, ref Vector2[] uvs, CreatureAsset creature_asset, float region_overlap_z_delta, bool skin_swap_active, string skin_swap_name, string active_animation_name, ref List <int> final_indices, ref List <int> final_skin_swap_indices, ref int[] triangles, ref int[] skin_swap_triangles) { m_isValid = false; var meta_data = creature_asset.creature_meta_data; if (meta_data == null) { // Meta Data not loaded return; } var cur_anim_name = creature_manager.GetActiveAnimationName(); if (!p_asset.m_ClipDataOffsets.ContainsKey(cur_anim_name)) { // No animation return; } // Copy over Character data first var cur_char = creature_manager.GetCreature(); int char_num_pts = cur_char.total_num_pts; var char_pts = cur_char.render_pts; CopyFloatsToVec3Array(char_pts, 0, char_pts.Count, ref vertices, 0); var char_uvs = cur_char.global_uvs; CopyFloatsToUVArray(char_uvs, 0, char_uvs.Count, ref uvs, 0); CopyBytesToColorArray(cur_char.render_colours, 0, cur_char.render_colours.Count, ref colors, 0); // Generate Particle data var pack_objs = p_asset.m_PackData; var clip_data = p_asset.m_ClipDataOffsets[cur_anim_name]; var cur_anim = creature_manager.GetAnimation(cur_anim_name); var delta_frames = (int)(Math.Round(creature_manager.getActualRuntime() - cur_anim.start_time)); int clip_runtime = Math.Min(Math.Max(0, delta_frames), clip_data.num_frames - 1); var frame_data = clip_data.particles_lookup[clip_runtime]; // Now start mesh generation int pt_offset = char_num_pts * 3; int uv_offset = char_num_pts * 2; int colors_offset = char_num_pts; int indices_offset = 0; m_numIndices = 0; var all_regions = cur_char.render_composition.getRegions(); // Go through each mesh region and check to see if we need to process it considering SkinSwaps as well float region_z = 0.0f; foreach (var cur_region in all_regions) { bool is_valid = true; if (skin_swap_active) { is_valid = (meta_data.skin_swaps[skin_swap_name].Contains(cur_region.getName())); } if (is_valid) { // Copy over base region indices CopyIntsToIntArray(cur_region.store_indices, cur_region.getStartIndex(), cur_region.getNumIndices(), ref final_indices, indices_offset); indices_offset += cur_region.getNumIndices(); // Set base region z for (int i = 0; i < cur_region.getNumIndices(); i++) { vertices[cur_region.store_indices[i + cur_region.getStartIndex()]].z = region_z; } int layer_idx = cur_region.getTagId(); if (frame_data.ContainsKey(cur_region.getTagId())) { // Process Particles for layer Start var layer_data = frame_data[cur_region.getTagId()]; for (int i = 0; i < layer_data.num_particles; i++) { int rel_offset = layer_data.offset + (i * 5); var p_pos_list = (object[])pack_objs[rel_offset]; float p_angle = (float)pack_objs[rel_offset + 1]; int p_sprite_idx = -(int)pack_objs[rel_offset + 2]; var p_size = (object[])pack_objs[rel_offset + 3]; var p_color = (object[])pack_objs[rel_offset + 4]; var p_sprite_uvs = meta_data.uvs_data[p_sprite_idx]; var b_uv0 = new Vector2(p_sprite_uvs.uv0.x, p_sprite_uvs.uv0.y); var b_uv1 = new Vector2(p_sprite_uvs.uv1.x, p_sprite_uvs.uv1.y); var b_color = new Vector4((float)p_color[0], (float)p_color[1], (float)p_color[2], (float)p_color[3]); region_z += region_overlap_z_delta * 0.1f; if (p_pos_list.Length == 2) { // No Trail int idx_pt_offset = pt_offset / 3; var b_pos = new Vector2((float)p_pos_list[0], (float)p_pos_list[1]); setVertData( b_pos + rotVec2D(new Vector2(-(float)p_size[0], -(float)p_size[1]), p_angle), region_z, new Vector2(b_uv0.x, b_uv0.y), b_color, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); setVertData( b_pos + rotVec2D(new Vector2(-(float)p_size[0], (float)p_size[1]), p_angle), region_z, new Vector2(b_uv0.x, b_uv1.y), b_color, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); setVertData( b_pos + rotVec2D(new Vector2((float)p_size[0], (float)p_size[1]), p_angle), region_z, new Vector2(b_uv1.x, b_uv1.y), b_color, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); setVertData( b_pos + rotVec2D(new Vector2((float)p_size[0], -(float)p_size[1]), p_angle), region_z, new Vector2(b_uv1.x, b_uv0.y), b_color, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); // Indices setIndiceData(ref indices_offset, idx_pt_offset + 2, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 1, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 2, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 3, ref final_indices); } else if (p_pos_list.Length > 2) { // With Trail int idx_pt_offset = pt_offset / 3; int trail_num = p_pos_list.Length / 2; var dir_p = new Vector2(0, 0); var rot_p = new Vector2(0, 0); var diff_p = new Vector2(0, 0); var delta_uvs = b_uv1 - b_uv0; for (int j = 0; j < trail_num; j++) { var p1 = GetParticlePos(p_pos_list, j); if (j < (trail_num - 1)) { diff_p = GetParticlePos(p_pos_list, j + 1) - GetParticlePos(p_pos_list, j); } else { diff_p = GetParticlePos(p_pos_list, trail_num - 1) - GetParticlePos(p_pos_list, trail_num - 2); } if (diff_p.magnitude > 0) { dir_p = diff_p.normalized; } rot_p = rotVec2D_90(dir_p) * (float)p_size[1]; var cur_uv = new Vector2(0, 0); float sub_alpha = Math.Min(1.0f / (float)(trail_num) * (float)(j), 1.0f); if (j < (trail_num - 1)) { cur_uv.x = delta_uvs.x / (float)(trail_num) * (float)(j) + b_uv0.x; cur_uv.y = b_uv0.y; setVertData( p1 + rot_p, region_z, cur_uv, b_color * sub_alpha, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); cur_uv.y = b_uv1.y; setVertData( p1 - rot_p, region_z, cur_uv, b_color * sub_alpha, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); } else { // Final trail pos cur_uv.x = b_uv1.x; cur_uv.y = b_uv0.y; setVertData( p1 + diff_p + rot_p, region_z, cur_uv, b_color * sub_alpha, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); cur_uv.y = b_uv1.y; setVertData( p1 + diff_p + rot_p, region_z, cur_uv, b_color * sub_alpha, ref pt_offset, ref uv_offset, ref colors_offset, ref vertices, ref uvs, ref colors ); } } // Indices int delta_trail_indices = 0; for (int j = 0; j < trail_num - 1; j++) { setIndiceData(ref indices_offset, idx_pt_offset + 2 + delta_trail_indices, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + delta_trail_indices, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 1 + delta_trail_indices, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 2 + delta_trail_indices, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 1 + delta_trail_indices, ref final_indices); setIndiceData(ref indices_offset, idx_pt_offset + 3 + delta_trail_indices, ref final_indices); delta_trail_indices += 2; } } } // Process Particles for layer End } } region_z += region_overlap_z_delta; } m_numIndices = indices_offset; m_isValid = true; }