示例#1
0
    private List <PlacementQuery> CreateLocationQueriesForSolver(int desiredLocationCount, Vector3 boxFullDims, ObjectType objType)
    {
        List <PlacementQuery> placementQueries = new List <PlacementQuery>();

        var halfBoxDims = boxFullDims * .5f;

        var disctanceFromOtherObjects = halfBoxDims.x > halfBoxDims.z ? halfBoxDims.x * 3f : halfBoxDims.z * 3f;

        for (int i = 0; i < desiredLocationCount; ++i)
        {
            var placementRules = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule>
            {
                SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule.Create_AwayFromOtherObjects(disctanceFromOtherObjects)
            };

            var placementConstraints = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint>();

            SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloor(halfBoxDims);

            placementQueries.Add(
                new PlacementQuery(placementDefinition,
                                   boxFullDims,
                                   objType,
                                   placementRules,
                                   placementConstraints
                                   ));
        }

        return(placementQueries);
    }
示例#2
0
    //返回存放放置定义,规则,限制的表
    private List <PlacementQuery> CreateLocationQueriesForSolver(int desiredLocationCount, Vector3 boxFullDims, ObjectType objType)
    {
        List <PlacementQuery> placementQueries = new List <PlacementQuery>();

        //Bounds的size是extent的2倍
        var halfBoxDims = boxFullDims * .5f;

        var distanceFromOtherObjects = halfBoxDims.x > halfBoxDims.z ? halfBoxDims.x * 3f : halfBoxDims.z * 3f;

        for (int i = 0; i < desiredLocationCount; ++i)
        {
            var placementRules = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule>
            {
                //放置Rule:要远离其他物体一定距离
                SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule.Create_AwayFromOtherObjects(distanceFromOtherObjects)
            };

            //放置Constraint,即每个形状组件之间的连接关系:无
            var placementConstraints = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint>();

            //放置定义:放置在地面上,即放在XZ面上
            SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloor(halfBoxDims);

            placementQueries.Add(
                new PlacementQuery(placementDefinition,
                                   boxFullDims,
                                   objType,
                                   placementRules,
                                   placementConstraints
                                   ));
        }

        return(placementQueries);
    }
示例#3
0
    private bool TryPlaceObject(
        out SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult placementResult,
        string placementName,
        SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition,
        List <Rule> rules = null)
    {
        placementResult = null;
        List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule>       placementRules       = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule>();
        List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint>();

        if (rules != null)
        {
            foreach (Rule rule in rules)
            {
                rule.AddTo(placementRules);
                rule.AddTo(placementConstraints);
            }
        }
        int result = SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject(
            placementName,
            SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementDefinition),
            placementRules.Count,
            placementRules.Count > 0 ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementRules.ToArray()) : IntPtr.Zero,
            placementConstraints.Count,
            placementConstraints.Count > 0 ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementConstraints.ToArray()) : IntPtr.Zero,
            SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr());

        if (result > 0)
        {
            placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();
            return(true);
        }
        return(false);
    }
示例#4
0
    private PlacementResult PlaceObject(string placementName,
                                        SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition,
                                        Vector3 boxFullDims,
                                        ObjectType objType,
                                        List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules             = null,
                                        List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null)

    {
        //Solver_PlaceObject()返回0代表失败,返回1代表成功
        //故判断是否大于0,成功则获取放置结果
        //PinObject直接返回指定的物体在内存中的位置
        if (SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject(
                placementName,
                SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementDefinition),
                (placementRules != null) ? placementRules.Count : 0,
                ((placementRules != null) && (placementRules.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementRules.ToArray()) : IntPtr.Zero,
                (placementConstraints != null) ? placementConstraints.Count : 0,
                (placementConstraints != null) && (placementConstraints.Count > 0)?SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementConstraints.ToArray()):IntPtr.Zero,
                SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr())
            > 0)
        {
            SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();

            return(new PlacementResult(placementResult.Clone() as SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult, boxFullDims, objType));
        }
        return(null);
    }
