public override void OnImportAsset(AssetImportContext ctx)
    {
        // Main asset
        var obj = new GameObject("MainModel");

        ctx.AddObjectToAsset("MainModel", obj);
        ctx.SetMainObject(obj);

        var         voxComp = obj.AddComponent <VoxelComponent>();
        MagicaFlags flags   = 0;

        if (trimEmptySpace)
        {
            flags |= MagicaFlags.Trim;
        }

        voxComp.LoadMagicaModel(ctx.assetPath, true, colliderType, flags);

        var meshFilter = obj.GetComponent <MeshFilter>();
        var mesh       = meshFilter.sharedMesh;

        ctx.AddObjectToAsset("Mesh", mesh);

        var meshRenderer = obj.GetComponent <MeshRenderer>();

        for (int i = 0; i < meshRenderer.sharedMaterials.Length; ++i)
        {
            ctx.AddObjectToAsset("Material_" + i, meshRenderer.sharedMaterials[i]);
        }

        if (includeRigidBody)
        {
            obj.AddComponent <Rigidbody>();
        }
    }
Beispiel #2
0
 public static extern unsafe IntPtr MagicaLoadModel([MarshalAs(UnmanagedType.LPStr)] String filepath, MagicaFlags flags);
Beispiel #3
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);
    }
Beispiel #4
0
 static extern IntPtr obx_MagicaLoadModel([MarshalAs(UnmanagedType.LPStr)] String str, MagicaFlags flags);