Пример #1
0
 /**
  * Create a new placement query.
  *
  * @param placementDefinition   placement definition
  * @param placementRules        placement rules
  * @param placementConstraints  placement constraints
  */
 public PlacementQuery(SUDLLOP.ObjectPlacementDefinition placementDefinition, List <SUDLLOP.ObjectPlacementRule> placementRules = null,
                       List <SUDLLOP.ObjectPlacementConstraint> placementConstraints = null)
 {
     this.placementDefinition  = placementDefinition;
     this.placementRules       = placementRules;
     this.placementConstraints = placementConstraints;
 }
Пример #2
0
        /**
         * Process the given placement query.
         *
         * @param placementName         placement description
         * @param placementDefinition   placement definition
         * @param placementRules        list of placement rules
         * @param placementConstraints  list of placement constraints
         * @param clearObjectsFirst     should already detected placement results should be removed
         * @param isASync               indicates whether this query is handled asynchronously
         * @param drawBox               indicates whether an animated box should be drawn around the placement result
         * @param callback              callback method
         */
        private bool PlaceObject(string placementName, SUDLLOP.ObjectPlacementDefinition placementDefinition, List <SUDLLOP.ObjectPlacementRule> placementRules = null,
                                 List <SUDLLOP.ObjectPlacementConstraint> placementConstraints = null, bool clearObjectsFirst = false, bool isASync = true, bool drawBox = true, ResponseDelegate callback = null)
        {
            // Clear objects (if requested)
            if (!isASync && clearObjectsFirst)
            {
                this.ClearGeometry();
            }

            if (!SpatialUnderstanding.IsInitialized || !SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
            {
                return(false);
            }

            // Query parameters
            int placementRuleCount = (placementRules != null) ? placementRules.Count : 0;

            System.IntPtr placementRulesPtr = ((placementRules != null) && (placementRules.Count > 0))
                ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementRules.ToArray()) : System.IntPtr.Zero;
            int constraintCount = (placementConstraints != null) ? placementConstraints.Count : 0;

            System.IntPtr placementConstraintsPtr = ((placementConstraints != null) && (placementConstraints.Count > 0))
                ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementConstraints.ToArray()) : System.IntPtr.Zero;
            System.IntPtr placementResultPtr = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr();

            // New query
            int success = SUDLLOP.Solver_PlaceObject(placementName, SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementDefinition), placementRuleCount,
                                                     placementRulesPtr, constraintCount, placementConstraintsPtr, placementResultPtr);

            if (success > 0)
            {
                SUDLLOP.ObjectPlacementResult placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();
                if (!isASync)
                {
                    // If not running async, we can just add the results to the draw list right now
                    Debug.Log(placementName + " (1)");
                    float timeDelay = this.placementResults.Count * AnimatedBox.DelayPerItem;
                    this.placementResults.Add(new PlacementResult(timeDelay, placementResult.Clone() as SUDLLOP.ObjectPlacementResult, drawBox, callback));
                }
                else
                {
                    this.queryStatus.queryResult.Add(placementResult.Clone() as SUDLLOP.ObjectPlacementResult);
                }
                return(true);
            }

            if (!isASync)
            {
                Debug.Log(placementName + " (0)");
            }

            return(false);
        }
Пример #3
0
        /**
         * Query the SpatialUnderstanding DLL for a specific placement.
         *
         * @param pos       position near which the object should be placed
         * @param drawBox   indicates whether an animated box should be drawn around the placement result
         * @param callback  callback method
         */
        public void Query_OnFloor_NearPoint(Vector3 pos, bool drawBox = true, ResponseDelegate callback = null)
        {
            List <PlacementQuery> placementQueries = new List <PlacementQuery>();

            for (int i = 0; i < 4; ++i)
            {
                float halfDimSize = 0.25f;
                SUDLLOP.ObjectPlacementDefinition  placementDefinition = SUDLLOP.ObjectPlacementDefinition.Create_OnFloor(new Vector3(halfDimSize, halfDimSize * 3.6f, halfDimSize));
                List <SUDLLOP.ObjectPlacementRule> rules = new List <SUDLLOP.ObjectPlacementRule> {
                    SUDLLOP.ObjectPlacementRule.Create_AwayFromOtherObjects(halfDimSize * 3.0f),
                    //SUDLLOP.ObjectPlacementRule.Create_AwayFromPosition(CameraCache.Main.transform.position, 1.0f)
                };
                List <SUDLLOP.ObjectPlacementConstraint> constraints = new List <SUDLLOP.ObjectPlacementConstraint> {
                    SUDLLOP.ObjectPlacementConstraint.Create_NearPoint(pos, 0.5f, 2.0f)
                };
                placementQueries.Add(new PlacementQuery(placementDefinition, rules, constraints));
            }
            this.PlaceObjectAsync("OnFloor - NearPoint/AwayFromMe", placementQueries, false, drawBox, callback);
        }