示例#5
0
 public PlacementQuery(SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition, Vector3 dimensions, ObjectType objType, List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules = null, List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null)
 {
     PlacementDefinition  = placementDefinition;
     PlacementRules       = placementRules;
     PlacementConstraints = placementConstraints;
     Dimensions           = dimensions;
     ObjType = objType;
 }
示例#6
0
 public PlacementQuery(
     SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition,
     List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules             = null,
     List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null)
 {
     PlacementDefinition  = placementDefinition;
     PlacementRules       = placementRules;
     PlacementConstraints = placementConstraints;
 }
示例#7
0
    private bool PlaceObject(
        string placementName,
        GameObject input,
        SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition,
        List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules             = null,
        List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null,
        bool clearObjectsFirst = true,
        bool isASync           = false)
    {
        isASync = false;
        // Clear objects (if requested)
        if (!isASync && clearObjectsFirst)
        {
        }
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return(false);
        }

        // New query
        if (SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject(
                placementName,
                SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementDefinition),
                (placementRules != null) ? placementRules.Count : 0,
                ((placementRules != null) && (placementRules.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementRules.ToArray()) : IntPtr.Zero,
                (placementConstraints != null) ? placementConstraints.Count : 0,
                ((placementConstraints != null) && (placementConstraints.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementConstraints.ToArray()) : IntPtr.Zero,
                SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr()) > 0)
        {
            SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();
            if (!isASync)
            {
                // Add to instantiation list here

                // If not running async, we can just add the results to the draw list right now
                AppState.Instance.ObjectPlacementDescription = placementName + " (1)";

                placementResults.Add(new PlacementResult(input, 1.0f, placementResult.Clone() as SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult));
                Quaternion thisRotation = Quaternion.LookRotation(placementResult.Forward, placementResult.Up);
                //print("Space Found");
                objectsToMake.Add(new ObjectToInstantiate(input, placementResult.Position, thisRotation));
                //print(objectsToMake.Count);
            }
            else
            {
                queryStatus.QueryResult.Add(placementResult.Clone() as SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult);
            }
            return(true);
        }
        if (!isASync)
        {
            print("No Spaces Found!");
            AppState.Instance.ObjectPlacementDescription = "Placement Failed";
        }
        return(false);
    }
示例#8
0
    public bool TryPlaceOnFloor(out Vector3 position, Vector3 size, List <Rule> rules = null)
    {
        position = Vector3.zero;
        string token = "Floor-" + m_uniquePlacementID++;

        SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloor(0.5f * size);
        SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult     placementResult;
        if (TryPlaceObject(out placementResult, token, placementDefinition, rules))
        {
            position = placementResult.Position;
            return(true);
        }
        return(false);
    }
示例#9
0
    public bool TryPlaceOnPlatformEdge(out Vector3 position, Vector3 size, List <Rule> rules = null)
    {
        position = Vector3.zero;
        string token = "Edge-" + m_uniquePlacementID++;

        //TODO: unsure of what halfDimsBottom really means
        SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnEdge(0.5f * size, 0.5f * new Vector3(size.x, size.y, size.z));
        SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult     placementResult;
        if (TryPlaceObject(out placementResult, token, placementDefinition, rules))
        {
            position = placementResult.Position;
            return(true);
        }
        return(false);
    }
示例#10
0
 private bool PlaceObjectAsync(
     string placementName,
     SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition,
     List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules             = null,
     List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null,
     bool clearObjectsFirst = true)
 {
     return(PlaceObjectAsync(
                placementName,
                new List <PlacementQuery>()
     {
         new PlacementQuery(placementDefinition, placementRules, placementConstraints)
     },
                clearObjectsFirst));
 }
