Ejemplo n.º 1
0
    /// Loads a MagicaVoxel model into the current model.
    public void LoadMagicaModel(string magicaVoxelFile, bool retainVoxels, VoxelFactory.ColliderType colliderType, MagicaFlags flags)
    {
        Clear();

        this.colliderType = colliderType;

        PointQuadList opaqueFaces      = new PointQuadList();
        PointQuadList transparentFaces = new PointQuadList();

        IntPtr model = OpenBoxNative.MagicaLoadModel(magicaVoxelFile, flags);

        OpenBoxNative.MagicaExtractFaces(model, ref opaqueFaces, ref transparentFaces);

        if (retainVoxels || colliderType != VoxelFactory.ColliderType.None)
        {
            // Copy voxels over to the C# side
            voxels = new VoxelSet <Color32>(OpenBoxNative.MagicaModelSize(model));
            OpenBoxNative.MagicaCopyVoxels(voxels.Pin(), model);
            voxels.Unpin();

            // TODO: Calculate colliders natively
            UpdateColliders();
        }

        OpenBoxNative.MagicaFreeModel(model);

        MakeMeshFromQuadLists(opaqueFaces, transparentFaces);

        OpenBoxNative.FreeFacesHandle(opaqueFaces.handle);
        OpenBoxNative.FreeFacesHandle(transparentFaces.handle);
    }
Ejemplo n.º 2
0
    /// Turns the current voxel set into a mesh, replacing any currently attached mesh.
    public void UpdateMesh()
    {
        MeshFilter mf = GetComponent <MeshFilter>();

        // TODO: Remove old mesh?

        PointQuadList opaqueFaces      = new PointQuadList();
        PointQuadList transparentFaces = new PointQuadList();

        IntPtr voxelsPtr = voxels.Pin();

        OpenBoxNative.ExtractFaces(voxelsPtr, voxels.Size, ref opaqueFaces, ref transparentFaces);
        voxels.Unpin();

        MakeMeshFromQuadLists(opaqueFaces, transparentFaces);

        OpenBoxNative.FreeFacesHandle(opaqueFaces.handle);
        OpenBoxNative.FreeFacesHandle(transparentFaces.handle);
    }