archgame
|
|
« Reply #166 on: February 01, 2019, 10:52:07 PM » |
|
Coming from the world of architecture, I've always been more comfortable modeling in Rhino and Grasshopper than Unity ( not to mention that the scene navigation camera makes working in the interior sphere very difficult to navigate and Unity was going through a number of versions and the placed models would break their links, and since I've created the octree loading system, the city is fragmented into a number of scenes, while it is still a single file in Rhino), however Rhino has certain limitations as far as types of objects unity can import. To circumvent this issue, I've made some editor tools that help us translate information from rhino into Unity. I've provided the source code for anyone looking to begin making their own editor tools at the bottom. In the images you can see that the tools take points and lines from rhino and turn them into lights in unity, while also taking surfaces from rhino and turning them into climbing surfaces in unity by making their origin point not 0,0,0 and adding the required colliders and materials. I've made a number of other scripts, but most of them aren't Unity focused, but more focused on automatically exporting meshes from rhino and putting them in the right location within the Unity project. (also made a few gifs showing the before and after detailing of the architecture). using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEditor;
namespace RhinoInside { public class RhinoIn : ScriptableWizard { #region MenuItem //[ExecuteInEditMode] [MenuItem("Window/Rhino/Lights")] private static void RhinoLights() { Debug.Log("Rhino/Lights"); //CSV structure: Light Type, posX, posY, posZ, rotX, rotY, rotZ, scene, R, G, B, Intensity, Optional: EposX, EposY, EposZ List<string[]> parsedData = parseCSV(Application.dataPath + "/LIGHT.csv");
//set up parent GameObject parent = new GameObject("Lights");
for (int i = 0; i < parsedData.Count; i++) { Debug.Log("parsedData.Count: " + parsedData.Count); string[] row = parsedData[i]; if (row[0] == "Point") //instantiate point light from csv info { GameObject obj = InstPointLight( float.Parse(row[1]), float.Parse(row[2]), float.Parse(row[3]), row[7], float.Parse(row[8]), float.Parse(row[9]), float.Parse(row[10]), float.Parse(row[11])); obj.transform.SetParent(parent.transform); } else if (row[0] == "Spot") //instantiate spot light from csv info { GameObject obj = InstSpotLight( float.Parse(row[1]), float.Parse(row[2]), float.Parse(row[3]), float.Parse(row[4]), float.Parse(row[5]), float.Parse(row[6]), row[7], float.Parse(row[8]), float.Parse(row[9]), float.Parse(row[10]), float.Parse(row[11])); obj.transform.SetParent(parent.transform); }
} }
[MenuItem("Window/Rhino/Climbing Surfaces")] private static void RhinoClimbingSurfaces() { Debug.Log("Rhino/Climbing Surfaces"); //CSV structure: Name, posX, posY, posZ, LookX, LookY, LookZ, UpX, UpY, UpZ, scene, width, height List<string[]> parsedData = parseCSV(Application.dataPath + "\\CLIMB.csv");
//set up parent GameObject parent = new GameObject("Climbing"); PhysicMaterial NoFriction = null; string[] filenames = Directory.GetFiles(Application.dataPath, "*.physicMaterial", SearchOption.AllDirectories); for (int i = 0; i<filenames.Length;i++) { if(filenames[i].Contains("NoFriction.physicMaterial")) { NoFriction = (PhysicMaterial)AssetDatabase.LoadAssetAtPath(filenames[i].Replace(Application.dataPath, "Assets"), typeof(PhysicMaterial)); } }
for (int i = 0; i < parsedData.Count; i++) { string[] row = parsedData[i]; GameObject obj = InstClimbingSurface( float.Parse(row[1]), float.Parse(row[2]), float.Parse(row[3]), //position float.Parse(row[4]), float.Parse(row[5]), float.Parse(row[6]), //look at vector float.Parse(row[7]), float.Parse(row[8]), float.Parse(row[9]), //up vector row[10], //scene float.Parse(row[11]), float.Parse(row[12]), //width/height NoFriction); //phsyical material obj.transform.SetParent(parent.transform); } } #endregion
#region Instantiation Functions private static GameObject InstPointLight(float posX, float posY, float posZ, string scene, float R, float G, float B, float Intensity) { GameObject obj = new GameObject("PointLight"); obj.transform.position = new Vector3(posX, posY, posZ);
Light light = obj.AddComponent<Light>(); light.color = new Color(R, G, B); light.intensity = Intensity; return obj; }
private static GameObject InstSpotLight(float posX, float posY, float posZ, float LookX, float LookY, float LookZ, string scene, float R, float G, float B, float Intensity) { GameObject obj = new GameObject("SpotLight"); obj.transform.position = new Vector3(posX, posY, posZ); obj.transform.LookAt(new Vector3(LookX, LookY, LookZ));
Light light = obj.AddComponent<Light>(); light.color = new Color(R, G, B); light.type = LightType.Spot; light.intensity = Intensity; return obj; }
private static GameObject InstClimbingSurface(float posX, float posY, float posZ, float LookX, float LookY, float LookZ, float UpX, float UpY, float UpZ, string scene, float width, float height, PhysicMaterial mat) { GameObject obj = new GameObject("ClimbingSurface"); obj.transform.position = new Vector3(posX, posY, posZ); obj.transform.LookAt(new Vector3(LookX, LookY, LookZ), new Vector3(UpX, UpY, UpZ));
obj.layer = LayerMask.NameToLayer("Climb"); //make layer climb BoxCollider col = obj.AddComponent<BoxCollider>(); col.isTrigger = true; //check is trigger col.material = mat;//add NoFriction material to collider Vector3 size = new Vector3(height, width, 0.01f); //create vector for box size col.size = size;//set collider height return obj; } #endregion
#region Generic Functions public static List<string[]> parseCSV(string path) { //https://danashurst.com/parsing-a-csv-file/ List<string[]> parsedData = new List<string[]>(); using (StreamReader readFile = new StreamReader(path)) { string line; string[] row; while ((line = readFile.ReadLine()) != null) { row = line.Split(','); parsedData.Add(row); } } return parsedData; } #endregion }
}
Still haven't decided on a name for the game yet. I'm going to go back to working on the urban materials and shaders before I dive deep into lighting.
|