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);
    }
    private void LeafMorphologicalInheritance()
    {
        OrganMorphologicalInheritance();    //基类中的数据继承

        LeafIndex curLeafIndex = CurIndex as LeafIndex;
        LeafIndex preLeafIndex = PreIndex as LeafIndex;

        curLeafIndex.Width               = preLeafIndex.Width;
        curLeafIndex.LeafArea            = preLeafIndex.LeafArea;
        curLeafIndex.LeafArea_Uninsected = preLeafIndex.LeafArea_Uninsected;

        curLeafIndex.LimitRatio          = preLeafIndex.LimitRatio;
        curLeafIndex.Texture_PreDay      = GameObjectOperation.GetTexture(preLeafIndex.Belong);
        curLeafIndex.MeshHashCode_PreDay = preLeafIndex.LeafMesh.GetHashCode();
    }
Beispiel #3
0
    private void ClearAllWormholeTex()
    {
        if (m_listOrganModels == null)
        {
            return;
        }

        foreach (GameObject OrganModel in m_listOrganModels)
        {
            Texture tex = GameObjectOperation.GetTexture(OrganModel);

            if (tex.name == "Wormhole Texture")
            {
                GameObjectOperation.ClearTexture(OrganModel);
                GameObject.DestroyObject(tex);
            }
        }
    }
Beispiel #4
0
    /// <summary>
    /// 射线与三角形求交(有纹理)
    /// </summary>
    public static bool IntersectRayTriangleWithTexture(Ray _Ray, Triangle _Triangle, out float Distance)
    {
        float u, v;

        if (!IntersectRayTriangleWithoutTexture(_Ray, _Triangle, out u, out v, out Distance))
        {
            return(false);                                                                       //射线与面片无交点
        }
        Vector2 UV = _Triangle.GetUV(u, v);                                                      //获取该交点的UV坐标

        Texture2D Texture = GameObjectOperation.GetTexture(_Triangle.Index.Belong) as Texture2D; //获取纹理

        if (Texture.GetPixelBilinear(UV.x, UV.y).a > 0f)                                         //获取该点的透明度,如果大于0.5则有碰撞
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
    private Texture GetWormholeTex(double actualInsectIntake, out int threshold)
    {
        /*
         * 阈值
         * 用于后续关键帧动画中虫洞的模拟
         * 当为0时表示虫洞未发生变化
         */
        threshold = 0;

        /*
         * 存在的各种情况:
         * 1、该叶片不受病虫影响
         *     1.1、该叶片原先无病虫害,故现在也无病虫害,即叶面积(LeafArea)与未受病虫害的叶面积(LeafArea_Uninsected)相等
         *          故该模型的纹理无需替换
         *     1.2、该叶片原先有病虫害,再分两种情况:
         *          1.2.1、与昨日的模型相同,即今日模型的哈希值与昨日模型的哈希值相同,故叶片形态、纹理与昨日相同
         *          故直接调用昨日模型的纹理即可
         *          1.2.2、与昨日的模型不同,即该叶片发育到不同的阶段(成熟或衰老),故调用的纹理与昨日不同
         *          故重新生成虫洞纹理
         * 2、该叶片受病虫影响
         *    形态不同,故直接重新生成虫洞纹理
         */
        if (LeafArea == LeafArea_Uninsected)
        {
            return(null);
        }
        else if (Texture_PreDay != null &&
                 actualInsectIntake <= 0 && LeafMesh.GetHashCode() == MeshHashCode_PreDay)
        {
            return(Texture_PreDay);
        }
        else
        {
            if (Texture_PreDay != null && Texture_PreDay.name == "Wormhole Texture")
            {
                if (LScene.GetInstance().HaveAnimator)
                {
                    GameObjectOperation.DestroyTexWithoutAnimation(Texture_PreDay);
                }
                else
                {
                    GameObject.Destroy(Texture_PreDay);
                }

                Texture_PreDay = null;
            }

            Texture leafTex = GameObjectOperation.GetTexture(Belong);

            Texture wormholeTex = CelluarTex.CreateWormhole(InsectedRatio, leafTex, out threshold);
            wormholeTex.name = "Wormhole Texture";

            /*
             * 清除纹理
             * 释放内存
             */
            if (leafTex.name == "Wormhole Texture")
            {
                GameObject.DestroyObject(leafTex);
            }

            return(wormholeTex);
        }
    }