Exemplo n.º 1
0
    public void CreateRenderingData()
    {
        if (switch_region.Length <= 0)
        {
            return;
        }

        var target_creature = creature_manager.target_creature;

        MeshBoneUtil.MeshRenderBoneComposition render_composition =
            target_creature.render_composition;
        var regions_map = render_composition.getRegionsMap();

        if (regions_map.ContainsKey(switch_region) == false)
        {
            return;
        }

        var cur_region = regions_map [switch_region];

        vertices  = new Vector3[cur_region.getNumPts()];
        colors    = new Color32[cur_region.getNumPts()];
        uvs       = new Vector2[cur_region.getNumPts()];
        triangles = new int[cur_region.getNumIndices()];
    }
Exemplo n.º 2
0
    public void UpdateRenderingData()
    {
        if (switch_region.Length <= 0)
        {
            return;
        }

        if (target_switch_name == null)
        {
            return;
        }

        if (switch_items.ContainsKey(target_switch_name) == false)
        {
            return;
        }

        var target_creature = creature_manager.target_creature;

        MeshBoneUtil.MeshRenderBoneComposition render_composition =
            target_creature.render_composition;
        var regions_map = render_composition.getRegionsMap();

        if (regions_map.ContainsKey(switch_region) == false)
        {
            return;
        }

        var          cur_region = regions_map [switch_region];
        List <float> render_pts = creature_manager.target_creature.render_pts;
        List <float> render_uvs = creature_manager.target_creature.global_uvs;
        //List<byte> render_colors = creature_manager.target_creature.render_colours;

        int pt_index    = cur_region.getStartPtIndex() * 3;
        int uv_index    = cur_region.getStartPtIndex() * 2;
        int color_index = cur_region.getStartPtIndex() * 4;

        var   cur_switch_item = switch_items [target_switch_name];
        float rel_u_width     = switch_max_uv.x - switch_min_uv.x;
        float rel_v_height    = switch_max_uv.y - switch_min_uv.y;

        for (int i = 0; i < vertices.Length; i++)
        {
            vertices[i].x = render_pts[pt_index + 0];
            vertices[i].y = render_pts[pt_index + 1];
            vertices[i].z = render_pts[pt_index + 2];

            float read_u = render_uvs[uv_index + 0];
            float read_v = render_uvs[uv_index + 1];

            // transform to new texture space
            float rel_u = (read_u - switch_min_uv.x) / rel_u_width;
            float rel_v = (read_v - switch_min_uv.y) / rel_v_height;
            rel_u = rel_u * cur_switch_item.u_width + cur_switch_item.uv.x;
            rel_v = rel_v * cur_switch_item.v_height + cur_switch_item.uv.y;

            uvs[i].x = rel_u;
            uvs[i].y = 1.0f - rel_v;

            colors[i].r = 255;
            colors[i].g = 255;
            colors[i].b = 255;
            colors[i].a = 255;

            pt_index    += 3;
            uv_index    += 2;
            color_index += 4;
        }

        List <int> render_indices = creature_manager.target_creature.global_indices;

        //int start_lookup = render_indices [cur_region.getStartIndex ()];

        for (int i = 0; i < cur_region.getNumIndices(); i++)
        {
            int lookup = render_indices[cur_region.getStartIndex() + i];
            triangles[i] = lookup - min_indice;
        }

        active_mesh.vertices  = vertices;
        active_mesh.colors32  = colors;
        active_mesh.triangles = triangles;
        active_mesh.uv        = uvs;
    }
Exemplo n.º 3
0
    public void InitData()
    {
        if (creature_renderer)
        {
            // init the render data
            CreatureManager ref_manager = creature_renderer.creature_asset.GetCreatureManager();
            creature_manager            = new CreatureManager(ref_manager.target_creature);
            creature_manager.animations = ref_manager.animations;

            var target_creature = creature_manager.target_creature;
            MeshBoneUtil.MeshRenderBoneComposition render_composition =
                target_creature.render_composition;
            var regions_map = render_composition.getRegionsMap();
            if (regions_map.ContainsKey(switch_region) == false)
            {
                return;
            }

            var cur_region = regions_map [switch_region];
            int uv_index   = cur_region.getStartPtIndex() * 2;
            var global_uvs = target_creature.global_uvs;

            switch_min_uv = new Vector2(global_uvs[uv_index], global_uvs[uv_index + 1]);
            switch_max_uv = new Vector2(switch_min_uv.x, switch_min_uv.y);

            for (int i = 0; i < cur_region.getNumPts(); i++)
            {
                float cur_u = global_uvs[uv_index];
                float cur_v = global_uvs[uv_index + 1];

                if (cur_u < switch_min_uv.x)
                {
                    switch_min_uv.x = cur_u;
                }
                else if (cur_u > switch_max_uv.x)
                {
                    switch_max_uv.x = cur_u;
                }

                if (cur_v < switch_min_uv.y)
                {
                    switch_min_uv.y = cur_v;
                }
                else if (cur_v > switch_max_uv.y)
                {
                    switch_max_uv.y = cur_v;
                }

                uv_index += 2;
            }

            List <int> render_indices = creature_manager.target_creature.global_indices;
            min_indice = render_indices[cur_region.getStartIndex()];
            for (int i = 0; i < cur_region.getNumIndices(); i++)
            {
                int cur_indice = render_indices[cur_region.getStartIndex() + i];
                if (cur_indice < min_indice)
                {
                    min_indice = cur_indice;
                }
            }
        }
    }