示例#11
0
        private bool PlaceObject(
            string placementName,
            SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition,
            List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules             = null,
            List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null,
            bool clearObjectsFirst = true,
            bool isASync           = false)
        {
            // Clear objects (if requested)
            if (!isASync && clearObjectsFirst)
            {
                ClearGeometry();
            }
            if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
            {
                return(false);
            }

            // New query
            if (SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject(
                    placementName,
                    SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementDefinition),
                    (placementRules != null) ? placementRules.Count : 0,
                    ((placementRules != null) && (placementRules.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementRules.ToArray()) : IntPtr.Zero,
                    (placementConstraints != null) ? placementConstraints.Count : 0,
                    ((placementConstraints != null) && (placementConstraints.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementConstraints.ToArray()) : IntPtr.Zero,
                    SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr()) > 0)
            {
                SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();
                if (!isASync)
                {
                    // If not running async, we can just add the results to the draw list right now
                    AppState.Instance.ObjectPlacementDescription = placementName + " (1)";
                    float timeDelay = (float)placementResults.Count * AnimatedBox.DelayPerItem;
                    placementResults.Add(new PlacementResult(timeDelay, placementResult.Clone() as SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult));
                }
                else
                {
                    queryStatus.QueryResult.Add(placementResult.Clone() as SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult);
                }
                return(true);
            }
            if (!isASync)
            {
                AppState.Instance.ObjectPlacementDescription = placementName + " (0)";
            }
            return(false);
        }
示例#12
0
 private bool _PlaceGameObject(string name, SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition, List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules = null, List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null)
 {
     return
         (
         SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject
         (
             name,
             SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementDefinition),
             (placementRules != null) ? placementRules.Count : 0,
             ((placementRules != null) && (placementRules.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementRules.ToArray()) : System.IntPtr.Zero,
             (placementConstraints != null) ? placementConstraints.Count : 0,
             ((placementConstraints != null) && (placementConstraints.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementConstraints.ToArray()) : System.IntPtr.Zero,
             SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr()
         ) > 0
         );
 }
示例#13
0
    public bool TryPlaceInAir(out Vector3 position, out Quaternion rotation, Vector3 size, List <Rule> rules = null)
    {
        size     = ClampToMinSize(size);
        position = Vector3.zero;
        rotation = Quaternion.identity;
        string token = "InAir-" + m_uniquePlacementID++;

        SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_InMidAir(0.5f * size);
        SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult     placementResult;
        if (TryPlaceObject(out placementResult, token, placementDefinition, rules))
        {
            position = placementResult.Position;
            return(true);
        }
        return(false);
    }
示例#14
0
 public bool TryPlaceOnFloor(out string placementName, out Vector3 position, out Quaternion rotation, Vector3 size, List <Rule> rules = null)
 {
     size          = ClampToMinSize(size);
     position      = Vector3.zero;
     rotation      = Quaternion.identity;
     placementName = "Floor-" + m_uniquePlacementID++;
     SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloor(0.5f * size);
     SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult     placementResult;
     if (TryPlaceObject(out placementResult, placementName, placementDefinition, rules))
     {
         position = placementResult.Position;
         rotation = Quaternion.LookRotation(placementResult.Forward, placementResult.Up);
         return(true);
     }
     return(false);
 }
示例#15
0
    bool AsyncRunQuery(SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition,
                       List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules             = null,
                       List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null)
    {
#if UNITY_WSA && !UNITY_EDITOR
        System.Threading.Tasks.Task.Run(() =>
        {
            RunQuery(placementDefinition, placementRules, placementConstraints);
        }
                                        );

        return(true);
#else
        return(RunQuery(placementDefinition, placementRules, placementConstraints));
#endif
    }
示例#16
0
    void CreateScene()
    {
        // DLLの初期化
        SpatialUnderstandingDllObjectPlacement.Solver_Init();

        var halfBoxDims = boxFullDims * .5f;
        // 他のオブジェクトから離す距離
        var disctanceFromOtherObjects = halfBoxDims.x > halfBoxDims.z ? halfBoxDims.x * 3f : halfBoxDims.z * 3f;
        // 作成したいオブジェクトの数
        var desiredLocationCount = 3;

        for (int i = 0; i < desiredLocationCount; ++i)
        {
            // ルールの作成(複数追加可能)
            var placementRules = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule>();
            placementRules.Add(SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule.Create_AwayFromOtherObjects(disctanceFromOtherObjects));

            // 制約の作成(複数追加可能)
            var placementConstraints = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint>();
            placementConstraints.Add(SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint.Create_AwayFromOtherObjects());

            // 定義の作成(1つだけ)
            SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloor(halfBoxDims);

            int ret = SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject(
                "my placement",
                SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementDefinition),
                placementRules.Count,
                SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementRules.ToArray()),
                placementConstraints.Count,
                SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementConstraints.ToArray()),
                SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr()
                );

            if (ret > 0)
            {
                SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();

                var rotation = Quaternion.LookRotation(placementResult.Forward, Vector3.up);
                var obj      = Instantiate(toPlaceObj, placementResult.Position, rotation);

                print("Placed:" + obj.transform.position);
            }
        }
    }
