public CarBalltreeMeshes GetBalltreeMeshes(CRBalltreeAsset btAsset)
        {
            if (!dictionaryBalltreeMeshes.ContainsKey(btAsset))
            {
                CarBalltreeMeshes btMeshes = CreateBalltreeMeshes(btAsset);
                dictionaryBalltreeMeshes.Add(btAsset, btMeshes);
            }

            return(dictionaryBalltreeMeshes[btAsset]);
        }
Пример #2
0
        public CarCreationData(GameObject go, Mesh renderMesh, Mesh colliderMesh, CRBalltreeAsset btAsset, bool isRope)
        {
            gameObject_ = go;
            isRope_     = isRope;

            positionRotationCanBeUpdated_ = true;

            renderFingerprint_   = null;
            colliderFingerprint_ = null;

            btAsset_ = btAsset;

            if (renderMesh != null)
            {
                renderFingerprint_ = new byte[256];
                CarGeometryUtils.CalculateFingerprint(renderMesh, renderFingerprint_);
            }

            if (colliderMesh != null)
            {
                colliderFingerprint_ = new byte[256];
                CarGeometryUtils.CalculateFingerprint(colliderMesh, colliderFingerprint_);
            }

            position_   = go.transform.position;
            rotation_   = go.transform.rotation;
            lossyScale_ = go.transform.lossyScale;

            positionCollider_   = Vector3.zero;
            rotationCollider_   = Quaternion.identity;
            lossyScaleCollider_ = Vector3.one;

            Caronte_Fx_Body fxBody = go.GetComponent <Caronte_Fx_Body>();

            if (fxBody != null)
            {
                colliderType_     = fxBody.ColliderType;
                hasValidCollider_ = fxBody.HasValidCollider();

                if (colliderType_ == Caronte_Fx_Body.EColliderType.CustomGameObject)
                {
                    GameObject goCollider = fxBody.GetColliderGameObject();

                    if (goCollider != null)
                    {
                        positionCollider_   = goCollider.transform.position;
                        rotationCollider_   = goCollider.transform.rotation;
                        lossyScaleCollider_ = goCollider.transform.lossyScale;
                    }
                }
            }
        }
        private CRBalltreeAsset CreateBallTreeAsset(string name, string folderPath, byte[] balltree_bytes, byte[] balltreeCheckheader_bytes, CarSphere[] arrLeafSphere)
        {
            CRBalltreeAsset btAsset = CRBalltreeAsset.CreateInstance <CRBalltreeAsset>();

            btAsset.BalltreeBytes    = balltree_bytes;
            btAsset.CheckHeaderBytes = balltreeCheckheader_bytes;
            btAsset.LeafSpheres      = arrLeafSphere;

            string assetFilePath = AssetDatabase.GenerateUniqueAssetPath(folderPath + "/" + "Bt_" + name + ".asset");

            AssetDatabase.CreateAsset(btAsset, assetFilePath);

            return(btAsset);
        }
        private CarBalltreeMeshes CreateBalltreeMeshes(CRBalltreeAsset btAsset)
        {
            CarBalltreeMeshes btMeshes = new CarBalltreeMeshes();

            CarSphere[] arrSphere      = btAsset.LeafSpheres;
            int         arrSphere_size = arrSphere.Length;

            for (uint i = 0; i < arrSphere_size; i++)
            {
                CarSphere sphere = arrSphere[i];
                btMeshes.AddSphere(CarColor.ColorBasic42(i), sphere.center_, sphere.radius_);
            }

            btMeshes.FinishAddingSpheres();
            return(btMeshes);
        }
Пример #5
0
        //-----------------------------------------------------------------------------------
        public static void GetBalltreeAsset(GameObject go, ref CRBalltreeAsset btAsset)
        {
            Caronte_Fx_Body bodyComponent = go.GetComponent <Caronte_Fx_Body>();

            btAsset = bodyComponent.GetBalltreeAsset();
        }
