Exemplo n.º 1
0
    public override void OnImportAsset(AssetImportContext ctx)
    {
        // Attempt to generate models for each frame
        string    expectedImage = Path.Combine(Path.GetDirectoryName(ctx.assetPath), Path.GetFileNameWithoutExtension(ctx.assetPath));
        Texture2D sourceTexture = AssetDatabase.LoadAssetAtPath <Texture2D>(expectedImage);

        if (sourceTexture == null)
        {
            ctx.LogImportError($"Failed to load associated texture at '{expectedImage}'");
            return;
        }

        ctx.DependsOnSourceAsset(expectedImage);
        IVoxelVolume textureVolume = new Texture2DVoxelVolume(sourceTexture);

        // Layers will be stacked next to each other progressing
        int layerCount = m_ImportSettings.GetTotalChannelCountRounded(4) / 4;

        Vector3Int cellSize, frameStep, channelStep;

        if (m_ImportFrameOrientation == LayoutOrientation.Vertical)
        {
            cellSize   = new Vector3Int();
            cellSize.x = sourceTexture.width / layerCount;
            cellSize.y = sourceTexture.height / m_ImportSettings.FrameCount;

            frameStep   = new Vector3Int(0, cellSize.y, 0);
            channelStep = new Vector3Int(cellSize.x, 0, 0);
        }
        else
        {
            cellSize   = new Vector3Int();
            cellSize.x = sourceTexture.width / m_ImportSettings.FrameCount;
            cellSize.y = sourceTexture.height / layerCount;

            frameStep   = new Vector3Int(cellSize.x, 0, 0);
            channelStep = new Vector3Int(0, cellSize.y, 0);
        }

        CommonVoxelImporter importer  = new CommonVoxelImporter(textureVolume, m_ImportSettings, cellSize, frameStep, channelStep);
        MeshSheet           meshSheet = importer.GenerateMeshSheet();

        ctx.AddObjectToAsset("Meshes", meshSheet);
        for (int i = 0; i < meshSheet.FrameCount; ++i)
        {
            Mesh mesh = meshSheet.GetMeshAtFrame(i);
            mesh.name = Path.GetFileNameWithoutExtension(ctx.assetPath) + "_MeshFrame_" + i;
            ctx.AddObjectToAsset("MeshFrame_" + i, mesh);
        }

        ctx.SetMainObject(meshSheet);
    }
Exemplo n.º 2
0
        public MeshSheet GenerateMeshSheet()
        {
            MeshSheetFrame[] frames = new MeshSheetFrame[m_Settings.FrameCount];

            for (int i = 0; i < frames.Length; ++i)
            {
                int f = i;
                if (m_Settings.FlipFrameDirection)
                {
                    f = frames.Length - i - 1;
                }

                frames[f] = GenerateFrame(i);
            }

            MeshSheet sheet = MeshSheet.CreateNew(frames);

            sheet.PlayMode = m_Settings.PlaybackMode;
            return(sheet);
        }