static void Start()
        {
            objectPreviews = new Dictionary <Guid, DocumentPreviewServer>();

            using (var service = DBES.ExternalServiceRegistry.GetService(DBES.ExternalServices.BuiltInExternalServices.DirectContext3DService) as DBES.MultiServerService)
            {
                var activeServerIds = service.GetActiveServerIds();
                foreach (var o in ActiveDocument.Objects)
                {
                    if (!ObjectPrimitive.IsSupportedObject(o, true))
                    {
                        continue;
                    }

                    var preview  = new DocumentPreviewServer(o);
                    var serverId = preview.GetServerId();
                    objectPreviews.Add(serverId, preview);
                    service.AddServer(preview);
                    activeServerIds.Add(serverId);
                }
                service.SetActiveServers(activeServerIds);
            }

            Revit.RefreshActiveView();
        }
 static void RhinoDoc_DeleteRhinoObject(object sender, RhinoObjectEventArgs e)
 {
     if (e.TheObject.Document == ActiveDocument && ObjectPrimitive.IsSupportedObject(e.TheObject, false))
     {
         Revit.EnqueueReadAction((doc, canceled) => objectPreviews[e.TheObject.Id]?.Unregister());
         Revit.RefreshActiveView();
     }
 }
 static void RhinoDoc_AddRhinoObject(object sender, RhinoObjectEventArgs e)
 {
     if (e.TheObject.Document == ActiveDocument && ObjectPrimitive.IsSupportedObject(e.TheObject, true))
     {
         Revit.EnqueueReadAction((doc, canceled) => new DocumentPreviewServer(e.TheObject).Register());
         Revit.RefreshActiveView();
     }
 }
        void AddPointCloudPreviews(PointCloud previewCloud)
        {
            int verticesCount = previewCloud.Count;

            if (verticesCount > VertexThreshold)
            {
                primitives = new Primitive[(verticesCount / VertexThreshold) + ((verticesCount % VertexThreshold) > 0 ? 1 : 0)];
                for (int c = 0; c < verticesCount / VertexThreshold; ++c)
                {
                    var part = new Primitive.Part(c * VertexThreshold, (c + 1) * VertexThreshold);
                    primitives[c] = new ObjectPrimitive(rhinoObject, previewCloud, part);
                }

                if ((verticesCount % VertexThreshold) > 0)
                {
                    var part = new Primitive.Part((primitives.Length - 1) * VertexThreshold, verticesCount);
                    primitives[primitives.Length - 1] = new ObjectPrimitive(rhinoObject, previewCloud, part);
                }
            }
            else
            {
                primitives = new Primitive[] { new ObjectPrimitive(rhinoObject, previewCloud) }
            };
        }

        void AddMeshPreviews(Mesh previewMesh)
        {
            int verticesCount = previewMesh.Vertices.Count;

            if (verticesCount > VertexThreshold || previewMesh.Faces.Count > VertexThreshold)
            {
                // If it's insane big show as point clouds
                if (previewMesh.Faces.Count > (VertexThreshold - 1) * 16)
                {
                    primitives = new Primitive[(verticesCount / VertexThreshold) + ((verticesCount % VertexThreshold) > 0 ? 1 : 0)];
                    for (int c = 0; c < verticesCount / VertexThreshold; ++c)
                    {
                        var part = new Primitive.Part(c * VertexThreshold, (c + 1) * VertexThreshold);
                        primitives[c] = new ObjectPrimitive(rhinoObject, previewMesh, part);
                    }

                    if ((verticesCount % VertexThreshold) > 0)
                    {
                        var part = new Primitive.Part((primitives.Length - 1) * VertexThreshold, verticesCount);
                        primitives[primitives.Length - 1] = new ObjectPrimitive(rhinoObject, previewMesh, part);
                    }

                    // Mesh.Reduce is slow in this case
                    //previewMesh = previewMesh.DuplicateMesh();
                    //previewMesh.Reduce((BigMeshThreshold - 1) * 16, true, 5, true);
                }

                // Split the mesh into partitions
                else if (previewMesh.CreatePartitions(VertexThreshold, int.MaxValue))
                {
                    int partitionCount = previewMesh.PartitionCount;
                    primitives = new Primitive[partitionCount];
                    for (int p = 0; p < partitionCount; ++p)
                    {
                        primitives[p] = new ObjectPrimitive(rhinoObject, previewMesh, previewMesh.GetPartition(p));
                    }
                }
            }
            else
            {
                primitives = new Primitive[] { new ObjectPrimitive(rhinoObject, previewMesh) }
            };
        }
