public void Voxelize(Mesh mesh, Bounds bounds)
        {
            if (data != null)
            {
                data.Dispose();
                data = null;
            }

            // data = GPUVoxelizer.Voxelize(voxelizer, mesh, mesh.bounds, resolution, true, false);
            data = GPUVoxelizer.Voxelize(
                voxelizer, mesh, bounds, Mathf.Max(10, resolution) >> _level,
                volume, false
                );
        }
예제 #2
0
        protected void Sample()
        {
            skinned.BakeMesh(mesh);

            // expand bounds to contain all bounds of animated meshes
            bounds.Encapsulate(mesh.bounds.min);
            bounds.Encapsulate(mesh.bounds.max);

            if (data != null)
            {
                data.Dispose();
                data = null;
            }
            data = GPUVoxelizer.Voxelize(voxelizer, bounds, mesh, resolution);
        }
예제 #3
0
        void Update()
        {
            if (data == null)
            {
                return;
            }

            data.Dispose();

            var mesh = Sample();

            data = GPUVoxelizer.Voxelize(voxelizer, mesh, count, (type == MeshType.Volume));

            Compute(updateKernel, data, Time.deltaTime);
        }
        void Update()
        {
            if (data == null)
            {
                return;
            }

            data.Dispose();

            var mesh = Sample();

            data = GPUVoxelizer.Voxelize(voxelizer, mesh, count, (type == MeshType.Volume));

            Compute(updateKernel, data, Time.deltaTime);
            block.SetBuffer(kParticleBufferKey, particleBuffer);
            _renderer.SetPropertyBlock(block);
        }
예제 #5
0
    // Start is called before the first frame update
    public void Voxelize()
    {
        var          mesh = GetComponent <MeshFilter>().mesh;
        GPUVoxelData data = GPUVoxelizer.Voxelize(
            voxelizer, // ComputeShader (Voxelizer.compute)
            mesh,      // a target mesh
            transform.worldToLocalMatrix,
            1.0f
            );

        gridData = data.VoxeltoGridVoxel(transform.localToWorldMatrix);
        WorldDataManager.Instance.ActiveWorld.CreateNewObjectFromGridData(gridData, new Voxel());

        // need to release a voxel buffer
        data.Dispose();
        Destroy(gameObject);
    }
        void Start()
        {
            var mesh = Sample();

            data = GPUVoxelizer.Voxelize(voxelizer, mesh, count, (type == MeshType.Volume));
            var pointMesh = BuildPoints(data);

            particleBuffer = new ComputeBuffer(pointMesh.vertexCount, Marshal.SizeOf(typeof(VParticle_t)));

            GetComponent <MeshFilter>().sharedMesh = pointMesh;

            block     = new MaterialPropertyBlock();
            _renderer = GetComponent <Renderer>();
            _renderer.GetPropertyBlock(block);

            setupKernel  = new Kernel(particleUpdate, kSetupKernelKey);
            updateKernel = new Kernel(particleUpdate, kUpdateKernelKey);

            Setup(data);
        }
예제 #7
0
        public void InitMeshVoxelizer()
        {
            var mesh = SampleMesh();

            if (mesh == null)
            {
                return;
            }
            //defaultMesh = mesh;
            //defaultMaterial =this.spawnObj.GetComponent<MeshRenderer>().sharedMaterial;

            Bounds fireBounds  = this.mediator.bounds;
            Bounds spawnBounds = this.spawnObj.GetComponent <Renderer>().bounds;

            //Debug.Log("box min: " + this.mediator.bounds.min);
            //Debug.Log("box center: " + this.mediator.bounds.center);
            //Debug.Log("box size: " + this.mediator.bounds.size);
            //Debug.Log("spawn box center: " + spawnBounds.center);
            //Debug.Log("spawn box min: " + spawnBounds.min);
            //Debug.Log("spawn box max: " + spawnBounds.max);
            //Debug.Log("spawn box extends: " + spawnBounds.extents);
            //Debug.Log("spawn box size: " + spawnBounds.size);
            //Debug.Log("spawn mesh box center: " + mesh.bounds.center);
            //Debug.Log("spawn mesh box size: " + mesh.bounds.size);

            this.SetObjectCenter();
            this.SetObjectRadius();

            numOfVoxels = Mathf.ClosestPowerOfTwo(this.mediator.fluidSimulator3D.m_width);

            this.gpuVoxelizer = new GPUVoxelizer();
            this.gpuVoxelizer.InitVoxelization(mesh, this.mediator.bounds, numOfVoxels);
            this.voxelsInBounds = gpuVoxelizer.Voxelize(voxelizer, mesh, this.spawnObj.transform, true);

            this.GetComponent <MeshFilter>().sharedMesh = VoxelMesh.Build(this.voxelsInBounds.GetData(), this.voxelsInBounds.UnitLength, true);

            //Debug.LogFormat("!!!!!!!!!!!!!!!!!!!!! Num of triangles: {0}", mesh.triangles.Length);
        }
        void Start()
        {
            data = GPUVoxelizer.Voxelize(voxelizer, mesh, count);

            int[] indices;
            var   pointMesh = BuildPoints(data, out indices);

            particleBuffer = new ComputeBuffer(pointMesh.vertexCount, Marshal.SizeOf(typeof(VParticle_t)));
            indexBuffer    = new ComputeBuffer(pointMesh.vertexCount, Marshal.SizeOf(typeof(int)));
            indexBuffer.SetData(indices);

            GetComponent <MeshFilter>().sharedMesh = pointMesh;

            block    = new MaterialPropertyBlock();
            renderer = GetComponent <Renderer>();
            renderer.GetPropertyBlock(block);
            bounds = mesh.bounds;

            setupKernel  = new Kernel(particleUpdate, kSetupKernelKey);
            updateKernel = new Kernel(particleUpdate, kUpdateKernelKey);

            Setup();
        }