Beispiel #1
0
    /// <summary>
    /// 计算叶片面积(Unity单位)
    /// </summary>
    private double ComputeLeafArea(GameObject meshModel)
    {
        Texture2D texture = GameObjectOperation.GetTexture(meshModel.transform.GetChild(0).gameObject) as Texture2D;

        VisualPixelCount = 0;
        PixelCount       = texture.width * texture.height; //总像素个数

        //统计非透明像素个数
        for (int x = 0; x < texture.width; x++)
        {
            for (int y = 0; y < texture.height; y++)
            {
                if (texture.GetPixel(x, y).a > 0)
                {
                    VisualPixelCount++;
                }
            }
        }

        VisibilityRatio = VisualPixelCount * 1.0f / PixelCount;

        UniformMeshArea = GameObjectOperation.GetOrganArea(meshModel.transform.GetChild(0).gameObject) *
                          MaizeParams.SCALE * MaizeParams.SCALE; //㎡

        //获取该模型的面积,并乘以非透明像素所占百分比即得叶片面积
        return(UniformMeshArea * VisibilityRatio);
    }
 /// <summary>
 /// 计算面积
 /// </summary>
 private void ComputeArea(GameObject _Object)
 {
     /*
      * 计算模型的面积和叶面积
      * 用于后续辐射量的计算已经病虫害模拟等
      * 其中 MaizeParams.SCALE 将计算出的模型面积的单位从Unity中一单位转换成m
      */
     m_MeshArea            = GameObjectOperation.GetOrganArea(_Object) * MaizeParams.SCALE * MaizeParams.SCALE;
     m_LeafArea_Uninsected = m_MeshArea * VisibilityRatio;
 }