Example #5
0
        private void ColorHolder()
        {
            //default setting for objects
            ClearPHAM();


            currentObject = ObjectPrimitive.Cylinder;

            // bool startHorizontal = false;
            // currentObject = ObjectPrimitive.Cylinder;



            int taskType = Random.Range(1, 5);

            switch (taskType)
            {
            case 1:
                initialTransform = GameObject.Find("VerticalHolder_TopLeft").transform.Find("TargetCylinder").transform;
                primitives["Cylinder"].transform.position = initialTransform.position;
                primitives["Cylinder"].transform.rotation = initialTransform.rotation;

                primitives["Cylinder"].SetActive(true);
                primitives["Cylinder"].GetComponent <DroppedObjectLogic>().SetDroppedStatus(false);
                GameObject.Find("HorizontalHolder_BotRight").GetComponent <Renderer>().material.color = Color.red;
                targetTransform = GameObject.Find("HorizontalHolder_BotRight").transform.Find("TargetCylinder").transform;
                GameObject.Find("HorizontalHolder_BotRight").GetComponent <Holder>().activate();
                break;

            case 2:
                initialTransform = GameObject.Find("HorizontalHolder_TopLeft").transform.Find("TargetCylinder").transform;
                primitives["Cylinder"].transform.position = initialTransform.position;
                primitives["Cylinder"].transform.rotation = initialTransform.rotation;

                primitives["Cylinder"].SetActive(true);
                primitives["Cylinder"].GetComponent <DroppedObjectLogic>().SetDroppedStatus(false);
                GameObject.Find("VerticalHolder_BotRight").GetComponent <Renderer>().material.color = Color.red;
                targetTransform = GameObject.Find("VerticalHolder_BotRight").transform.Find("TargetCylinder").transform;
                GameObject.Find("VerticalHolder_BotRight").GetComponent <Holder>().activate();
                break;

            case 3:
                initialTransform = GameObject.Find("HorizontalHolder_BotLeft").transform.Find("TargetCylinder").transform;
                primitives["Cylinder"].transform.position = initialTransform.position;
                primitives["Cylinder"].transform.rotation = initialTransform.rotation;

                primitives["Cylinder"].SetActive(true);
                primitives["Cylinder"].GetComponent <DroppedObjectLogic>().SetDroppedStatus(false);
                GameObject.Find("VerticalHolder_TopRight").GetComponent <Renderer>().material.color = Color.red;
                targetTransform = GameObject.Find("VerticalHolder_TopRight").transform.Find("TargetCylinder").transform;
                GameObject.Find("VerticalHolder_TopRight").GetComponent <Holder>().activate();
                break;

            case 4:
                initialTransform = GameObject.Find("HorizontalHolder_TopoRight").transform.Find("TargetCylinder").transform;
                primitives["Cylinder"].transform.position = initialTransform.position;
                primitives["Cylinder"].transform.rotation = initialTransform.rotation;

                primitives["Cylinder"].SetActive(true);
                primitives["Cylinder"].GetComponent <DroppedObjectLogic>().SetDroppedStatus(false);
                GameObject.Find("VerticalHolder_BotLeft").GetComponent <Renderer>().material.color = Color.red;
                targetTransform = GameObject.Find("VerticalHolder_BotLeft").transform.Find("TargetCylinder").transform;
                GameObject.Find("VerticalHolder_BotLeft").GetComponent <Holder>().activate();
                break;
            }
        }