Exemplo n.º 1
0
        public static void RemoveRenderEvent(Camera camera, CameraEventHandler onPostRenderEvent)
        {
            if (camera == null)
            {
                return;
            }

            RenderEvent renderEvent = camera.GetComponent <RenderEvent>();

            if (renderEvent != null)
            {
                renderEvent.OnPostRenderEvent -= onPostRenderEvent;
            }
        }
        private MeshVoxelizer m_voxelizer; // calling the Meshvoxelizer script which is in the scripts folder /Assets

        void Start()
        {
            RenderEvent.AddRenderEvent(Camera.main, DrawOutline);  // notify camera of render event; needed in the main camera to render the voxels

            MeshFilter   filter   = GetComponent <MeshFilter>();   // takes the mesh filter of mesh this script is attached to
            MeshRenderer renderer = GetComponent <MeshRenderer>(); // takes the mesh renderer of mesh this script is attached to

            if (filter == null || renderer == null)                // if the mesh is not present in the parent then check in the children for meshes
            {
                filter   = GetComponentInChildren <MeshFilter>();  // same as above
                renderer = GetComponentInChildren <MeshRenderer>();
            }

            if (filter == null || renderer == null)
            {
                return;
            }

            renderer.enabled = false;                                                                      //set renderer to false?

            Mesh     mesh = filter.mesh;                                                                   // derives only the mesh from the mesh filter
            Material mat  = renderer.material;                                                             // derives material from renderer

            Box3 bounds = new Box3(mesh.bounds.min, mesh.bounds.max);                                      // check for bounding box's bounds; Box3 is a function defined in the current namespace; mesh.bounds: This is the axis-aligned bounding box of the mesh in its local space (that is, not affected by the transform)

            m_voxelizer = new MeshVoxelizer(size, size, size);                                             // voxelize mesh with given size resolution
            m_voxelizer.Voxelize(mesh.vertices, mesh.triangles, bounds);                                   // access the .Voxelize public void function in MeshVoxelizer.cs; takes in the mesh's vertices triangles and bounds

            Vector3 scale = new Vector3(bounds.Size.x / size, bounds.Size.y / size, bounds.Size.z / size); // scale of each individual voxel in local space
            Vector3 m     = new Vector3(bounds.Min.x, bounds.Min.y, bounds.Min.z);

            mesh = CreateMesh(m_voxelizer.Voxels, scale, m);//come back to this


            //assign local positionns, scale and rotations to the voxelized mesh
            GameObject go = new GameObject("Voxelized");

            go.transform.parent        = transform;// transform of parent applied to voxelized child gameobject "voxelized" and is instantiated at the position of parent
            go.transform.localPosition = Vector3.zero;
            go.transform.localScale    = Vector3.one;
            go.transform.localRotation = Quaternion.identity;

            filter   = go.AddComponent <MeshFilter>();
            renderer = go.AddComponent <MeshRenderer>();

            filter.mesh       = mesh; // assign the new mesh created after voxelization to the mesh filter
            renderer.material = mat;  // do the same for material as well
        }
Exemplo n.º 3
0
        void Start()
        {
            RenderEvent.AddRenderEvent(Camera.main, DrawOutline);

            MeshFilter   filter   = GetComponent <MeshFilter>();
            MeshRenderer renderer = GetComponent <MeshRenderer>();

            if (filter == null || renderer == null)
            {
                filter   = GetComponentInChildren <MeshFilter>();
                renderer = GetComponentInChildren <MeshRenderer>();
            }

            if (filter == null || renderer == null)
            {
                return;
            }

            renderer.enabled = false;

            Mesh     mesh = filter.mesh;
            Material mat  = renderer.material;

            Box3 bounds = new Box3(mesh.bounds.min, mesh.bounds.max);

            m_voxelizer = new MeshVoxelizer(size, size, size);
            m_voxelizer.Voxelize(mesh.vertices, mesh.triangles, bounds);

            Vector3 scale = new Vector3(bounds.Size.x / size, bounds.Size.y / size, bounds.Size.z / size);
            Vector3 m     = new Vector3(bounds.Min.x, bounds.Min.y, bounds.Min.z);

            mesh = CreateMesh(m_voxelizer.Voxels, scale, m);

            GameObject go = new GameObject("Voxelized");

            go.transform.parent        = transform;
            go.transform.localPosition = Vector3.zero;
            go.transform.localScale    = Vector3.one;
            go.transform.localRotation = Quaternion.identity;

            filter   = go.AddComponent <MeshFilter>();
            renderer = go.AddComponent <MeshRenderer>();

            filter.mesh       = mesh;
            renderer.material = mat;
        }
 /*private void FixedUpdate()// is not present originally; might have to be called only during start()
  * {
  *  RenderEvent.AddRenderEvent(Camera.main, DrawOutline);
  *
  *  MeshFilter filter = GetComponent<MeshFilter>();
  *  MeshRenderer renderer = GetComponent<MeshRenderer>();
  *
  *  if (filter == null || renderer == null)
  *  {
  *      filter = GetComponentInChildren<MeshFilter>();
  *      renderer = GetComponentInChildren<MeshRenderer>();
  *  }
  *
  *  if (filter == null || renderer == null) return;
  *
  *  renderer.enabled = false;
  *
  *  Mesh mesh = filter.mesh;
  *  Material mat = renderer.material;
  *
  *  Box3 bounds = new Box3(mesh.bounds.min, mesh.bounds.max);
  *
  *  m_voxelizer = new MeshVoxelizer(size, size, size);
  *  m_voxelizer.Voxelize(mesh.vertices, mesh.triangles, bounds);
  *
  *  Vector3 scale = new Vector3(bounds.Size.x / size, bounds.Size.y / size, bounds.Size.z / size);
  *  Vector3 m = new Vector3(bounds.Min.x, bounds.Min.y, bounds.Min.z);
  *  mesh = CreateMesh(m_voxelizer.Voxels, scale, m);
  *
  *  GameObject go = new GameObject("Voxelized");
  *  go.transform.parent = transform;
  *  go.transform.localPosition = Vector3.zero;
  *  go.transform.localScale = Vector3.one;
  *  go.transform.localRotation = Quaternion.identity;
  *
  *  filter = go.AddComponent<MeshFilter>();
  *  renderer = go.AddComponent<MeshRenderer>();
  *
  *  filter.mesh = mesh;
  *  renderer.material = mat;
  * }*/
 void OnDestroy()
 {
     RenderEvent.RemoveRenderEvent(Camera.main, DrawOutline);// finish render event after lines of AABB tree have been drawn; Drawoutlines function if defined below
 }
Exemplo n.º 5
0
 void OnDestroy()
 {
     RenderEvent.RemoveRenderEvent(Camera.main, DrawOutline);
 }