static void DrawGizmosSelected(RayfireShatter shatter, GizmoType gizmoType) { // Color preview if (shatter.colorPreview == true) { ColorPreview(shatter); } // Custom point cloud preview if (shatter.type == FragType.Custom) { if (shatter.custom.enable == true) { Gizmos.color = Color.green; // Get bounds for preview Bounds bound = shatter.GetBound(); if (bound.size.magnitude > 0) { List <Vector3> pointCloud = RFCustom.GetCustomPointCLoud(shatter.custom, shatter.transform, shatter.advanced.seed, bound); if (pointCloud.Count > 0) { for (int i = 0; i < pointCloud.Count; i++) { Gizmos.DrawSphere(pointCloud[i], shatter.custom.size); } } } } } }
// Constructor public RFCustom(RFCustom src) { source = src.source; useAs = src.useAs; amount = src.amount; radius = src.radius; enable = false; size = src.size; transforms = src.transforms; vector3 = src.vector3; }
// Get custom input cloud static List <Vector3> GetCustomInputCloud(RFCustom custom, Transform tm) { // Vars custom.noPoints = false; List <Vector3> inputPoints = new List <Vector3> (); // Children transform if (custom.source == RFCustom.RFPointCloudSourceType.ChildrenTransform) { if (tm.childCount > 0) { for (int i = 0; i < tm.childCount; i++) { inputPoints.Add(tm.GetChild(i).position); } } } // Transform array else if (custom.source == RFCustom.RFPointCloudSourceType.TransformArray) { if (custom.transforms != null && custom.transforms.Length > 0) { for (int i = 0; i < custom.transforms.Length; i++) { if (custom.transforms[i] != null) { inputPoints.Add(custom.transforms[i].position); } } } } // Vector 3 array else if (custom.source == RFCustom.RFPointCloudSourceType.Vector3Array) { if (custom.vector3 != null && custom.vector3.Length > 0) { for (int i = 0; i < custom.vector3.Length; i++) { inputPoints.Add(custom.vector3[i]); } } } return(inputPoints); }
// 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); }
// Get final output point cloud static List <Vector3> GetCustomOutputCloud(RFCustom custom, List <Vector3> inputPoints, int seed, Bounds bound) { // Use same input point if (custom.useAs == RFCustom.RFPointCloudUseType.PointCloud) { return(inputPoints); } // Volume around point if (custom.useAs == RFCustom.RFPointCloudUseType.VolumePoints) { // Stop if no points if (inputPoints.Count == 0) { return(inputPoints); } // Get amount of points in radius int pointsPerPoint = custom.amount / inputPoints.Count; int localSeed = seed; // Generate new points around point List <Vector3> newPoints = new List <Vector3>(); for (int p = 0; p < inputPoints.Count; p++) { localSeed++; Random.InitState(localSeed); for (int i = 0; i < pointsPerPoint; i++) { Vector3 randomPoint = RandomPointInRadius(inputPoints[p], custom.radius); if (bound.Contains(randomPoint) == false) { randomPoint = RandomPointInRadius(inputPoints[p], custom.radius); if (bound.Contains(randomPoint) == false) { randomPoint = RandomPointInRadius(inputPoints[p], custom.radius); } } newPoints.Add(randomPoint); } } return(newPoints); } return(inputPoints); }
// Set custom point cloud static void SetCustom(RFShatter shatter, RFCustom custom, Transform tm, MeshFilter mf, Bounds bound, RFSplinters splint, RFSplinters slabs, int seed) { // Set properties shatter.SetFragmentParameter(RFShatter.FragmentParams.type, (int)RFShatter.FragmentType.voronoi); shatter.SetFragmentParameter(RFShatter.FragmentParams.voronoi_type, (int)RFShatter.VoronoiType.custom); // Get Point Cloud List <Vector3> pointCloud = GetCustomPointCLoud(custom, tm, seed, bound); // Set points shatter.SetVoroCustomPoints(pointCloud.ToArray(), tm); // Set Stretching TODO point cloud rescale by transform // if (custom.modifier == RFCustom.RFModifierType.Splinters) // SetStretching (shatter, splint.axis, splint.strength, FragType.Splinters); // else if (custom.modifier == RFCustom.RFModifierType.Slabs) // SetStretching (shatter, slabs.axis, slabs.strength, FragType.Slabs); }
/// ///////////////////////////////////////////////////////// /// Static /// ///////////////////////////////////////////////////////// // Get final point cloud for custom fragmentation public static List <Vector3> GetCustomPointCLoud(RFCustom custom, Transform tm, int seed, Bounds bound) { // Get input points List <Vector3> inputPoints = GetCustomInputCloud(custom, tm); // Get final output point cloud List <Vector3> outputPoints = GetCustomOutputCloud(custom, inputPoints, seed, bound); // Get points in bound List <Vector3> boundPoints = GetCustomBoundPoints(outputPoints, bound); // Stop if no points if (boundPoints.Count <= 1) { custom.noPoints = true; } return(boundPoints); }