Exemplo n.º 1
0
        /// Converts a GeometryPool into a BrushSample.
        static BrushSample GetBrushSample(GeometryPool geomPool,
                                          List <Stroke> strokes,
                                          Matrix4x4 mat44)
        {
            var sample = new BrushSample();

            GetMeshSample(geomPool, mat44, sample);

            var vertexLayout = geomPool.Layout;

            // Used for shader binding.
            sample.brush = strokes[0].m_BrushGuid;

            // Optional StrokeInfo, this can be disabled to improve performance.
            sample.stroke = GetStrokeBatchInfo(strokes);

            return(sample);
        }
Exemplo n.º 2
0
 private void InitializeItems()
 {
     DataSource = new BrushSample[]
     {
         new BrushSample("Hard Round 1 pixel", Resources.BrushHardRound1px),
         new BrushSample("Hard Round 3 pixels", Resources.BrushHardRound3px),
         new BrushSample("Hard Round 5 pixels", Resources.BrushHardRound5px),
         new BrushSample("Hard Round 9 pixels", Resources.BrushHardRound9px),
         new BrushSample("Hard Round 13 pixels", Resources.BrushHardRound13px),
         new BrushSample("Hard Round 19 pixels", Resources.BrushHardRound19px),
         new BrushSample("Soft Round 5 pixels", Resources.BrushSoftRound5px),
         new BrushSample("Soft Round 9 pixels", Resources.BrushSoftRound9px),
         new BrushSample("Soft Round 13 pixels", Resources.BrushSoftRound13px),
         new BrushSample("Soft Round 17 pixels", Resources.BrushSoftRound17px),
         new BrushSample("Soft Round 21 pixels", Resources.BrushSoftRound21px),
         new BrushSample("Soft Round 27 pixels", Resources.BrushSoftRound27px),
         new BrushSample("Airbrush Hard Round 9 pixels", Resources.AirBrushHardRound9px),
         new BrushSample("Airbrush Hard Round 13 pixels", Resources.AirBrushHardRound13px),
         new BrushSample("Airbrush Hard Round 19 pixels", Resources.AirBrushHardRound19px),
         new BrushSample("Spatter 14 pixels", Resources.BrushSpatter14px),
         new BrushSample("Spatter 24 pixels", Resources.BrushSpatter24px),
         new BrushSample("Spatter 27 pixels", Resources.BrushSpatter27px),
         new BrushSample("Spatter 39 pixels", Resources.BrushSpatter39px),
         new BrushSample("Spatter 46 pixels", Resources.BrushSpatter46px),
         new BrushSample("Spatter 59 pixels", Resources.BrushSpatter59px),
         new BrushSample("Dune Grass 112 pixels", Resources.BrushDuneGrass112px),
         new BrushSample("Grass 134 pixels", Resources.BrushGrass134px),
         new BrushSample("Scattered Maple Leaves 74 pixels", Resources.BrushScatteredMapleLeaves74px),
         new BrushSample("Scattered Leaves 95 pixels", Resources.BrushScatteredLeaves95px),
         new BrushSample("Flowing Stars 29 pixels", Resources.BrushFlowingStars29px),
         new BrushSample("Fuzzball 192 pixels", Resources.BrushFuzzball192px),
         new BrushSample("Chalk 36 pixels", Resources.BrushChalk36px),
         new BrushSample("Charcoal Large Smear 36 pixels", Resources.BrushCharcoalLargeSmear36px),
         new BrushSample("Hard Pastel On Canvas 33 pixels", Resources.BrushHardPastelOnCanvas33px),
         new BrushSample("Oil Pastel Large 63 pixels", Resources.BrushOilPastelLarge63px),
         new BrushSample("Dry Brush Tip Light Flow 66 pixels", Resources.BrushDryBrushTipLightFlow66px),
         new BrushSample("Dry Brush 39 pixels", Resources.BrushDryBrush39px),
     };
 }