示例#17
0
        IEnumerator PlaceGameObjectCoro(GameObject g, SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition, List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules = null, List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null)
        {
            string name       = g.name;
            bool   hasResults = false;
            var    thread     =
#if UNITY_EDITOR || !UNITY_WSA
                new System.Threading.Thread
#else
                System.Threading.Tasks.Task.Run
#endif
                    (() =>
            {
                hasResults = _PlaceGameObject(name, placementDefinition, placementRules, placementConstraints);
            });

#if UNITY_EDITOR || !UNITY_WSA
            thread.Start()
#endif
            ;

            while
            (
#if UNITY_EDITOR || !UNITY_WSA
                !thread.Join(System.TimeSpan.Zero)
#else
                !thread.IsCompleted
#endif
            )
            {
                yield return(null);
            }

            if (hasResults)
            {
                SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();
                g.transform.position = placementResult.Position;
            }
            else
            {
                Debug.Log("No placements found");
            }
        }
示例#18
0
    public void FindPlaces()
    {
        if (!InitializeSolver())
        {
            return;
        }

        Reset();

        Bounds  bounds   = GetBoundsForObject(prefab);
        Vector3 halfDims = new Vector3(bounds.size.x * 0.5f, bounds.size.y * 0.5f, bounds.size.z * 0.5f);

        SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition  placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloor(halfDims);
        List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules      = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule>()
        {
            SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule.Create_AwayFromPosition(Camera.main.transform.position, distanceFromUser),
        };

        AsyncRunQuery(placementDefinition, placementRules);
    }
示例#19
0
 private PlacementResult PlaceObject(string placementName,
                                     SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition,
                                     Vector3 boxFullDims,
                                     ObjectType objType,
                                     List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules             = null,
                                     List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null)
 {
     // New query
     if (SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject(
             placementName,
             SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementDefinition),
             (placementRules != null) ? placementRules.Count : 0,
             ((placementRules != null) && (placementRules.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementRules.ToArray()) : IntPtr.Zero,
             (placementConstraints != null) ? placementConstraints.Count : 0,
             ((placementConstraints != null) && (placementConstraints.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementConstraints.ToArray()) : IntPtr.Zero,
             SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr()) > 0)
     {
         SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();
         Debug.Log("TO BE Placed:---------" + (objType == ObjectType.Menu ? "turtorial":"object"));
         return(new PlacementResult(placementResult.Clone() as SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult, boxFullDims, objType));
     }
     Debug.Log("Not Placed:-----------" + (objType == ObjectType.Menu ? "turtorial":"object"));
     return(null);
 }
示例#20
0
    bool RunQuery(SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition,
                  List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules             = null,
                  List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null)
    {
        if (SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject(
                this.name,
                SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementDefinition),
                (placementRules != null) ? placementRules.Count : 0,
                ((placementRules != null) && (placementRules.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementRules.ToArray()) : IntPtr.Zero,
                (placementConstraints != null) ? placementConstraints.Count : 0,
                ((placementConstraints != null) && (placementConstraints.Count > 0)) ? SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementConstraints.ToArray()) : IntPtr.Zero,
                SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr()) > 0)
        {
            SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();

            queryPlacementResults.Add(placementResult.Clone() as SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult);

            return(true);
        }

        State = States.Finished;

        return(true);
    }
