Exemplo n.º 1
0
            bool Bake(IGH_Param param, BakeOptions options, out ICollection <DB.ElementId> ids)
            {
                var geometryToBake = param.VolatileData.AllData(true).Select(x => x.ScriptVariable()).
                                     Select(x =>
                {
                    switch (x)
                    {
                    case Rhino.Geometry.Point3d point: return(new Rhino.Geometry.Point(point));

                    case Rhino.Geometry.GeometryBase geometry: return(geometry);
                    }

                    return(null);
                });

                if (geometryToBake.Any())
                {
                    var categoryId = options.Category?.Id ?? new DB.ElementId(DB.BuiltInCategory.OST_GenericModel);

                    var worksetId = DB.WorksetId.InvalidWorksetId;
                    if (options.Document.IsWorkshared)
                    {
                        worksetId = options.Workset?.Id ?? options.Document.GetWorksetTable().GetActiveWorksetId();
                    }

                    ids = new List <DB.ElementId>();
                    foreach (var geometry in geometryToBake)
                    {
                        var ds = DB.DirectShape.CreateElement(options.Document, categoryId);
                        ds.Name = param.NickName;
                        if (options.Document.IsWorkshared)
                        {
                            var worksetParam = ds.get_Parameter(DB.BuiltInParameter.ELEM_PARTITION_PARAM);
                            if (worksetParam != null)
                            {
                                worksetParam.SetWorksetId(worksetId);
                            }
                        }

                        var shape = geometry.ToShape().ToList();
                        ds.SetShape(shape);
                        ids.Add(ds.Id);
                    }

                    return(true);
                }

                ids = default;
                return(false);
            }
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        if (blendTree == null)
        {
            return;
        }

        conversionSystem.DeclareAssetDependency(gameObject, blendTree);

        var rig = dstManager.GetComponentData <Rig>(entity);

        var clipConfiguration = new ClipConfiguration
        {
            Mask = ClipConfigurationMask.LoopValues
        };

        var bakeOptions = new BakeOptions
        {
            ClipConfiguration = clipConfiguration,
            RigDefinition     = rig.Value,
            SampleRate        = 60.0f
        };

        var blendTreeIndex       = BlendTreeConversion.Convert(blendTree, entity, dstManager, bakeOptions);
        var blendTree2DResources = dstManager.GetBuffer <BlendTree2DResource>(entity);

        var blendTreeAsset =
            BlendTreeBuilder.CreateBlendTree2DFromComponents(blendTree2DResources[blendTreeIndex], dstManager, entity);

        conversionSystem.BlobAssetStore.AddUniqueBlobAsset(ref blendTreeAsset);

        var blendTree2DData = new BlendTree2DRuntime
        {
            BlendTreeAsset = blendTreeAsset
        };

        dstManager.AddComponentData(entity, blendTree2DData);

        var blendTree2DParam = new BlendTree2DParamRuntime
        {
            InputMapping = float2.zero,
            StepMapping  = paramStep
        };

        dstManager.AddComponentData(entity, blendTree2DParam);

        dstManager.AddComponent <DeltaTimeRuntime>(entity);
        dstManager.AddComponent <ProcessDefaultAnimationGraph.AnimatedRootMotion>(entity);
    }
Exemplo n.º 3
0
    //-------------------------------------------------------------------------------------------------------------------------
    void OnGUI()
    {
        // Display options
        display = (BakeOptions)EditorGUI.EnumPopup(
            new Rect(3, 3, position.width - 6, 15),
            "Bake Option:",
            display);

        GUILayout.Space(20);
        ScriptableObject   target         = this;
        SerializedObject   so             = new SerializedObject(target);
        SerializedProperty scenesProperty = so.FindProperty("scenes");

        EditorGUILayout.PropertyField(scenesProperty, true); // True shows children
        so.ApplyModifiedProperties();                        // Apply modified properties

        if (GUILayout.Button(bakeButton))                    // Button to initiate baking
        {
            StartBake();
        }

        if (GUILayout.Button(buildSettingScenes)) // Button to fetch scenes from Build Settings
        {
            LoadBuildSettingScenes();
        }

        GUILayout.Space(20);
        overrideLightSettings = EditorGUILayout.Toggle("Override Lighting Settings", overrideLightSettings); // Toggle to assign Lighting Preset
        ScriptableObject   preset           = this;
        SerializedObject   scriptableObj    = new SerializedObject(preset);
        SerializedProperty lightingProperty = scriptableObj.FindProperty("lightingPreset");

        EditorGUILayout.PropertyField(lightingProperty); // True means show children
        scriptableObj.ApplyModifiedProperties();         // Remember to apply modified properties

        GUILayout.Space(20);
        EditorGUILayout.LabelField("Debug: ");
        printTiming   = EditorGUILayout.Toggle("Print Timing", printTiming);       //Toggle to activate printing timing
        logPrintTimes = EditorGUILayout.Toggle("Log Debug Values", logPrintTimes); // Toggle to print baking times to console log

        GUILayout.Space(10);
        EditorGUILayout.LabelField("Status:  ", status); // Show baking status
        so.Update();
    }