Exemplo n.º 3
0
        protected override void OnDrawItem(DrawComboBoxItemEventArgs e)
        {
            BrushSample brushSample = Items[e.ItemIndex] as BrushSample;

            if (brushSample == null)
            {
                base.OnDrawItem(e);
                return;
            }

            if (e.IsSelected)
            {
                e.PaintSelectedBackground();
            }
            else
            {
                e.PaintNormalBackground();
            }

            Rectangle sampleBounds = new Rectangle(e.Bounds.Location, _brushSampleSize);

            sampleBounds.X += (e.Bounds.Width - _brushSampleSize.Width) / 2;
            sampleBounds.Y += (e.Bounds.Height - _brushSampleSize.Height) / 2;

            Rectangle boundingLineBounds = sampleBounds;

            boundingLineBounds.Offset(-1, -1);
            boundingLineBounds.Width  += 1;
            boundingLineBounds.Height += 1;

            using (Pen p = new Pen(Color.Black))
            {
                e.Graphics.DrawRectangle(p, boundingLineBounds);
            }

            e.Graphics.DrawImage(brushSample.BrushSampleImage, sampleBounds);
        }
Exemplo n.º 4
0
        // -------------------------------------------------------------------------------------------- //
        // Export Logic
        // -------------------------------------------------------------------------------------------- //

        /// Exports either all brush strokes or the given selection to the specified file.
        static public void ExportPayload(string outputFile)
        {
            // Would be nice to find a way to kick this off automatically.
            // Redundant calls are ignored.
            if (!InitUsd.Initialize())
            {
                return;
            }

            // Unity is left handed (DX), USD is right handed (GL)
            var payload      = ExportCollector.GetExportPayload(AxisConvention.kUsd);
            var brushCatalog = BrushCatalog.m_Instance;

            // The Scene object provids serialization methods arbitrary C# objects to USD.
            USD.NET.Scene scene = USD.NET.Scene.Create(outputFile);

            // The target time at which samples will be written.
            //
            // In this case, all data is being written to the "default" time, which means it can be
            // overridden by animated values later.
            scene.Time = null;

            // Bracketing times to specify the valid animation range.
            scene.StartTime = 1.0;
            scene.EndTime   = 1.0;

            const string kGeomName   = "/Geom";
            const string kCurvesName = "/Curves";

            string path = "";

            AddSketchRoot(scene, GetSketchPath()); // Create: </Sketch>

            CreateXform(scene, GetStrokesPath());  // Create: </Sketch/Strokes>
            CreateXform(scene, GetModelsPath());   // Create: </Sketch/Models>

            // Main export loop.
            try
            {
                foreach (ExportUtils.GroupPayload group in payload.groups)
                {
                    // Example: </Sketch/Strokes/Group_0>
                    path = GetGroupPath(group.id);
                    CreateXform(scene, path);

                    // Example: </Sketch/Strokes/Group_0/Geom>
                    CreateXform(scene, path + kGeomName);

                    // Example: </Sketch/Strokes/Group_0/Curves>
                    CreateXform(scene, path + kCurvesName);

                    int iBrushMeshPayload = -1;
                    foreach (var brushMeshPayload in group.brushMeshes)
                    {
                        ++iBrushMeshPayload;
                        // Conditionally moves Normal into Texcoord1 so that the normal semantic is respected.
                        // This only has an effect when layout.bFbxExportNormalAsTexcoord1 == true.
                        // Note that this modifies the GeometryPool in place.
                        FbxUtils.ApplyFbxTexcoordHack(brushMeshPayload.geometry);

                        // Brushes are expected to be batched by type/GUID.
                        Guid   brushGuid = brushMeshPayload.strokes[0].m_BrushGuid;
                        string brushName = "/" +
                                           SanitizeIdentifier(brushCatalog.GetBrush(brushGuid).DurableName) + "_";

                        // Example: </Sketch/Strokes/Group_0/Geom/Marker_0>
                        string meshPath = path + kGeomName + brushName;

                        // Example: </Sketch/Strokes/Group_0/Curves/Marker_0>
                        string curvePath = path + kCurvesName + brushName;

                        var geomPool       = brushMeshPayload.geometry;
                        var strokes        = brushMeshPayload.strokes;
                        var mat44          = Matrix4x4.identity;
                        var meshPrimPath   = new pxr.SdfPath(meshPath + iBrushMeshPayload.ToString());
                        var curvesPrimPath = new pxr.SdfPath(curvePath + iBrushMeshPayload.ToString());

                        //
                        // Geometry
                        //
                        BrushSample brushSample = GetBrushSample(geomPool, strokes, mat44);

                        // Write the BrushSample to the same point in the scenegraph at which it exists in Tilt
                        // Brush. Notice this method is Async, it is queued to a background thread to perform I/O
                        // which means it is not safe to read from the scene until WaitForWrites() is called.
                        scene.Write(meshPrimPath, brushSample);

                        //
                        // Stroke Curves
                        //
                        var curvesSample = GetCurvesSample(payload, strokes, Matrix4x4.identity);
                        scene.Write(curvesPrimPath, curvesSample);

                        //
                        // Materials
                        //
                        double?oldTime = scene.Time;
                        scene.Time = null;

                        string materialPath = CreateMaterialNetwork(
                            scene,
                            brushMeshPayload.exportableMaterial,
                            GetStrokesPath());

                        BindMaterial(scene, meshPrimPath.ToString(), materialPath);
                        BindMaterial(scene, curvesPrimPath.ToString(), materialPath);

                        scene.Time = oldTime;
                    }
                }

                //
                // Models
                //

                var knownModels = new Dictionary <Model, string>();

                int iModelMeshPayload = -1;
                foreach (var modelMeshPayload in payload.modelMeshes)
                {
                    ++iModelMeshPayload;
                    var modelId         = modelMeshPayload.modelId;
                    var modelNamePrefix = "/Model_"
                                          + SanitizeIdentifier(modelMeshPayload.model.GetExportName())
                                          + "_";
                    var modelName = modelNamePrefix + modelId;

                    var xf = modelMeshPayload.xform;
                    // Geometry pools may be repeated and should be turned into references.
                    var geomPool = modelMeshPayload.geometry;

                    var modelRootPath = new pxr.SdfPath(GetModelsPath() + modelName);

                    // Example: </Sketch/Models/Model_Andy_0>
                    CreateXform(scene, modelRootPath, xf);

                    // Example: </Sketch/Models/Model_Andy_0/Geom>
                    CreateXform(scene, modelRootPath + kGeomName);

                    string modelPathToReference;
                    if (knownModels.TryGetValue(modelMeshPayload.model, out modelPathToReference) &&
                        modelPathToReference != modelRootPath)
                    {
                        // Create an Xform, note that the world transform here will override the referenced model.
                        var meshXf = new MeshXformSample();
                        meshXf.transform = xf;
                        scene.Write(modelRootPath, meshXf);
                        // Add a USD reference to previously created model.
                        var prim = scene.Stage.GetPrimAtPath(modelRootPath);
                        prim.GetReferences().AddReference("", new pxr.SdfPath(modelPathToReference));
                        continue;
                    }

                    // Example: </Sketch/Models/Geom/Model_Andy_0/Mesh_0>
                    path = modelRootPath + kGeomName + "/Mesh_" + iModelMeshPayload.ToString();

                    var meshPrimPath = new pxr.SdfPath(path);
                    var meshSample   = new MeshSample();

                    GetMeshSample(geomPool, Matrix4x4.identity, meshSample);
                    scene.Write(path, meshSample);
                    scene.Stage.GetPrimAtPath(new pxr.SdfPath(path)).SetInstanceable(true);

                    //
                    // Materials
                    //

                    // Author at default time.
                    double?oldTime = scene.Time;
                    scene.Time = null;

                    // Model materials must live under the model root, since we will reference the model.
                    string materialPath = CreateMaterialNetwork(
                        scene,
                        modelMeshPayload.exportableMaterial,
                        modelRootPath);
                    BindMaterial(scene, meshPrimPath.ToString(), materialPath);

                    // Continue authoring at the desired time index.
                    scene.Time = oldTime;

                    //
                    // Setup to be referenced.
                    //
                    if (!knownModels.ContainsKey(modelMeshPayload.model))
                    {
                        knownModels.Add(modelMeshPayload.model, modelRootPath);
                    }
                }
            }
            catch
            {
                scene.Save();
                scene.Close();
                throw;
            }

            // Save will force a sync with all async reads and writes.
            scene.Save();
            scene.Close();
        }