示例#21
0
    private List <PlacementQuery> CreateLocationQueriesForSolver(int desiredLocationCount, Vector3 boxFullDims, ObjectType objType)
    {
        List <PlacementQuery> placementQueries = new List <PlacementQuery>();

        var halfBoxDims = boxFullDims * 0.5f;

        var disctanceFromOtherObjects = halfBoxDims.x > halfBoxDims.z ? halfBoxDims.x * 2.2f : halfBoxDims.z * 2.2f;

        for (int i = 0; i < desiredLocationCount; ++i)
        {
            var placementRules = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> {
                SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule.Create_AwayFromOtherObjects(disctanceFromOtherObjects)
            };

            var placementConstraints = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint>();

            if (objType == ObjectType.Bottle)
            {
                int randomPlace = UnityEngine.Random.Range(1, 3);
                if (randomPlace == 1)
                {
                    SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloor(halfBoxDims);

                    placementQueries.Add(
                        new PlacementQuery(placementDefinition,
                                           boxFullDims,
                                           objType,
                                           placementRules,
                                           placementConstraints
                                           ));
                }
                else if (randomPlace == 2)
                {
                    SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnShape(halfBoxDims, "Couch", 1);

                    placementQueries.Add(
                        new PlacementQuery(placementDefinition,
                                           boxFullDims,
                                           objType,
                                           placementRules,
                                           placementConstraints
                                           ));
                }
                else
                {
                    SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnShape(halfBoxDims, "All Surfaces", 1);

                    placementQueries.Add(
                        new PlacementQuery(placementDefinition,
                                           boxFullDims,
                                           objType,
                                           placementRules,
                                           placementConstraints
                                           ));
                }
            }
            else if (objType == ObjectType.Table)
            {
                SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloor(halfBoxDims);

                placementQueries.Add(
                    new PlacementQuery(placementDefinition,
                                       boxFullDims,
                                       objType,
                                       placementRules,
                                       placementConstraints
                                       ));
            }
            else if (objType == ObjectType.House)
            {
                // SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule.Create_AwayFromWalls(0.1f, 2.0f);

                SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnWall(halfBoxDims, -0.2f, 1.5f);

                placementQueries.Add(
                    new PlacementQuery(placementDefinition,
                                       boxFullDims,
                                       objType,
                                       placementRules,
                                       placementConstraints
                                       ));
            }
            else if (objType == ObjectType.Shield)
            {
                SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnWall(halfBoxDims, 1.7f, 2.0f);

                placementQueries.Add(
                    new PlacementQuery(placementDefinition,
                                       boxFullDims,
                                       objType,
                                       placementRules,
                                       placementConstraints
                                       ));
            }
        }

        return(placementQueries);
    }