Exemplo n.º 4
0
    public override void AddGraphSetupComponent(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        var rigDefinition     = dstManager.GetComponentData <Rig>(entity);
        var clipConfiguration = new ClipConfiguration {
            Mask = ClipConfigurationMask.LoopValues
        };
        var bakeOptions = new BakeOptions {
            RigDefinition = rigDefinition.Value, ClipConfiguration = clipConfiguration, SampleRate = 60.0f
        };

        var blendTreeIndex = BlendTreeConversion.Convert(BlendTree, entity, dstManager, bakeOptions);

        var graphSetup = new BlendTree1DSetup
        {
            BlendTreeIndex = blendTreeIndex,
        };

        dstManager.AddComponentData(entity, graphSetup);
    }
            bool IGH_ElementIdBakeAwareObject.Bake(BakeOptions options, out ICollection <DB.ElementId> ids)
            {
                using (var trans = new DB.Transaction(options.Document, "Bake"))
                {
                    if (trans.Start() == DB.TransactionStatus.Started)
                    {
                        bool result = false;

                        if (activeObject is IGH_Param param)
                        {
                            result = Bake(param, options, out ids);
                        }
                        else if (activeObject is IGH_Component component)
                        {
                            var list = new List <DB.ElementId>();
                            foreach (var outParam in component.Params.Output)
                            {
                                if (Bake(outParam, options, out var partial))
                                {
                                    result = true;
                                    list.AddRange(partial);
                                }
                            }

                            ids = result ? list : default;
                        }
                        else
                        {
                            ids = default;
                        }

                        trans.Commit();
                        return(result);
                    }
                }

                ids = default;
                return(false);
            }
    public void Convert(Entity entity, EntityManager dstManager, [NotNull] GameObjectConversionSystem conversionSystem)
    {
        conversionSystem.DeclareAssetDependency(gameObject, blendTree);

        var rigComponent      = dstManager.GetComponentData <Rig>(entity);
        var clipConfiguration = new ClipConfiguration {
            Mask = ClipConfigurationMask.LoopValues
        };
        var bakeOptions = new BakeOptions
        {
            RigDefinition = rigComponent.Value, ClipConfiguration = clipConfiguration, SampleRate = 60.0f
        };

        var blendTreeIndex = BlendTreeConversion.Convert(blendTree, entity, dstManager, bakeOptions);

        var blendTreeComponents = dstManager.GetBuffer <BlendTree1DResource>(entity);
        var blobBlendTreeRef    =
            BlendTreeBuilder.CreateBlendTree1DFromComponents(blendTreeComponents[blendTreeIndex], dstManager, entity);

        conversionSystem.BlobAssetStore.AddUniqueBlobAsset(ref blobBlendTreeRef);

        var blendTreeRuntime = new BlendTree1DRuntime
        {
            BlendTree = blobBlendTreeRef
        };

        dstManager.AddComponentData(entity, blendTreeRuntime);

        var blendTreeParamRuntime = new BlendTree1DParamRuntime
        {
            VelocityStep = velocityStep,
            VelocityX    = 0.0f
        };

        dstManager.AddComponentData(entity, blendTreeParamRuntime);

        dstManager.AddComponent <DeltaTimeRuntime>(entity);
    }
            bool Bake(IGH_Param param, BakeOptions options, out ICollection <DB.ElementId> ids)
            {
                var geometryToBake = param.VolatileData.AllData(true).Select(x => x.ScriptVariable()).
                                     Select(x =>
                {
                    switch (x)
                    {
                    case Rhino.Geometry.Point3d point:          return(new Rhino.Geometry.Point(point));

                    case Rhino.Geometry.GeometryBase geometry:  return(geometry);
                    }

                    return(null);
                });

                if (geometryToBake.Any())
                {
                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    var categoryId  = options.Category?.Id ?? new DB.ElementId(DB.BuiltInCategory.OST_GenericModel);

                    ids = new List <DB.ElementId>();
                    foreach (var geometry in geometryToBake)
                    {
                        var ds = DB.DirectShape.CreateElement(options.Document, categoryId);
                        ds.Name = param.NickName;

                        var shape = geometry.ToHostMultiple(scaleFactor).ToList();
                        ds.SetShape(shape);
                        ids.Add(ds.Id);
                    }

                    return(true);
                }

                ids = default;
                return(false);
            }
