// Copy from void CopyFrom(RayfireShatter shatter) { type = shatter.type; voronoi = new RFVoronoi(shatter.voronoi); splinters = new RFSplinters(shatter.splinters); slabs = new RFSplinters(shatter.slabs); radial = new RFRadial(shatter.radial); custom = new RFCustom(shatter.custom); slice = new RFSlice(shatter.slice); tets = new RFTets(shatter.tets); mode = shatter.mode; material.CopyFrom(shatter.material); clusters = new RFShatterCluster(shatter.clusters); advanced = new RFShatterAdvanced(shatter.advanced); }
/// ///////////////////////////////////////////////////////// /// Properties setup /// ///////////////////////////////////////////////////////// // Set common fragmentation properties static RFShatter SetShatter(int shatterMode, Mesh mesh, Transform transform, RFSurface interior, bool decompose, bool deleteCol, int seed = 1, FragmentMode mode = FragmentMode.Runtime, bool preCap = true, bool remCap = false, bool remDbl = true, bool exInside = false, int percSize = 3) { // Creating shatter RFShatter shatter = new RFShatter((RFShatter.RFShatterMode)shatterMode, true); // Safe/unsafe properties if (mode == FragmentMode.Editor) { float sizeFilter = mesh.bounds.size.magnitude * percSize / 100f; // TODO check render bound size SetShatterEditorMode(shatter, sizeFilter, preCap, remCap, remDbl, exInside); } else { SetShatterRuntimeMode(shatter); } // Detach by elements shatter.DecomposeResultMesh(decompose); // Set properties shatter.SetFragmentParameter(RFShatter.FragmentParams.seed, seed); shatter.SetGeneralParameter(RFShatter.GeneralParams.pre_weld_threshold, 0.001f); shatter.SetGeneralParameter(RFShatter.GeneralParams.delete_collinear, deleteCol); // Other shatter.SetGeneralParameter(RFShatter.GeneralParams.maping_scale, interior.mappingScale); shatter.SetGeneralParameter(RFShatter.GeneralParams.restore_normals, true); // Setting shatter params bool inputState = shatter.SetInputMesh(transform, mesh); // Failed input if (inputState == false) { Debug.Log("Bad input mesh: " + transform.name, transform.gameObject); return(null); } return(shatter); }
/// ///////////////////////////////////////////////////////// /// Shatter /// ///////////////////////////////////////////////////////// // Cache for shatter public static void CacheMeshes(ref Mesh[] meshes, ref Vector3[] pivots, ref List <RFDictionary> origSubMeshIdsRf, RayfireShatter scrShatter) { // TODO check vars by type: slice list, etc // Turn off fast mode for tets and slices int shatterMode = GetShatterMode(scrShatter); // Get mesh Mesh mesh = GetDemolitionMesh(scrShatter);; // Decompose in Editor only, slice runtime only FragmentMode mode = scrShatter.mode; if (scrShatter.type == FragType.Decompose) // TODO FIX { mode = FragmentMode.Editor; } if (scrShatter.type == FragType.Slices) { mode = FragmentMode.Runtime; } // Set up shatter RFShatter shatter = SetShatter( shatterMode, mesh, scrShatter.transform, scrShatter.material, scrShatter.advanced.decompose, scrShatter.advanced.removeCollinear, scrShatter.advanced.seed, mode, scrShatter.advanced.inputPrecap, scrShatter.advanced.outputPrecap, scrShatter.advanced.removeDoubleFaces, scrShatter.advanced.excludeInnerFragments, scrShatter.advanced.elementSizeThreshold); // Failed input if (shatter == null) { meshes = null; pivots = null; return; } // Get innerSubId int innerSubId = RFSurface.SetInnerSubId(scrShatter); // Set fragmentation properties SetFragmentProperties(shatter, scrShatter, null); // Custom points check if (scrShatter.type == FragType.Custom && scrShatter.custom.noPoints == true) { meshes = null; pivots = null; Debug.Log("No custom ponts"); return; } // Calculate fragments List <Dictionary <int, int> > origSubMeshIds = new List <Dictionary <int, int> >(); bool successState = Compute( shatterMode, shatter, scrShatter.transform, ref meshes, ref pivots, mesh, innerSubId, ref origSubMeshIds, scrShatter); // Create RF dictionary origSubMeshIdsRf = new List <RFDictionary>(); for (int i = 0; i < origSubMeshIds.Count; i++) { origSubMeshIdsRf.Add(new RFDictionary(origSubMeshIds[i])); } // Failed fragmentation. Increase bad mesh if (successState == false) { Debug.Log("Bad shatter output mesh: " + scrShatter.name); } else { for (int i = 0; i < meshes.Length; i++) { meshes[i].name = scrShatter.name + "_" + i; } } }