示例#22
0
    /*
     * création des contraintes pour les objets
     */
    private List <PlacementQuery> CreateLocationQueriesForSolver(int desiredLocationCount, Vector3 boxFullDims, ObjectType objType)
    {
        List <PlacementQuery> placementQueries = new List <PlacementQuery>();

        var halfBoxDims = boxFullDims * .5f;


        for (int i = 0; i < desiredLocationCount; ++i)
        {
            var placementConstraints = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint>();
            SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnWall(halfBoxDims, Camera.main.transform.position.y - 2 * halfBoxDims.y, Camera.main.transform.position.y + 2 * halfBoxDims.y);//Create_OnFloor(halfBoxDims);

            /**
             * Les regles de placement d'objet. La regle definit que l'objet doit être éloigné d'un autre objet ou point ou autre...
             * Variable à exploiter.
             **/
            var placementRules = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule>
            {
                SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule.Create_AwayFromOtherObjects(distanceFromOtherObject),
                SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule.Create_AwayFromPosition(Camera.main.transform.position, distanceFromOtherObject)
            };

            switch (objType)
            {
            case ObjectType.FloorObject:
                /**
                 * Les contraintes de placement des objets. On peut placer un objet près d'un centre ou près d'un point à particulier.
                 * Cette variable est aussi à exploiter par rapport ce qu'on veux voir
                 **/
                // var placementConstraints = new List<SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint>(); //->par défaut
                placementConstraints = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> {
                    SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint.Create_NearPoint(Camera.main.transform.position - 2 * Camera.main.transform.forward),
                    //SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint.Create_AwayFromPoint(2*Camera.main.transform.position)
                };

                /**
                 * Ici nous définissons où veut on placer les objets.
                 * Nous utilisons pour le moment que deux création d'objet : Create_OnFloor et Create_OnWall.
                 * On peut exploirer plus cette variable pour mieux définir la position des objets.
                 **/
                placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloor(halfBoxDims);

                break;

            case ObjectType.WallObject:
                /**
                 * Les contraintes de placement des objets. On peut placer un objet près d'un centre ou près d'un point à particulier.
                 * Cette variable est aussi à exploiter par rapport ce qu'on veux voir
                 **/
                // var placementConstraints = new List<SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint>(); //->par défaut
                placementConstraints = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> {
                    SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint.Create_NearCenter(),
                        SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint.Create_AwayFromPoint(Camera.main.transform.position)
                };

                /**
                 * Ici nous définissons où veut on placer les objets.
                 * Nous utilisons pour le moment que deux création d'objet : Create_OnFloor et Create_OnWall.
                 * On peut exploirer plus cette variable pour mieux définir la position des objets.
                 **/
                placementDefinition = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnWall(halfBoxDims, 1.6f, 1.8f);    //Create_OnFloor(halfBoxDims);

                break;
            }



            placementQueries.Add(
                new PlacementQuery(placementDefinition,
                                   boxFullDims,
                                   objType,
                                   placementRules,
                                   placementConstraints
                                   ));
        }

        return(placementQueries);
    }
示例#23
0
        /// <summary>
        /// Attempts to place an object given the parameters.
        /// Returns false if object could not be placed, or spatial mapping could not be initialized.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="position"></param>
        /// <param name="customHalfDims"></param>
        /// <param name="minDistFromOthers"></param>
        /// <param name="minDistFromPlayer"></param>
        /// <param name="maxDistFromPlayer"></param>
        /// <returns></returns>
        public static bool PlaceObject(GameObject target, WrappedPlacement position, Vector3?customHalfDims = null, float minDistFromOthers = 3f, float minDistFromPlayer = .25f, float maxDistFromPlayer = 4.0f)
        {
            if (!Init())
            {
                return(false);
            }

            Vector3  halfDims = Vector3.one * .5f;
            Renderer r        = target.GetComponentInChildren <Renderer>();

            if (r != null)
            {
                halfDims = (r.bounds.size * .5f);
                WorldErrors.Print("halfDims: " + (r.bounds.size * .5f).ToString());
            }

            if (customHalfDims != null)
            {
                halfDims = customHalfDims.Value;
            }

            List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule>()
            {
                SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule.Create_AwayFromOtherObjects(halfDims.magnitude * minDistFromOthers)
            };

            List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint>()
            {
                SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint.Create_NearPoint(Camera.main.transform.position, minDistFromPlayer, maxDistFromPlayer)
            };

            SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition def = new SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition();

            switch (position)
            {
            case WrappedPlacement.Place_InMidAir:
                def = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_InMidAir(halfDims);
                break;

            case WrappedPlacement.Place_OnCeiling:
                def = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnCeiling(halfDims);
                break;

            case WrappedPlacement.Place_OnEdge: {
                Vector3 halfDimsBot = halfDims;
                halfDimsBot.y *= .5f;
                def            = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnEdge(halfDims, halfDimsBot);
            }
            break;

            case WrappedPlacement.Place_OnFloor:
                def = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloor(halfDims);
                break;

            case WrappedPlacement.Place_OnFloorAndCeiling: {
                Vector3 halfDimsBot = halfDims;
                halfDimsBot.y *= .5f;
                def            = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloorAndCeiling(halfDims, halfDimsBot);
            }
            break;

            case WrappedPlacement.Place_OnShape:
                Debug.LogWarning("Not supported");
                def = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnShape(halfDims, "DefaultShape", 0);
                break;

            case WrappedPlacement.Place_OnWall:
                def = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnWall(halfDims, halfDims.y, 2.4f);
                break;

            case WrappedPlacement.Place_RandomInAir:
                def = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_RandomInAir(halfDims);
                break;

            case WrappedPlacement.Place_UnderPlatformEdge:
                def = SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_UnderPlatformEdge(halfDims);
                break;
            }

            //SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult result = new SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult();
            if (SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject(target.name,
                                                                          SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(def),
                                                                          placementRules.Count, SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementRules.ToArray()),             //rules
                                                                          placementConstraints.Count, SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placementConstraints.ToArray()), //constraints
                                                                          SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr()
                                                                          ) > 0)
            {
                target.transform.position = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult().Position;
                return(true);
            }

            return(false);
        }