Exemplo n.º 8
0
    public void Build(Mesh nativemesh)
    {
        var vertices = new List <Vertex>();

        var positions = nativemesh.vertices;

        var normals  = nativemesh.normals;
        var tangents = nativemesh.tangents;
        var uv       = nativemesh.uv;
        var uv2      = nativemesh.uv2;
        var uv3      = nativemesh.uv3;
        var uv4      = nativemesh.uv4;
        var uv5      = nativemesh.uv5;
        var uv6      = nativemesh.uv6;
        var uv7      = nativemesh.uv7;
        var uv8      = nativemesh.uv8;

        bakeoptions = new BakeOptions();

        bakeoptions.normals  = normals.Length == nativemesh.vertexCount;
        bakeoptions.tangents = tangents.Length == nativemesh.vertexCount;
        bakeoptions.uv       = uv.Length == nativemesh.vertexCount;
        bakeoptions.uv2      = uv2.Length == nativemesh.vertexCount;
        bakeoptions.uv3      = uv3.Length == nativemesh.vertexCount;
        bakeoptions.uv4      = uv4.Length == nativemesh.vertexCount;
        bakeoptions.uv5      = uv5.Length == nativemesh.vertexCount;
        bakeoptions.uv6      = uv6.Length == nativemesh.vertexCount;
        bakeoptions.uv7      = uv7.Length == nativemesh.vertexCount;
        bakeoptions.uv8      = uv8.Length == nativemesh.vertexCount;

        for (int i = 0; i < nativemesh.vertexCount; i++)
        {
            var vertex = new Vertex();

            vertex.position = positions[i];

            if (bakeoptions.normals)
            {
                vertex.normal = normals[i];
            }
            if (bakeoptions.tangents)
            {
                vertex.tangent = tangents[i];
            }
            if (bakeoptions.uv)
            {
                vertex.uv = uv[i];
            }
            if (bakeoptions.uv2)
            {
                vertex.uv2 = uv2[i];
            }
            if (bakeoptions.uv3)
            {
                vertex.uv3 = uv3[i];
            }
            if (bakeoptions.uv4)
            {
                vertex.uv4 = uv4[i];
            }
            if (bakeoptions.uv5)
            {
                vertex.uv5 = uv5[i];
            }
            if (bakeoptions.uv6)
            {
                vertex.uv6 = uv6[i];
            }
            if (bakeoptions.uv7)
            {
                vertex.uv7 = uv7[i];
            }
            if (bakeoptions.uv8)
            {
                vertex.uv8 = uv8[i];
            }

            vertices.Add(vertex);
        }

        var nodes = new int[vertices.Count];

        for (int i = 0; i < nodes.Length; i++)
        {
            nodes[i] = i;
        }

        List <int> indices    = new List <int>();
        List <int> submeshids = new List <int>();

        for (int i = 0; i < nativemesh.subMeshCount; i++)
        {
            var triangles = nativemesh.GetTriangles(i);
            indices.AddRange(triangles);
            submeshids.AddRange(Enumerable.Repeat(i, triangles.Length));
        }

        Build(indices.ToArray(), submeshids.ToArray(), vertices.ToArray(), nodes);
    }
 bool IGH_ElementIdBakeAwareObject.CanBake(BakeOptions options) => activeObject.IsBakeCapable;
 public static IEnumerable <IGH_ElementIdBakeAwareObject> ObjectsToBake(GH_Document definition, BakeOptions options) =>
 ElementIdBakeAwareObject.OfType
 (
     definition.SelectedObjects().
     OfType <IGH_ActiveObject>().
     Where(x => !x.Locked)
 ).
 Where(x => x.CanBake(options));