public qb_Point AddPoint(Vector3 position, Vector3 upVector, Vector3 dirVector) { qb_Point newPoint = new qb_Point(position, upVector, dirVector); points.Add(newPoint); curPoint = newPoint; return curPoint; }
public qb_Point AddPoint(Vector3 position, Vector3 upVector, Vector3 dirVector) { qb_Point newPoint = new qb_Point(position, upVector, dirVector); points.Add(newPoint); curPoint = newPoint; return(curPoint); }
static void DoBrushIterration(qb_Point newPoint) // do whatever needs to be done on the bruh itteration { //if brush is positive //do a paint itteration if(brushDirection == true) PlaceGeo(newPoint); //if brush is negative //do an erase itteration else EraseGeo(newPoint); //later, we'll need another case for a vertex color brush, probably just an additional layer rather than exclusive }
private static void EraseGeo(qb_Point newPoint) { // qb_ObjectContainer objectContainer = qb_ObjectContainer.GetInstance(); GameObject[] objects = window.GetObjects(); List<int> removalList = new List<int>(); for(int i = 0; i < objects.Length; i++) { if(Vector3.Distance(objects[i].transform.position, newPoint.position) < window.brushRadius) { removalList.Add(i); } } if(removalList.Count > 0) window.EraseObjects(removalList); }
private static GameObject PlaceObject(qb_Point newPoint) { //-1 : if there are no prefabs in the queue. Do not place if(window.prefabGroup.Length == 0) return null; if(window.prefabGroup[0] == null) return null; //0 : declare function variables Vector3 spawnPosition = Vector3.zero; Quaternion spawnRotation = Quaternion.identity; Vector3 upVector = Vector3.up; //1 : if there is more than one prefab in the queue, pick one if(window.selectedPrefabIndex != -1) { if(window.prefabGroup.Length > window.selectedPrefabIndex && window.prefabGroup[window.selectedPrefabIndex] != null) objectToSpawn = window.prefabGroup[window.selectedPrefabIndex].prefab; else window.selectedPrefabIndex = -1; } else { if(window.prefabGroup.Length > 0 && window.prefabGroup[0] != null) objectToSpawn = window.prefabGroup[0].prefab; else { //window.selectedPrefabIndex = -1; return null; } } //else return null; //2 : use the current point in the stroke to Get a random point around its upVector Axis Vector3 castPosition = newPoint.position; //3 : use the random disk point to cast down along the upVector of the stroke point Vector3 rayDir = -newPoint.upVector; qb_RaycastResult result = DoPlacementRaycast(castPosition, rayDir); //4 : if cast successful, get cast point and normal - if cast is unsuccessful, return...<--- if(result.success == true) { spawnPosition = result.hit.point; if(window.alignToNormal == true) { upVector = result.hit.normal; } } else return null; //5 : instantiate the prefab GameObject newObject = null; newObject = PrefabUtility.InstantiatePrefab(objectToSpawn) as GameObject; qb_Object marker = newObject.AddComponent<qb_Object>();//.hideFlags = HideFlags.HideInInspector; marker.hideFlags = HideFlags.HideInInspector; Undo.RegisterCreatedObjectUndo(newObject,"QB Place Object"); //6 : use settings to scale, rotate, and place the object if(window.alignToNormal) { spawnRotation = Quaternion.LookRotation(curStroke.GetCurPoint().dirVector,upVector); } else { spawnRotation = Quaternion.LookRotation(Vector3.forward,Vector3.up); } newObject.transform.position = spawnPosition; newObject.transform.rotation = spawnRotation; //7 : If we have a group, add the object to the group if(window.groupObjects == true && curGroup != null) { curGroup.AddObject(newObject); } // qb_ObjectContainer.GetInstance().AddObject(newObject); return newObject; }
private static void PlaceGeo(qb_Point newPoint) { //-1 : if there are no prefabs in the queue. Do not paint if(window.prefabGroup.Length == 0) return; //0 : declare function variables Vector3 spawnPosition = Vector3.zero; Quaternion spawnRotation = Quaternion.identity; //Vector3 spawnScale = new Vector3(1f,1f,1f); Vector3 upVector = Vector3.up; Vector3 forwardVector = Vector3.forward; //blank filled - this value should never end up being used //1 : if there is more than one prefab in the queue, pick one using the randomizer if(window.prefabGroup.Length > 0) { if(window.selectedPrefabIndex != -1) { if(window.prefabGroup.Length > window.selectedPrefabIndex && window.prefabGroup[window.selectedPrefabIndex] != null) objectToSpawn = window.prefabGroup[window.selectedPrefabIndex].prefab; else { window.selectedPrefabIndex = -1; return; } } else objectToSpawn = PickRandPrefab(); } else return; //2 : use the current point in the stroke to Get a random point around its upVector Axis Vector3 castPosition = GetRandomPointOnDisk(newPoint.upVector);//Vector3.zero; //3 : use the random disk point to cast down along the upVector of the stroke point Vector3 rayDir = -newPoint.upVector; //RaycastHit hit; qb_RaycastResult result = DoPlacementRaycast(castPosition + (rayDir * -0.02F), rayDir); //4 : if cast successful, get cast point and normal - if cast is unsuccessful, return...<--- if(result.success == true) { spawnPosition = result.hit.point; if(window.alignToNormal == true) { upVector = result.hit.normal; forwardVector = GetFlattenedDirection(Vector3.forward,upVector); } forwardVector = GetFlattenedDirection(Vector3.forward,upVector); if(window.alignToStroke == true) { //forwardVector = curStroke.GetCurPoint().dirVector; forwardVector = GetFlattenedDirection(curStroke.GetCurPoint().dirVector,upVector); } } else return; //5 : instantiate the prefab GameObject newObject = null; newObject = PrefabUtility.InstantiatePrefab(objectToSpawn) as GameObject; qb_Object marker = newObject.AddComponent<qb_Object>();//.hideFlags = HideFlags.HideInInspector; marker.hideFlags = HideFlags.HideInInspector; Undo.RegisterCreatedObjectUndo(newObject,"QB Place Object"); //6 : use settings to scale, rotate, and place the object spawnRotation = GetSpawnRotation(upVector,forwardVector); newObject.transform.position = spawnPosition; newObject.transform.rotation = spawnRotation; Vector3 randomScale; if(window.scaleUniform == true) { float randomScaleUni = Random.Range(window.scaleRandMinUniform,window.scaleRandMaxUniform); randomScale = new Vector3(randomScaleUni,randomScaleUni,randomScaleUni); } else randomScale = new Vector3(Random.Range(window.scaleRandMin.x,window.scaleRandMax.x),Random.Range(window.scaleRandMin.y,window.scaleRandMax.y),Random.Range(window.scaleRandMin.z,window.scaleRandMax.z)); newObject.transform.localScale = new Vector3(randomScale.x,randomScale.y,randomScale.z);//Random.Range(scaleMin.x,scaleMax.x),Random.Range(scaleMin.y,scaleMax.y),Random.Range(scaleMin.z,scaleMax.z));//spawnScale; //7 : If we have a group, add the object to the group if(window.groupObjects == true && curGroup != null) { curGroup.AddObject(newObject); } // qb_ObjectContainer.GetInstance().AddObject(newObject); }
private static void EraseGeo(qb_Point newPoint,int i) { qb_Template curTemplate = window.brushTemplates[i]; GameObject[] objects = window.GetGroupObjects(); List<int> removalList = new List<int>(); object curPrefab = null; bool eraseSelected = false; bool eraseGrouped = false; bool groupIsNothing = false; if(curTemplate.eraseBySelected == true) if(curTemplate.selectedPrefabIndex != -1) { curPrefab = curTemplate.prefabGroup[curTemplate.selectedPrefabIndex].prefab; eraseSelected = true; } if(curTemplate.eraseByGroup == true) { if(curTemplate.curGroup != null) { eraseGrouped = true; } else { if(curTemplate.groupName == string.Empty) { eraseGrouped = true; groupIsNothing = true; } else { curTemplate.curGroup = GetGroupWithName(curTemplate.groupName); } } if(curTemplate.curGroup == null && groupIsNothing == false) eraseGrouped = false; } bool addToList; for(int ii = 0; ii < objects.Length; ii++) { addToList = true; if(Vector3.Distance(objects[ii].transform.position, newPoint.position) < curTemplate.brushRadius) { if(eraseSelected == true) { //if the current object's prefab is the curPrefab if(PrefabUtility.GetPrefabParent(objects[ii]) != curPrefab) addToList = false; } //if group erase is on if(eraseGrouped == true) { if(groupIsNothing == false) {//Regular, group based if(objects[ii].transform.parent != curTemplate.curGroup.transform)//curGroup.transform) { addToList = false; } } //Only those which have no group else { if(objects[ii].transform.parent != null)//curGroup.transform) { addToList = false; } } } if(addToList == true) removalList.Add(ii); } } if(removalList.Count > 0) window.EraseObjects(removalList); }
private static GameObject PlaceObject(qb_Point newPoint,int i) { qb_Template curTemplate = window.brushTemplates[i]; //-1 : if there are no prefabs in the queue. Do not place if(curTemplate.prefabGroup.Length == 0) return null; if(curTemplate.prefabGroup[0] == null) return null; //0 : declare function variables Vector3 spawnPosition = Vector3.zero; Quaternion spawnRotation = Quaternion.identity; Vector3 upVector = Vector3.up; Vector3 placeUpVector = Vector3.up; //1 : if there is more than one prefab in the queue, pick one if(curTemplate.selectedPrefabIndex != -1) { if(curTemplate.prefabGroup.Length > curTemplate.selectedPrefabIndex && curTemplate.prefabGroup[curTemplate.selectedPrefabIndex] != null) objectToSpawn = curTemplate.prefabGroup[curTemplate.selectedPrefabIndex].prefab; else curTemplate.selectedPrefabIndex = -1; } else { if(curTemplate.prefabGroup.Length > 0 && curTemplate.prefabGroup[0] != null) objectToSpawn = curTemplate.prefabGroup[0].prefab; else { //window.selectedPrefabIndex = -1; return null; } } //else return null; //2 : use the current point in the stroke to Get a random point around its upVector Axis Vector3 castPosition = newPoint.position; //3 : use the random disk point to cast down along the upVector of the stroke point Vector3 rayDir = -newPoint.upVector; qb_RaycastResult result = DoPlacementRaycast(castPosition, rayDir, curTemplate); //4 : if cast successful, get cast point and normal - if cast is unsuccessful, return...<--- if(result.success == true) { spawnPosition = result.hit.point; if(curTemplate.alignToNormal == true) { upVector = result.hit.normal; placeUpVector = upVector; if(curTemplate.flipNormalAlign) placeUpVector *= -1f; } } else return null; //5 : instantiate the prefab GameObject newObject = null; newObject = PrefabUtility.InstantiatePrefab(objectToSpawn) as GameObject; qb_Object marker = newObject.AddComponent<qb_Object>();//.hideFlags = HideFlags.HideInInspector; marker.hideFlags = HideFlags.HideInInspector; Undo.RegisterCreatedObjectUndo(newObject,"qbP"); //6 : use settings to scale, rotate, and place the object if(curTemplate.alignToNormal) { spawnRotation = Quaternion.LookRotation(curStrokes[i].GetCurPoint().dirVector,placeUpVector); } else { spawnRotation = Quaternion.LookRotation(Vector3.forward,Vector3.up); } newObject.transform.position = spawnPosition; newObject.transform.rotation = spawnRotation; newObject.transform.position += (newObject.transform.right * curTemplate.positionOffset.x) + (upVector.normalized * curTemplate.positionOffset.y) + (newObject.transform.forward * curTemplate.positionOffset.z); //7 : If we have a group, add the object to the group if(curTemplate.groupObjects == true) { bool doGroup = false; //if group is missing - (either not yet assigned based on selection, or does not exist in this scene) if(curTemplate.curGroup == null) { //if the group selected is not "nothing" - otherwise no grouping is done if(curTemplate.groupName != string.Empty) { //the group has a name - check if group exists in scene qb_Group testGroup = GetGroupWithName(curTemplate.groupName); //if it does exist, assign as curGroup if(testGroup == null) curTemplate.curGroup = CreateGroup(curTemplate.groupName); else curTemplate.curGroup = testGroup; doGroup = true; } } else doGroup = true; if(doGroup) curTemplate.curGroup.AddObject(newObject); } return newObject; }
private static void PlaceGeo(qb_Point newPoint,int i) { qb_Template curTemplate = window.brushTemplates[i]; //-1 : if there are no prefabs in the queue. Do not paint if(curTemplate.prefabGroup.Length == 0) return; // if(window.liveTemplate.prefabGroup.Length == 0) // return; //0 : declare function variables Vector3 spawnPosition = Vector3.zero; Quaternion spawnRotation = Quaternion.identity; //Vector3 spawnScale = new Vector3(1f,1f,1f); Vector3 upVector = Vector3.up; Vector3 placeUpVector = Vector3.up; Vector3 forwardVector = Vector3.forward; //blank filled - this value should never end up being used //1 : if there is more than one prefab in the queue, pick one using the randomizer if(curTemplate.prefabGroup.Length > 0) { if(curTemplate.selectedPrefabIndex != -1) { if(curTemplate.prefabGroup.Length > curTemplate.selectedPrefabIndex && curTemplate.prefabGroup[curTemplate.selectedPrefabIndex] != null) objectToSpawn = curTemplate.prefabGroup[curTemplate.selectedPrefabIndex].prefab; else { curTemplate.selectedPrefabIndex = -1; return; } } else objectToSpawn = PickRandPrefab(curTemplate); } else return; //2 : use the current point in the stroke to Get a random point around its upVector Axis Vector3 castPosition = GetRandomPointOnDisk(newPoint.position, newPoint.upVector, curTemplate.brushRadius);// * curTemplate.scatterRadius);//Vector3.zero; //3 : use the random disk point to cast down along the upVector of the stroke point Vector3 rayDir = -newPoint.upVector; //RaycastHit hit; qb_RaycastResult result = DoPlacementRaycast(castPosition + (rayDir * -0.02f), rayDir, curTemplate); //4 : if cast successful, get cast point and normal - if cast is unsuccessful, return...<--- if(result.success == true) { spawnPosition = result.hit.point; if(curTemplate.alignToNormal == true) { upVector = result.hit.normal; placeUpVector = upVector; if(curTemplate.flipNormalAlign) placeUpVector *= -1f; forwardVector = GetFlattenedDirection(Vector3.forward,upVector); } forwardVector = GetFlattenedDirection(Vector3.forward,upVector); if(curTemplate.alignToStroke == true) { forwardVector = GetFlattenedDirection(curStrokes[i].GetCurPoint().dirVector,upVector); if(curTemplate.flipStrokeAlign) forwardVector *= -1f; } } else return; //5 : instantiate the prefab GameObject newObject = null; newObject = PrefabUtility.InstantiatePrefab(objectToSpawn) as GameObject; qb_Object marker = newObject.AddComponent<qb_Object>();//.hideFlags = HideFlags.HideInInspector; marker.hideFlags = HideFlags.HideInInspector; Undo.RegisterCreatedObjectUndo(newObject,"qbP"); //6 : use settings to scale, rotate, and place the object spawnRotation = GetSpawnRotation(upVector,forwardVector); newObject.transform.position = spawnPosition; newObject.transform.rotation = spawnRotation; newObject.transform.position += (newObject.transform.right * curTemplate.positionOffset.x) + (upVector.normalized * curTemplate.positionOffset.y) + (newObject.transform.forward * curTemplate.positionOffset.z); Vector3 randomScale; if(curTemplate.scaleUniform == true) { float randomScaleUni = Random.Range(curTemplate.scaleRandMinUniform,curTemplate.scaleRandMaxUniform); randomScale = new Vector3(randomScaleUni,randomScaleUni,randomScaleUni); } else randomScale = new Vector3(Random.Range(curTemplate.scaleRandMin.x,curTemplate.scaleRandMax.x),Random.Range(curTemplate.scaleRandMin.y,curTemplate.scaleRandMax.y),Random.Range(curTemplate.scaleRandMin.z,curTemplate.scaleRandMax.z)); Vector3 finalScale = curTemplate.scaleAbsolute == true ? randomScale : new Vector3 (randomScale.x * newObject.transform.localScale.x, randomScale.y * newObject.transform.localScale.y, randomScale.z * newObject.transform.localScale.z); //7 : If we have a group, add the object to the group if(curTemplate.groupObjects == true) { bool doGroup = false; //if group is missing - (either not yet assigned based on selection, or does not exist in this scene) if(curTemplate.curGroup == null) { //if the group selected is not "nothing" - otherwise no grouping is done if(curTemplate.groupName != string.Empty) { //the group has a name - check if group exists in scene qb_Group testGroup = GetGroupWithName(curTemplate.groupName); //if it does exist, assign as curGroup if(testGroup == null) curTemplate.curGroup = CreateGroup(curTemplate.groupName); else curTemplate.curGroup = testGroup; doGroup = true; } } else doGroup = true; if(doGroup) curTemplate.curGroup.AddObject(newObject); } //8 : Scaling is applied after grouping to avoid float error newObject.transform.localScale = new Vector3(finalScale.x,finalScale.y,finalScale.z);//Random.Range(scaleMin.x,scaleMax.x),Random.Range(scaleMin.y,scaleMax.y),Random.Range(scaleMin.z,scaleMax.z));//spawnScale; }