示例#24
0
文件: UI.cs 项目: dag10/HoloDrink
    private IEnumerator SetupMenu()
    {
        // Setup for queries
        SpatialUnderstandingDllTopology.TopologyResult[] resultsTopology = new SpatialUnderstandingDllTopology.TopologyResult[1];
        IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology);

#if UNITY_WSA && !UNITY_EDITOR
        // Place on a wall (do it in a thread, as it can take a little while)
        SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placeOnWallDef =
            SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnWall(new Vector3(MenuWidth * 0.5f, MenuHeight * 0.5f, MenuMinDepth * 0.5f), 0.5f, 3.0f);
        SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();
        System.Threading.Tasks.Task thread = System.Threading.Tasks.Task.Run(() =>
        {
            if (SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject(
                    "UIPlacement",
                    SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placeOnWallDef),
                    0,
                    IntPtr.Zero,
                    0,
                    IntPtr.Zero,
                    SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr()) == 0)
            {
                placementResult = null;
            }
        });
        while (!thread.IsCompleted)
        {
            yield return(null);
        }
        if (placementResult != null)
        {
            Debug.Log("PlaceMenu - ObjectSolver-OnWall");
            Vector3 posOnWall = placementResult.Position - placementResult.Forward * MenuMinDepth * 0.5f;
            PlaceMenu(posOnWall, -placementResult.Forward);
            yield break;
        }
#endif

        // Wait a frame
        yield return(null);

        // Fallback, place floor (add a facing, if so)
        int locationCount = SpatialUnderstandingDllTopology.QueryTopology_FindLargestPositionsOnFloor(
            resultsTopology.Length, resultsTopologyPtr);
        if (locationCount > 0)
        {
            Debug.Log("PlaceMenu - LargestPositionsOnFloor");
            SpatialUnderstandingDllTopology.TopologyResult menuLocation = resultsTopology[0];
            Vector3 menuPosition   = menuLocation.position + Vector3.up * MenuHeight;
            Vector3 menuLookVector = Camera.main.transform.position - menuPosition;
            PlaceMenu(menuPosition, (new Vector3(menuLookVector.x, 0.0f, menuLookVector.z)).normalized, true);
            yield break;
        }

        // Final fallback just in front of the user
        SpatialUnderstandingDll.Imports.QueryPlayspaceAlignment(SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticPlayspaceAlignmentPtr());
        SpatialUnderstandingDll.Imports.PlayspaceAlignment alignment = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticPlayspaceAlignment();
        Vector3 defaultPosition = Camera.main.transform.position + Camera.main.transform.forward * 2.0f;
        PlaceMenu(new Vector3(defaultPosition.x, Math.Max(defaultPosition.y, alignment.FloorYValue + 1.5f), defaultPosition.z), (new Vector3(Camera.main.transform.forward.x, 0.0f, Camera.main.transform.forward.z)).normalized, true);
        Debug.Log("PlaceMenu - InFrontOfUser");
    }
示例#25
0
 public void PlaceGameObject(GameObject g, SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placementDefinition, List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule> placementRules = null, List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> placementConstraints = null)
 {
     StartCoroutine(PlaceGameObjectCoro(g, placementDefinition, placementRules, placementConstraints));
 }