예제 #1
0
    private ArmorGeometryData Slice(ArmorGeometryData data)
    {
        int[] div_segments      = new int[data.size - 1];
        int   tot_segmentations = 0;

        for (int i = 0; i < data.size - 1; i++)
        {
            // spaces out everything evenly
            float ideal_dist = (data.radii[i] + data.radii[i + 1]) * Mathf.PI / data.resolution;
            float whole_d    = Vector3.Distance(data.keypos[i], data.keypos[i + 1]);
            div_segments[i]    = (int)Mathf.Round(whole_d / ideal_dist);
            tot_segmentations += div_segments[i];
        }

        ArmorGeometryData tot_data = new ArmorGeometryData(++tot_segmentations, data.resolution);

        int tot_idx = 0;

        for (int i = 0; i < data.size - 1; i++)
        {
            int div_seg = div_segments[i];
            for (int j = 0; j < div_seg; j++)
            {
                tot_data.keypos [tot_idx]        = data.keypos[i] + (data.keypos [i + 1] - data.keypos [i]) * j / div_seg;
                tot_data.radii [tot_idx]         = data.radii[i] + (data.radii [i + 1] - data.radii [i]) * j / div_seg;
                tot_data.thicknesses [tot_idx++] = data.thicknesses[i] + (data.thicknesses [i + 1] - data.thicknesses [i]) * j / div_seg;
            }
        }

        tot_data.keypos [tot_idx]      = data.keypos[data.size - 1];
        tot_data.radii [tot_idx]       = data.radii[data.size - 1];
        tot_data.thicknesses [tot_idx] = data.thicknesses[data.size - 1];
        return(tot_data);
    }
예제 #2
0
    public ArmorMesh(ArmorGeometryData p_geometrydata, Vector2Int p_texture_size)
    {
        texture_size      = p_texture_size;
        geometry          = Slice(p_geometrydata);
        original_geometry = p_geometrydata;

        armor_obj = new GameObject("armor");
        offset    = (p_geometrydata.keypos [0] + p_geometrydata.keypos [p_geometrydata.size - 1]) / 2;
        armor_obj.transform.position = offset;
        GetMesh();

        filter      = armor_obj.AddComponent <MeshFilter>();
        renderer    = armor_obj.AddComponent <MeshRenderer>();
        filter.mesh = Main;

        float max_rad = 0;

        for (int i = 0; i < geometry.size; i++)
        {
            if (geometry.radii [i] > max_rad)
            {
                max_rad = geometry.radii [i];
            }
        }
        dimensions.Set(max_rad, max_rad, Mathf.Abs((geometry.keypos [geometry.size - 1] - geometry.keypos [0]).z));
        mmPpixel.Set(dimensions.z * 1000 / p_texture_size.x, max_rad * tau * 1000 / p_texture_size.y);

        default_materials [0] = Resources.Load("materials/default_armor") as Material;
        default_materials [0].EnableKeyword("_NORMALMAP");
        visual_damage = Globals.impact_textures.GetTexture(ImpactTextures.TextureTemplate.default_armor, p_texture_size.x, p_texture_size.y);
        default_materials [0].SetTexture("_DammageTex", visual_damage);
        default_materials [1] = Resources.Load("materials/armor_inner") as Material;

        thickness_indicator = Resources.Load("materials/armor_thickness") as Material;
        renderer.materials  = default_materials;



        raw_thickness = GetRawThicknessTexture();
    }