Exemplo 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);
    }
Exemplo n.º 2
0
    // Makes a mesh from the given voxel set.
    public static void MakeMeshNative(VoxelSet <Vec4b> voxels, out Mesh mesh, out Material[] materials)
    {
        PointQuadList opaqueFaces      = new PointQuadList();
        PointQuadList transparentFaces = new PointQuadList();

        IntPtr voxelsPtr = voxels.Pin();

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

        MakeMeshFromQuadLists(opaqueFaces, transparentFaces, out mesh, out materials);

        obx_FreeFacesHandle(opaqueFaces.handle);
        obx_FreeFacesHandle(transparentFaces.handle);
    }
Exemplo n.º 3
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);
    }