public void Import(string filename) { Scene scene = Scene.Open(filename); CommandGroup group = new CommandGroup(); var cameras = scene.ReadAll <CameraControllerSample>(); foreach (var camera in cameras) { CameraControllerSample sample = camera.sample; GameObject cameraPrefab = ResourceManager.GetPrefab(PrefabID.Camera); GameObject instance = SceneManager.InstantiateUnityPrefab(cameraPrefab); GameObject newObject = SceneManager.AddObject(instance); newObject.name = camera.path.GetName(); sample.CopyToCamera(newObject.GetComponent <CameraController>()); Maths.DecomposeMatrix(sample.transform, out Vector3 position, out Quaternion rotation, out Vector3 scale); newObject.transform.localPosition = position; newObject.transform.localRotation = rotation; newObject.transform.localScale = scale; } foreach (var m in scene.ReadAll <MeshSample>()) { MeshSample sample = m.sample; GameObject gobject = new GameObject(); gobject.name = m.path.GetName(); Maths.DecomposeMatrix(sample.transform, out Vector3 position, out Quaternion rotation, out Vector3 scale); gobject.transform.localPosition = position; gobject.transform.localRotation = rotation; gobject.transform.localScale = scale; Mesh mesh = new Mesh(); mesh.SetVertices(sample.points); mesh.SetNormals(sample.normals); mesh.SetUVs(0, sample.st as Vector2[]); mesh.SetTriangles(sample.faceVertexIndices, 0); MeshFilter meshFilter = gobject.AddComponent <MeshFilter>(); meshFilter.sharedMesh = mesh; MeshRenderer mr = gobject.AddComponent <MeshRenderer>(); mr.sharedMaterial = ResourceManager.GetMaterial(MaterialID.ObjectOpaque); gobject.AddComponent <MeshCollider>(); SceneManager.AddObject(gobject); } group.Submit(); scene.Close(); }
private static GameObject Create(PaintTools what, Color color) { GameObject rootObject = new GameObject(); rootObject.transform.parent = SceneManager.RightHanded; rootObject.transform.localPosition = Vector3.zero; rootObject.transform.localRotation = Quaternion.identity; rootObject.transform.localScale = Vector3.one; GameObject gobject = new GameObject(); gobject.transform.parent = rootObject.transform; gobject.name = Utils.CreateUniqueName(what == PaintTools.Volume ? "Volume" : "Paint"); gobject.transform.localPosition = Vector3.zero; gobject.transform.localRotation = Quaternion.identity; gobject.transform.localScale = Vector3.one; gobject.tag = "PhysicObject"; Mesh mesh = new Mesh { indexFormat = UnityEngine.Rendering.IndexFormat.UInt32 }; MeshFilter meshFilter = gobject.AddComponent <MeshFilter>(); meshFilter.mesh = mesh; MeshRenderer renderer = gobject.AddComponent <MeshRenderer>(); MaterialID materialId = color.a == 1f ? MaterialID.ObjectOpaque : MaterialID.ObjectTransparent; Material paintMaterial = ResourceManager.GetMaterial(materialId); renderer.sharedMaterial = paintMaterial; renderer.material.SetColor("_BaseColor", color); renderer.material.SetFloat("_Opacity", color.a); // Update scene data for live sync SceneManager.AddMaterialParameters(Utils.GetMaterialName(gobject), materialId, color); gobject.AddComponent <MeshCollider>(); if (what == PaintTools.Volume) { gobject.AddComponent <VolumeController>(); } else { gobject.AddComponent <PaintController>(); } return(gobject); }
// DEBUG public void InitDebugData() { Material debugMaterial = ResourceManager.GetMaterial(MaterialID.ObjectOpaque); DEBUG_filter = GetComponent <MeshFilter>(); DEBUG_render = GetComponent <MeshRenderer>(); DEBUG_render.sharedMaterial = debugMaterial; DEBUG_render.material.SetColor("_BaseColor", Color.red); DEBUG_render.material.SetFloat("_Opacity", 1.0f); DEBUG_positions = new List <Vector3>(); DEBUG_colors = new List <Color>(); DEBUG_indices = new List <int>(); DEBUG_normals = new List <Vector3>(); DEBUG_uvs = new List <Vector2>(); }