public SliceMesh ( Mesh mesh, Plane &slice ) : bool | ||
mesh | Mesh | |
slice | Plane | |
return | bool |
void SliceObject(ref Plane slicePlane, GameObject obj) { var mesh = obj.GetComponent <MeshFilter>().mesh; if (!meshCutter.SliceMesh(mesh, ref slicePlane)) { // If we didn't slice the object then no need to separate it into 2 objects // Debug.Log("Didn't slice"); return; } // TODO: Update center of mass bool posBigger = meshCutter.PositiveMesh.surfacearea > meshCutter.NegativeMesh.surfacearea; if (posBigger) { biggerMesh = meshCutter.PositiveMesh; smallerMesh = meshCutter.NegativeMesh; } else { biggerMesh = meshCutter.NegativeMesh; smallerMesh = meshCutter.PositiveMesh; } // Put the bigger mesh in the original object // Ignore colliders for now ReplaceMesh(mesh, biggerMesh); // Create new Sliced object with the other mesh GameObject newObject = Instantiate(SlicedPrefab, ObjectContainer); newObject.transform.SetPositionAndRotation(obj.transform.position, obj.transform.rotation); var newObjMesh = newObject.GetComponent <MeshFilter>().mesh; ReplaceMesh(newObjMesh, smallerMesh); Transform posTransform, negTransform; if (posBigger) { posTransform = obj.transform; negTransform = newObject.transform; } else { posTransform = newObject.transform; negTransform = obj.transform; } // Separate meshes SeparateMeshes(posTransform, negTransform, slicePlane.normal); }
private bool SliceObject(ref Plane slicePlane, GameObject obj, List <Transform> positiveObjects, List <Transform> negativeObjects, bool isPlayer) { var mesh = obj.GetComponent <MeshFilter>().mesh; if (!_meshCutter.SliceMesh(mesh, ref slicePlane)) { if (slicePlane.GetDistanceToPoint(_meshCutter.GetFirstVertex()) >= 0) { positiveObjects.Add(obj.transform); } else { negativeObjects.Add(obj.transform); } return(false); } bool posBigger = _meshCutter.PositiveMesh.surfacearea > _meshCutter.NegativeMesh.surfacearea; if (posBigger) { _biggerMesh = _meshCutter.PositiveMesh; _smallerMesh = _meshCutter.NegativeMesh; } else { _biggerMesh = _meshCutter.NegativeMesh; _smallerMesh = _meshCutter.PositiveMesh; } GameObject newObject = Instantiate(obj, objectContainer); newObject.transform.SetPositionAndRotation(obj.transform.position, obj.transform.rotation); var newObjMesh = newObject.GetComponent <MeshFilter>().mesh; obj.GetComponent <Rigidbody>().useGravity = true; obj.GetComponent <Rigidbody>().isKinematic = false; newObject.layer = 18; obj.layer = 18; // Destroy(obj.GetComponent<BoxCollider>()); // // obj.AddComponent<SphereCollider>(); obj.GetComponent <Rigidbody>().AddForce(isPlayer ? 10f : 0f, 10f, 0f); ReplaceMesh(mesh, _biggerMesh); ReplaceMesh(newObjMesh, _smallerMesh); (posBigger ? positiveObjects : negativeObjects).Add(obj.transform); (posBigger ? negativeObjects : positiveObjects).Add(newObject.transform); return(true); }
bool SliceObject(ref Plane slicePlane, GameObject obj, List <Transform> positiveObjects, List <Transform> negativeObjects) { var mesh = obj.GetComponent <MeshFilter>().mesh; if (!meshCutter.SliceMesh(mesh, ref slicePlane)) { // Put object in the respective list if (slicePlane.GetDistanceToPoint(meshCutter.GetFirstVertex()) >= 0) { positiveObjects.Add(obj.transform); } else { negativeObjects.Add(obj.transform); } return(false); } // TODO: Update center of mass // Silly condition that labels which mesh is bigger to keep the bigger mesh in the original gameobject bool posBigger = meshCutter.PositiveMesh.surfacearea > meshCutter.NegativeMesh.surfacearea; if (posBigger) { biggerMesh = meshCutter.PositiveMesh; smallerMesh = meshCutter.NegativeMesh; } else { biggerMesh = meshCutter.NegativeMesh; smallerMesh = meshCutter.PositiveMesh; } // Create new Sliced object with the other mesh GameObject newObject = Instantiate(obj, ObjectContainer); newObject.transform.SetPositionAndRotation(obj.transform.position, obj.transform.rotation); var newObjMesh = newObject.GetComponent <MeshFilter>().mesh; // Put the bigger mesh in the original object // TODO: Enable collider generation (either the exact mesh or compute smallest enclosing sphere) ReplaceMesh(mesh, biggerMesh); ReplaceMesh(newObjMesh, smallerMesh); (posBigger ? positiveObjects : negativeObjects).Add(obj.transform); (posBigger ? negativeObjects : positiveObjects).Add(newObject.transform); return(true); }
private bool SliceObject(ref Plane slicePlane, GameObject sliceObject, List <Transform> positiveObjects, List <Transform> negativeObjects) { var meshFilter = sliceObject.GetComponent <MeshFilter>(); var mesh = meshFilter.sharedMesh; if (!meshCutter.SliceMesh(mesh, ref slicePlane)) { // Распределяем куски объекта в соответствующие списки if (slicePlane.GetDistanceToPoint(meshCutter.GetFirstVertex()) >= 0) { positiveObjects.Add(sliceObject.transform); } else { negativeObjects.Add(sliceObject.transform); } return(false); } // Определяем больший меш для исходного объекта bool posBigger = meshCutter.PositiveMesh.surfaceArea > meshCutter.NegativeMesh.surfaceArea; if (posBigger) { biggerMesh = meshCutter.PositiveMesh; smallerMesh = meshCutter.NegativeMesh; } else { biggerMesh = meshCutter.NegativeMesh; smallerMesh = meshCutter.PositiveMesh; } //Новый меньший отрезанный объект GameObject newObject = Instantiate(sliceObject, ObjectContainer); newObject.transform.SetPositionAndRotation(sliceObject.transform.position, sliceObject.transform.rotation); var newObjMesh = newObject.GetComponent <MeshFilter>().mesh; //Распределение мешей и переопределение MeshCollider'ов ReplaceMesh(mesh, biggerMesh, sliceObject.GetComponent <MeshCollider>()); ReplaceMesh(newObjMesh, smallerMesh, newObject.GetComponent <MeshCollider>()); (posBigger ? positiveObjects : negativeObjects).Add(sliceObject.transform); (posBigger ? negativeObjects : positiveObjects).Add(newObject.transform); return(true); }
bool SliceObject(ref Plane slicePlane, GameObject obj, List <Transform> positiveObjects, List <Transform> negativeObjects) { var mesh = obj.GetComponent <MeshFilter>().mesh; if (!meshCutter.SliceMesh(mesh, ref slicePlane)) { if (slicePlane.GetDistanceToPoint(meshCutter.GetFirstVertex()) >= 0) { positiveObjects.Add(obj.transform); } else { negativeObjects.Add(obj.transform); } return(false); } bool posBigger = meshCutter.PositiveMesh.surfacearea > meshCutter.NegativeMesh.surfacearea; if (posBigger) { biggerMesh = meshCutter.PositiveMesh; smallerMesh = meshCutter.NegativeMesh; } else { biggerMesh = meshCutter.NegativeMesh; smallerMesh = meshCutter.PositiveMesh; } // Create new Sliced object with the other mesh GameObject newObject = Instantiate(obj, ObjectContainer); newObject.transform.SetPositionAndRotation(obj.transform.position, obj.transform.rotation); var newObjMesh = newObject.GetComponent <MeshFilter>().mesh; ReplaceMesh(mesh, biggerMesh); ReplaceMesh(newObjMesh, smallerMesh); (posBigger ? positiveObjects : negativeObjects).Add(obj.transform); (posBigger ? negativeObjects : positiveObjects).Add(newObject.transform); return(true); }
bool SliceObject(ref Plane slicePlane, GameObject obj, List <Transform> positiveObjects, List <Transform> negativeObjects, bool isPlayer) { var mesh = obj.GetComponent <MeshFilter>().mesh; if (!meshCutter.SliceMesh(mesh, ref slicePlane)) { // Put object in the respective list if (slicePlane.GetDistanceToPoint(meshCutter.GetFirstVertex()) >= 0) { positiveObjects.Add(obj.transform); } else { negativeObjects.Add(obj.transform); } return(false); } // TODO: Update center of mass // Silly condition that labels which mesh is bigger to keep the bigger mesh in the original gameobject bool posBigger = meshCutter.PositiveMesh.surfacearea > meshCutter.NegativeMesh.surfacearea; if (posBigger) { biggerMesh = meshCutter.PositiveMesh; smallerMesh = meshCutter.NegativeMesh; } else { biggerMesh = meshCutter.NegativeMesh; smallerMesh = meshCutter.PositiveMesh; } // Create new Sliced object with the other mesh GameObject newObject = Instantiate(obj, ObjectContainer); newObject.transform.SetPositionAndRotation(obj.transform.position, obj.transform.rotation); var newObjMesh = newObject.GetComponent <MeshFilter>().mesh; //add gravity and disable kinematic to new game object obj.GetComponent <Rigidbody>().useGravity = true; obj.GetComponent <Rigidbody>().isKinematic = false; newObject.layer = 13; obj.layer = 13; //Recalculate box collider Destroy(obj.GetComponent <BoxCollider>()); // obj.AddComponent<MeshCollider>(); // obj.GetComponent<MeshCollider>().convex = true; obj.AddComponent <SphereCollider>(); obj.GetComponent <Rigidbody>().AddForce(isPlayer ? 10f : 0f, gm.cutObjGravityCoefficient * 10f, 0f); //obj.GetComponent<SphereCollider>().isTrigger = true; // obj.GetComponent<SphereCollider>().radius = 0.5f; // obj.GetComponent<SphereCollider>().center = new Vector3(0f,1f,0f); // Put the bigger mesh in the original object // TODO: Enable collider generation (either the exact mesh or compute smallest enclosing sphere) ReplaceMesh(mesh, biggerMesh); ReplaceMesh(newObjMesh, smallerMesh); (posBigger ? positiveObjects : negativeObjects).Add(obj.transform); (posBigger ? negativeObjects : positiveObjects).Add(newObject.transform); return(true); }
bool SliceObject(ref Plane slicePlane, GameObject obj, List <Transform> positiveObjects, List <Transform> negativeObjects) { var mesh = obj.GetComponent <MeshFilter>().mesh; if (!meshCutter.SliceMesh(mesh, ref slicePlane)) { // Put object in the respective list if (slicePlane.GetDistanceToPoint(meshCutter.GetFirstVertex()) >= 0) { positiveObjects.Add(obj.transform); } else { negativeObjects.Add(obj.transform); } return(false); } // TODO: Update center of mass // Silly condition that labels which mesh is bigger to keep the bigger mesh in the original gameobject bool posBigger = meshCutter.PositiveMesh.surfacearea > meshCutter.NegativeMesh.surfacearea; if (posBigger) { biggerMesh = meshCutter.PositiveMesh; smallerMesh = meshCutter.NegativeMesh; } else { biggerMesh = meshCutter.NegativeMesh; smallerMesh = meshCutter.PositiveMesh; } // Create new Sliced object with the other mesh var newObject = Instantiate(obj, objectContainer); spawner.NewFruitCut(newObject); newObject.transform.SetPositionAndRotation(obj.transform.position, obj.transform.rotation); var newObjMesh = newObject.GetComponent <MeshFilter>().mesh; // Put the bigger mesh in the original object // TODO: Enable collider generation (either the exact mesh or compute smallest enclosing sphere) ReplaceMesh(mesh, biggerMesh); ReplaceMesh(newObjMesh, smallerMesh); (posBigger ? positiveObjects : negativeObjects).Add(obj.transform); (posBigger ? negativeObjects : positiveObjects).Add(newObject.transform); if (obj.layer != /*UI*/ 5) { sController?.AddScore(); } else { uiSliceCount += 1; if (uiSliceCount == 5) { gameStarter.GoToGameMode(); for (int i = 0; i < fruitsChild.transform.childCount; i++) { fruitsChild.transform.GetChild(i).gameObject.SetActive(false); } } } //audio sliceSample.Play(); //slice effect if (fruitSliceEffect != null) { Instantiate(fruitSliceEffect, obj.transform); } obj.tag = "nonSlisable"; newObject.tag = "nonSlisable"; return(true); }