public static void AddRelations(GameObject parentFx, GameObject[] arrGameObject, List <Tuple2 <Caronte_Fx, int> > listCaronteFx) { for (int i = 0; i < arrGameObject.Length; i++) { GameObject go = arrGameObject[i]; Caronte_Fx fxChild = go.GetComponent <Caronte_Fx>(); if (fxChild != null) { int depth = go.GetFxHierachyDepthFrom(parentFx); listCaronteFx.Add(Tuple2.New(fxChild, depth)); } } }
private void CreateNewObjects(Vector3 position, List <GameObject> listParentGO, List <GameObject> listChoppedParentGO, CaronteSharp.MeshParentInfo[] arrMeshParentInfo, UnityEngine.Mesh[] arrMeshPieceUnity, Tuple2 <int, int>[] arrSubmeshRange, int[] arrMeshComplexIdx, Vector3[] arrMeshPosition, uint[] arrOutsideInsideIdx) { List <GameObject> listChoppedGO = new List <GameObject>(); List <Tuple2 <GameObject, GameObject> > listOutsideInsideGOParent = new List <Tuple2 <GameObject, GameObject> >(); bool hasBeenSplitted = arrOutsideInsideIdx != null; // Create InsideOutSidePieces for (int i = 0; i < listParentGO.Count; i++) { GameObject parentGO = listParentGO[i]; GameObject chopParentGO = listChoppedParentGO[i]; if (hasBeenSplitted) { GameObject outsideGO = parentGO.CreateDummy(parentGO.name + "_outside"); GameObject insideGO = parentGO.CreateDummy(parentGO.name + "_inside"); outsideGO.transform.parent = chopParentGO.transform; insideGO.transform.parent = chopParentGO.transform; listOutsideInsideGOParent.Add(Tuple2.New(outsideGO, insideGO)); } if (Data.HideParentObjectAuto) { Undo.RecordObject(parentGO, "Change activate state - " + parentGO.name); parentGO.SetActive(false); EditorUtility.SetDirty(parentGO); } } //Create Chopped Pieces Dictionary <GameObject, int> dictChoppedGOInteriorSubmeshIdx = new Dictionary <GameObject, int>(); int nMeshPieces = arrMeshPieceUnity.Length; for (int i = 0; i < nMeshPieces; i++) { UnityEngine.Mesh meshPiece = arrMeshPieceUnity[i]; Tuple2 <int, int> submeshRange = arrSubmeshRange[i]; int meshComplexIdx = arrMeshComplexIdx[i]; Vector3 goPosition = arrMeshPosition[i]; MeshParentInfo parentInfo = arrMeshParentInfo[meshComplexIdx]; int parentIdx = (int)parentInfo.parentMeshIdx_; GameObject parentGO = listParentGO[parentIdx]; GameObject chopParentGO = listChoppedParentGO[parentIdx]; int interiorPieceSubmeshIdx; GameObject goPiece = CRGeometryUtils.CreatePiece(i, meshPiece, parentInfo, goPosition, submeshRange, Data.InteriorMaterial, parentGO, chopParentGO, out interiorPieceSubmeshIdx); if (hasBeenSplitted) { Tuple2 <GameObject, GameObject> tupleOutsideInside = listOutsideInsideGOParent[parentIdx]; GameObject outsideGO = tupleOutsideInside.First; GameObject insideGO = tupleOutsideInside.Second; uint outsideInsideIdx = arrOutsideInsideIdx[meshComplexIdx]; if (outsideInsideIdx == 0) { goPiece.transform.parent = outsideGO.transform; goPiece.name = parentGO.name + "_out_" + i; } else if (outsideInsideIdx == 1) { goPiece.transform.parent = insideGO.transform; goPiece.name = parentGO.name + "_in_" + i; } } listChoppedGO.Add(goPiece); dictChoppedGOInteriorSubmeshIdx.Add(goPiece, interiorPieceSubmeshIdx); } GameObject chopRoot = new GameObject(Data.Name + "_output"); chopRoot.transform.position = position; Undo.RegisterCreatedObjectUndo(chopRoot, "Created " + Data.Name + "_output"); Data.GameObjectChoppedRoot = chopRoot; for (int i = 0; i < listChoppedParentGO.Count; i++) { GameObject chopParentGO = listChoppedParentGO[i]; chopParentGO.transform.parent = Data.GameObjectChoppedRoot.transform; chopParentGO.transform.SetAsFirstSibling(); } Selection.activeGameObject = Data.GameObjectChoppedRoot; SaveNewChopInfo(dictChoppedGOInteriorSubmeshIdx); }
private static void CreateMeshesFromComplex(CaronteSharp.MeshComplex inputMesh, out UnityEngine.Mesh[] outputMeshes, out Tuple2 <int, int>[] outputSubmeshRange) { Vector3[] vertices = inputMesh.arrPosition_; Vector3[] normals = inputMesh.arrNormal_; Vector4[] tangents = inputMesh.arrTan_; Vector2[] uv = inputMesh.arrUV_; bool hasNormals = (normals != null) && (normals.Length > 0); bool hasTangents = (tangents != null) && (tangents.Length > 0); bool hasUVs = (uv != null) && (uv.Length > 0); int maxVertexesPerMesh = 65533; List <UnityEngine.Mesh> listMeshes = new List <UnityEngine.Mesh>(); List <Tuple2 <int, int> > listSubmeshRange = new List <Tuple2 <int, int> >(); List <Vector3> listCurPos = new List <Vector3>(); List <Vector3> listCurNor = new List <Vector3>(); List <Vector4> listCurTan = new List <Vector4>(); List <Vector2> listCurUVs = new List <Vector2>(); List <List <int> > listListCurIndices = new List <List <int> >(); Dictionary <int, int> dictOldIndexToNew = new Dictionary <int, int>(); int indexMin = 0; int indexMax = 0; int submeshIdMin = 0; int[] subMeshesIdx = inputMesh.arrSubmeshIdx_; int nSubmeshIdx = subMeshesIdx.Length; for (int i = 0; i < nSubmeshIdx; i++) { indexMin = indexMax; indexMax = subMeshesIdx[i] * 3; List <int> listCurIndices = new List <int>(); listListCurIndices.Add(listCurIndices); for (int j = indexMin; j < indexMax; j++) { int oldIndex = inputMesh.arrIndex_[j]; if (!dictOldIndexToNew.ContainsKey(oldIndex)) { dictOldIndexToNew.Add(oldIndex, listCurPos.Count); listCurPos.Add(vertices[oldIndex]); if (hasNormals) { listCurNor.Add(normals[oldIndex]); } if (hasTangents) { listCurTan.Add(tangents[oldIndex]); } if (hasUVs) { listCurUVs.Add(uv[oldIndex]); } } int index = dictOldIndexToNew[oldIndex]; listCurIndices.Add(index); bool isTriangleEnd = ((j % 3) == 2); bool isMaxVertexReached = (listCurPos.Count >= maxVertexesPerMesh); bool isLastMeshTriangle = ((i == (nSubmeshIdx - 1)) && (j == (indexMax - 1))); if ((isMaxVertexReached && isTriangleEnd) || isLastMeshTriangle) { Mesh mesh; GenerateUnityMesh(listCurPos, listCurNor, listCurTan, listCurUVs, listListCurIndices, out mesh); listMeshes.Add(mesh); listSubmeshRange.Add(Tuple2.New(submeshIdMin, i)); submeshIdMin = i; listListCurIndices.Add(listCurIndices); dictOldIndexToNew.Clear(); } } } outputMeshes = listMeshes.ToArray(); outputSubmeshRange = listSubmeshRange.ToArray(); }