Exemplo n.º 5
0
 private void InitializeItems()
 {
     DataSource = new BrushSample[]
         {
             new BrushSample("Hard Round 1 pixel", Resources.BrushHardRound1px),
             new BrushSample("Hard Round 3 pixels", Resources.BrushHardRound3px),
             new BrushSample("Hard Round 5 pixels", Resources.BrushHardRound5px),
             new BrushSample("Hard Round 9 pixels", Resources.BrushHardRound9px),
             new BrushSample("Hard Round 13 pixels", Resources.BrushHardRound13px),
             new BrushSample("Hard Round 19 pixels", Resources.BrushHardRound19px),
             new BrushSample("Soft Round 5 pixels", Resources.BrushSoftRound5px),
             new BrushSample("Soft Round 9 pixels", Resources.BrushSoftRound9px),
             new BrushSample("Soft Round 13 pixels", Resources.BrushSoftRound13px),
             new BrushSample("Soft Round 17 pixels", Resources.BrushSoftRound17px),
             new BrushSample("Soft Round 21 pixels", Resources.BrushSoftRound21px),
             new BrushSample("Soft Round 27 pixels", Resources.BrushSoftRound27px),
             new BrushSample("Airbrush Hard Round 9 pixels", Resources.AirBrushHardRound9px),
             new BrushSample("Airbrush Hard Round 13 pixels", Resources.AirBrushHardRound13px),
             new BrushSample("Airbrush Hard Round 19 pixels", Resources.AirBrushHardRound19px),
             new BrushSample("Spatter 14 pixels", Resources.BrushSpatter14px),
             new BrushSample("Spatter 24 pixels", Resources.BrushSpatter24px),
             new BrushSample("Spatter 27 pixels", Resources.BrushSpatter27px),
             new BrushSample("Spatter 39 pixels", Resources.BrushSpatter39px),
             new BrushSample("Spatter 46 pixels", Resources.BrushSpatter46px),
             new BrushSample("Spatter 59 pixels", Resources.BrushSpatter59px),
             new BrushSample("Dune Grass 112 pixels", Resources.BrushDuneGrass112px),
             new BrushSample("Grass 134 pixels", Resources.BrushGrass134px),
             new BrushSample("Scattered Maple Leaves 74 pixels", Resources.BrushScatteredMapleLeaves74px),
             new BrushSample("Scattered Leaves 95 pixels", Resources.BrushScatteredLeaves95px),
             new BrushSample("Flowing Stars 29 pixels", Resources.BrushFlowingStars29px),
             new BrushSample("Fuzzball 192 pixels", Resources.BrushFuzzball192px),
             new BrushSample("Chalk 36 pixels", Resources.BrushChalk36px),
             new BrushSample("Charcoal Large Smear 36 pixels", Resources.BrushCharcoalLargeSmear36px),
             new BrushSample("Hard Pastel On Canvas 33 pixels", Resources.BrushHardPastelOnCanvas33px),
             new BrushSample("Oil Pastel Large 63 pixels", Resources.BrushOilPastelLarge63px),
             new BrushSample("Dry Brush Tip Light Flow 66 pixels", Resources.BrushDryBrushTipLightFlow66px),
             new BrushSample("Dry Brush 39 pixels", Resources.BrushDryBrush39px),
         };
 }