Пример #6
0
 void OnEnable()
 {
     btAsset_ = (CRBalltreeAsset)target;
 }
 public bool HasBalltreeMeshes(CRBalltreeAsset btAsset)
 {
     return(dictionaryBalltreeMeshes.ContainsKey(btAsset));
 }
        public void CreateBalltrees()
        {
            string folder;
            int    pathIndex;
            bool   assetsPath = CarFileUtils.DisplaySaveFolderDialog("CaronteFX - Balltree assets folder...", out folder, out pathIndex);

            if (!assetsPath)
            {
                return;
            }
            folder = folder.Substring(pathIndex);

            Dictionary <GameObject, uint> dictionaryGameObjectIdBalltree = new Dictionary <GameObject, uint>();
            HashSet <BalltreeId>          hashsetIdBalltree = new HashSet <BalltreeId>();

            GameObject[] arrGameObject = FieldController.GetUnityGameObjects();
            RgInit       rgInit        = new RgInit();

            Matrix4x4 m_MODEL_to_WORLD  = Matrix4x4.identity;
            bool      isBakedRenderMesh = false;

            int nGameObject = arrGameObject.Length;

            for (int i = 0; i < nGameObject; i++)
            {
                int   currentGOIdx = i + 1;
                float progress     = (float)currentGOIdx / (float)nGameObject;
                EditorUtility.DisplayProgressBar("CaronteFX - Balltree Generator", "Creating balltree for " + nGameObject + " GameObjects. GameObject " + currentGOIdx + ".", progress);
                GameObject go           = arrGameObject[i];
                Mesh       balltreeMesh = null;

                Caronte_Fx_Body cfxBody = CarBodyUtils.AddBodyComponentIfHasMesh(go);
                if (cfxBody != null)
                {
                    if (Data.CreationMode == CNBalltreeGenerator.ECreationMode.USERENDERERS)
                    {
                        CarBodyUtils.GetRenderMeshData(go, ref balltreeMesh, out m_MODEL_to_WORLD, ref isBakedRenderMesh);
                    }
                    else if (Data.CreationMode == CNBalltreeGenerator.ECreationMode.USECOLLLIDERS)
                    {
                        CarBodyUtils.GetColliderMeshData(go, ref balltreeMesh, out m_MODEL_to_WORLD, ref isBakedRenderMesh);
                    }

                    if (balltreeMesh != null)
                    {
                        SetRgInitForBalltree(go, balltreeMesh, rgInit);
                        uint id = RigidbodyManager.CreateBalltree(rgInit);

                        dictionaryGameObjectIdBalltree.Add(go, id);
                        hashsetIdBalltree.Add(new BalltreeId(id, balltreeMesh.name));
                    }
                }
            }

            int balltreeIdx = 1;
            int nBaltrees   = hashsetIdBalltree.Count;

            Dictionary <uint, CRBalltreeAsset> dictionaryIdBalltreeBalltreeAsset = new Dictionary <uint, CRBalltreeAsset>();

            foreach (BalltreeId balltreeId in hashsetIdBalltree)
            {
                float progress = (float)balltreeIdx / (float)nBaltrees;
                EditorUtility.DisplayProgressBar("CaronteFX - Balltree Generator", "Saving " + nBaltrees + " balltree assets. Balltree  " + balltreeIdx + ".", progress);

                byte[]      balltree_bytes            = RigidbodyManager.GetBalltreeBytes(balltreeId.id_);
                byte[]      balltreeCheckheader_bytes = RigidbodyManager.GetBalltreeCheckheaderBytes(balltreeId.id_);
                CarSphere[] arrLeafSphere             = RigidbodyManager.GetBalltreeSpheres(balltreeId.id_);

                CRBalltreeAsset btAsset = CreateBallTreeAsset(balltreeId.name_, folder, balltree_bytes, balltreeCheckheader_bytes, arrLeafSphere);

                dictionaryIdBalltreeBalltreeAsset.Add(balltreeId.id_, btAsset);
                balltreeIdx++;
            }
            EditorUtility.ClearProgressBar();

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            ICollection <GameObject> goCollection = dictionaryGameObjectIdBalltree.Keys;

            foreach (GameObject go in goCollection)
            {
                Caronte_Fx_Body cfxBody = go.GetComponent <Caronte_Fx_Body>();
                if (cfxBody == null)
                {
                    cfxBody = go.AddComponent <Caronte_Fx_Body>();
                }

                uint            idBalltree = dictionaryGameObjectIdBalltree[go];
                CRBalltreeAsset btAsset    = dictionaryIdBalltreeBalltreeAsset[idBalltree];
                cfxBody.SetBalltreeAsset(btAsset);
                EditorUtility.SetDirty(cfxBody);
            }
        }
Пример #9
0
 public void SetBalltreeAsset(CRBalltreeAsset btAsset)
 {
     colliderType_ = EColliderType.BalltreeAsset;
     btAsset_      = btAsset;
 }