Beispiel #1
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);
        }
Beispiel #2
0
            /**
             * Create a new placement result.
             *
             * @param timeDelay     time delay for the animated box
             * @param result        placement result
             * @param drawBox       indicates whether an animated box should be drawn around the placement result
             * @param callback      callback method
             */
            public PlacementResult(float timeDelay, SUDLLOP.ObjectPlacementResult result, bool drawBox = true, ResponseDelegate callback = null)
            {
                if (drawBox)
                {
                    this.box = new AnimatedBox(timeDelay, result.Position, Quaternion.LookRotation(result.Forward, result.Up), Random.ColorHSV(0.0f, 1.0f, 1.0f, 1.0f, 0.5f, 1.0f), result.HalfDims);
                }
                if (callback != null)
                {
                    callback(true, new Vector3(result.Position.x, result.Position.y - result.HalfDims.y, result.Position.z));
                }

                this.result = result;
            }