static void DrawGizmosSelected(RayfireConnectivity targ, GizmoType gizmoType) { // Connections if (targ.showConnections == true) { if (Application.isPlaying == true) { Gizmos.color = Color.green; if (targ.cluster != null && targ.cluster.shards.Count > 0) { foreach (var shard in targ.cluster.shards) { // Set color Gizmos.color = shard.rigid.activation.unyielding == true ? Color.red : Color.green; // draw sphere if (targ.sphereSize > 0) { Gizmos.DrawWireSphere(shard.tm.position, shard.bound.size.magnitude / 13f * targ.sphereSize); } // Draw connection foreach (var neibShard in shard.neibShards) { if (neibShard.rigid.activation.connect != null) { Gizmos.DrawLine(shard.tm.position, neibShard.tm.position); } } } } } } // Gizmo preview if (targ.showGizmo == true) { // Gizmo properties Gizmos.color = wireColor; // Gizmo if (targ.source == RayfireConnectivity.ConnTargetType.Gizmo) { Gizmos.matrix = targ.transform.localToWorldMatrix; Gizmos.DrawWireCube(Vector3.zero, targ.size); } // Children if (targ.source == RayfireConnectivity.ConnTargetType.Children) { if (targ.transform.childCount > 0) { Bounds bound = RFCluster.GetChildrenBound(targ.transform); Gizmos.DrawWireCube(bound.center, bound.size); } } } }
static void GizmoDraw(RayfireConnectivity targ) { if (targ.showGizmo == true) { // Gizmo properties Gizmos.color = wireColor; if (targ.transform.childCount > 0) { Bounds bound = RFCluster.GetChildrenBound(targ.transform); Gizmos.DrawWireCube(bound.center, bound.size); } } }
// Set bound and size public static void SetBound(RayfireRigid scr) { if (scr.objectType == ObjectType.Mesh) { scr.limitations.bound = scr.meshRenderer.bounds; } else if (scr.objectType == ObjectType.SkinnedMesh) { scr.limitations.bound = scr.skinnedMeshRend.bounds; } else if (scr.objectType == ObjectType.NestedCluster || scr.objectType == ObjectType.ConnectedCluster) { scr.limitations.bound = RFCluster.GetChildrenBound(scr.transForm); } scr.limitations.bboxSize = scr.limitations.bound.size.magnitude; }
static void DrawGizmosSelected(RayfireCluster cluster, GizmoType gizmoType) { // Color preview if (cluster.colorPreview == true) { ColorPreview(cluster); } // Show bounds if (cluster.showGizmo == true) { if (cluster.transform.childCount > 0) { Bounds bound = RFCluster.GetChildrenBound(cluster.transform); Gizmos.color = cluster.wireColor; Gizmos.DrawWireCube(bound.center, bound.size); float size = bound.size.magnitude * 0.02f; Gizmos.color = new Color(1.0f, 0.60f, 0f); Gizmos.DrawSphere(bound.min, size); Gizmos.DrawSphere(bound.max, size); } } }
// Clusterize shards by amount List <RFCluster> ClusterizeClusterByAmount(RFCluster parentCluster, int amount) { // Empty list of all new cluster roots List <RFCluster> childClusters = new List <RFCluster>(); // Check if root has children more than at least 2 if (parentCluster.tm.childCount <= 2) { return(childClusters); } // Shards are more than cluster amount if (amount >= parentCluster.shards.Count) { return(childClusters); } // Get bounds for random point cloud generation Bounds bound = RFCluster.GetChildrenBound(parentCluster.tm); // Collect cluster points List <Vector3> voronoiPoints = VoronoiPointCloud(bound, amount); // Create cluster for each point foreach (Vector3 point in voronoiPoints) { RFCluster childCluster = new RFCluster(); childCluster.pos = point; childCluster.depth = parentCluster.depth + 1; // Set id clusterId++; childCluster.id = clusterId; childClusters.Add(childCluster); } // Separate shards by closest to cluster distance foreach (RFShard shard in parentCluster.shards) { // Puck first cluster float rootDist = Vector3.Distance(shard.tm.position, childClusters[0].pos); float minDist = rootDist; shard.cluster = childClusters[0]; // Set closest cluster if (childClusters.Count > 1) { for (int i = 1; i < childClusters.Count; i++) { rootDist = Vector3.Distance(shard.tm.position, childClusters[i].pos); if (rootDist < minDist) { minDist = rootDist; shard.cluster = childClusters[i]; } } } // Apply shard to closest cluster and reset shard.cluster.shards.Add(shard); shard.cluster = null; } // Check child clusters and remove empty or solo shard clusters List <RFShard> soloShards = new List <RFShard>(); for (int i = childClusters.Count - 1; i >= 0; i--) { if (childClusters[i].shards.Count < 2) { soloShards.AddRange(childClusters[i].shards); childClusters.RemoveAt(i); } } // First pass Find neib cluster for solo shards SetSoloShardToCluster(soloShards, childClusters); //// Second pass Find neib cluster for solo shards SetSoloShardToCluster(soloShards, childClusters); // Roughness pass. Remove shards from cluster and add to another. if (smoothPass > 0 && connectivity == ConnectivityType.ByMesh) { for (int i = 0; i < smoothPass; i++) { RoughnessPassShards(childClusters); } } // Create clusters by connectivity check if (connectivity == ConnectivityType.ByMesh) { ConnectivityCheck(childClusters); } // Check if only one cluster left if (childClusters.Count == 1) { childClusters.Clear(); return(childClusters); } // Create root for cluster at shards center and set shards as children foreach (RFCluster childCluster in childClusters) { CreateRoot(childCluster, parentCluster.tm); } return(childClusters); }