Пример #1
0
    public void CreateScene()
    {
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return;
        }

        if (!solverInit)
        {
            SpatialUnderstandingDllObjectPlacement.Solver_Init();
            solverInit = true;
        }

        List <PlacementQuery> queries = new List <PlacementQuery>();

        queries.AddRange(AddTree());
        Vector3 cameraPos = Camera.main.transform.position;
        Vector3 angles    = Camera.main.transform.eulerAngles;
        Vector3 pos       = new Vector3(cameraPos.x + Mathf.Sin((angles.y) * Mathf.Deg2Rad) * 1.5f,
                                        cameraPos.y,
                                        cameraPos.z + Mathf.Cos((angles.y) * Mathf.Deg2Rad) * 1.5f);
        Quaternion rot = Quaternion.LookRotation(Camera.main.transform.forward, Vector3.up);

        ObjectCollectionManager.Instance.CreateGate(pos, rot); //queries.AddRange(AddGate());
        GetLocationsFromSolver(queries);
    }
Пример #2
0
    public void CreateScene()
    {
        // Only if we're enabled
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return;
        }

        SpatialUnderstandingDllObjectPlacement.Solver_Init();

        SpatialUnderstandingState.Instance.SpaceQueryDescription = "Generating World";

        List <PlacementQuery> queries = new List <PlacementQuery>();

        if (DrawCowboy)
        {
            queries.AddRange(AddCowboy());
        }

        if (DrawBuildings)
        {
            queries.AddRange(AddBuildings());
        }

        if (DrawTrees)
        {
            queries.AddRange(AddTrees());
        }

        GetLocationsFromSolver(queries);
    }
Пример #3
0
    /*
     * Est appelé par SpatialUnderstandingUniqueState
     * Lance la création de la scéne avec ses objets
     */
    public bool CreateScene()
    {
        // Only if we're enabled
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return(false);
        }

        if (SpatialUnderstandingDllObjectPlacement.Solver_Init() > 0)
        {
            BillboardScript.Instance.SpaceQueryDescription = "Generating World";

            /*Liste des contraintes*/
            List <PlacementQuery> queries = new List <PlacementQuery>();

            if (DrawObjects)
            {
                queries.AddRange(AddObjects());
            }

            GetLocationsFromSolver(queries);
            return(true);
        }
        return(false);
    }
Пример #4
0
    public void CreateScene()
    {
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return;
        }

        //在扫描阶段完成、场景敲定后,初始化物体放置解析器。
        SpatialUnderstandingDllObjectPlacement.Solver_Init();

        SpatialUnderstandingState.Instance.SpaceQueryDescription = "Generating World";


        List <PlacementQuery> queries = new List <PlacementQuery>();

        if (DrawBuildings)
        {
            //AddRange()方法,可加入多个元素。可以枚举类型或表类型
            queries.AddRange(AddBuildings());
        }

        if (DrawTrees)
        {
            queries.AddRange(AddTrees());
        }


        GetLocationsFromSolver(queries);
    }
Пример #5
0
    private void Update()
    {
        if (m_scanningComplete)
        {
            return;
        }
        switch (m_spatialUnderstandingState)
        {
        case SpatialUnderstandingState.FinalizeScan:
            //TODO: timeout?
            if (!m_spatialUnderstanding.ScanStatsReportStillWorking)
            {
                Debug.Log("Finalizing scan...");
                m_spatialUnderstanding.RequestFinishScan();
                m_spatialUnderstandingState = SpatialUnderstandingState.WaitingForScanCompletion;
            }
            break;

        case SpatialUnderstandingState.WaitingForMeshImport:
            //TODO: timeout?
            if (m_spatialUnderstanding.UnderstandingCustomMesh.IsImportActive == false)
            {
                Debug.Log("Found " + m_spatialUnderstanding.UnderstandingCustomMesh.GetMeshFilters().Count + " meshes (import active=" + m_spatialUnderstanding.UnderstandingCustomMesh.IsImportActive + ")");
                if (!visualizeSpatialMeshes)
                {
                    HideSpatialMappingMeshes();
                }
                if (!visualizeSpatialUnderstandingMeshes)
                {
                    SetSpatialUnderstandingMaterial(occlusionMaterial);
                }
                SurfacePlaneDeformationManager.Instance.SetSpatialMeshFilters(m_spatialUnderstanding.UnderstandingCustomMesh.GetMeshFilters());
                m_spatialUnderstandingState = SpatialUnderstandingState.WaitingForPlacementSolverInit;
            }
            break;

        case SpatialUnderstandingState.WaitingForPlacementSolverInit:
            //TODO: error checking and timeout?
            if (!m_placementSolverInitialized)
            {
                m_placementSolverInitialized = (SpatialUnderstandingDllObjectPlacement.Solver_Init() == 1);
                Debug.Log("Placement Solver initialization " + (m_placementSolverInitialized ? "succeeded" : "FAILED"));
                if (m_placementSolverInitialized)
                {
                    if (OnScanComplete != null)
                    {
                        OnScanComplete();
                    }
                    m_scanningComplete          = true;
                    m_spatialUnderstandingState = SpatialUnderstandingState.Finished;
                }
            }
            break;

        default:
            break;
        }
    }
Пример #6
0
 public void Init_Spawner()
 {
     if (SpatialUnderstanding.Instance.ScanState == SpatialUnderstanding.ScanStates.Done)
     {
         SpatialUnderstandingDllObjectPlacement.Solver_Init();
         _init = true;
         Spawn();
     }
 }
Пример #7
0
 public bool InitializeSolver()
 {
     if (IsSolverInitialized || !SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
     {
         return(IsSolverInitialized);
     }
     if (SpatialUnderstandingDllObjectPlacement.Solver_Init() == 1)
     {
         IsSolverInitialized = true;
     }
     return(IsSolverInitialized);
 }
Пример #8
0
 static bool Init()
 {
     if (solverInitialized)
     {
         return(true);
     }
     if (SpatialUnderstandingDllObjectPlacement.Solver_Init() == 1)
     {
         solverInitialized = true;
     }
     return(solverInitialized);
 }
Пример #9
0
    private IEnumerator InitSolverCoroutine()
    {
        int retval = 0;
        Job job    = new Job(() => { retval = SpatialUnderstandingDllObjectPlacement.Solver_Init(); });

        job.Execute();
        while (!job.Finished())
        {
            yield return(null);
        }
        Debug.Log("Placement Solver initialization " + (retval == 1 ? "succeeded" : "FAILED"));
        m_solverInitialized = true;
    }
Пример #10
0
    public void CreateScene(int targets)
    {
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return;
        }

        SpatialUnderstandingDllObjectPlacement.Solver_Init();

        List <PlacementQuery> queries = new List <PlacementQuery>();

        queries.AddRange(AddTargets(targets));
        GetLocationsFromSolver(queries);
    }
Пример #11
0
    public void CreateMenu()
    {
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return;
        }

        if (!solverInit)
        {
            SpatialUnderstandingDllObjectPlacement.Solver_Init();
            solverInit = true;
        }
        GetLocationsFromSolver(AddMenu());
    }
Пример #12
0
    public void CreateScene()
    {
        // Only if we're enabled
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return;
        }

        SpatialUnderstandingDllObjectPlacement.Solver_Init();

        SpatialUnderstandingState.Instance.SpaceQueryDescription = "Generating World";

        InvokeRepeating("CreateSceneObjects", spawnTime, spawnTime);
        //CreateSceneObjects();
    }
Пример #13
0
    public void CreateScene()
    {
        // Only if we're enabled
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return;
        }

        SpatialUnderstandingDllObjectPlacement.Solver_Init();

        SpatialUnderstandingState.Instance.SpaceQueryDescription = "Generating World";

        List <PlacementQuery> queries = CreateLocationQueriesForSolver(1, WideBuildingSize, ObjectType.WideBuilding);

        GetLocationsFromSolver(queries);
    }
Пример #14
0
    public void CreateScene()
    {
        Debug.Log("Create scene");
        // Only if we're enabled
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return;
        }

        SpatialUnderstandingDllObjectPlacement.Solver_Init();

        Debug.Log("Generating World");

        List <PlacementQuery> queries = CreateLocationQueriesForSolver(1, GuitarSize, ObjectType.Cube);

        GetLocationsFromSolver(queries);
    }
Пример #15
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);
            }
        }
    }
Пример #16
0
    public void CreateScene()
    {
        // Only if we're enabled
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return;
        }
        //Calls the Solver after Spatial is finalized
        SpatialUnderstandingDllObjectPlacement.Solver_Init();

        SpatialUnderstandingState.Instance.SpaceQueryDescription = "Bottle Cowboy is Generating World";

        List <PlacementQuery> queries = new List <PlacementQuery>();

        if (DrawObject)
        {
            queries.AddRange(AddObjects());
        }

        GetLocationsFromSolver(queries);
    }
Пример #17
0
    /// <summary>
    /// Place given object
    /// </summary>
    /// <param name="placementObject">The object to place</param>
    /// <param name="requiredSpace">The bounds of the object to place</param>
    /// <param name="requiredSurfaceSpace">The bounds of the bottom of the shape to place, only used for edge and floor/ceiling placement</param>
    /// <returns></returns>
    public STPlacementResult Place(GameObject placementObject, Vector3 requiredSpace, Vector3 requiredSurfaceSpace = default(Vector3))
    {
        if (!solverIsInit)
        {
            solverIsInit = SpatialUnderstandingDllObjectPlacement.Solver_Init() == 1;
        }

        Result = new SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult();

        List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule>       nativeRules       = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementRule>();
        List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint> nativeConstraints = new List <SpatialUnderstandingDllObjectPlacement.ObjectPlacementConstraint>();

        foreach (STPlacementRule rule in Rules)
        {
            nativeRules.Add(rule.ToNativeRule());
        }

        foreach (STPlacementConstraint con in Constraints)
        {
            nativeConstraints.Add(con.ToNativeConstraint());
        }

        IntPtr rulePtr       = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(nativeRules.ToArray());
        IntPtr constraintPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(nativeConstraints.ToArray());
        IntPtr definitionPtr = IntPtr.Zero;

        switch (Type)
        {
        case STPlacementType.Floor:
            definitionPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloor(requiredSpace));
            break;

        case STPlacementType.Wall:
            definitionPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnWall(requiredSpace, MinHeight, MaxHeight));
            break;

        case STPlacementType.Ceiling:
            definitionPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnCeiling(requiredSpace));
            break;

        case STPlacementType.Shape:
            definitionPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnShape(requiredSpace, TargetShape.ShapeName, TargetShape.GetComponentIndex(TargetShapeComponent)));
            break;

        case STPlacementType.Edge:
            definitionPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnEdge(requiredSpace, requiredSurfaceSpace));
            break;

        case STPlacementType.FloorAndCeiling:
            definitionPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnFloorAndCeiling(requiredSpace, requiredSurfaceSpace));
            break;

        case STPlacementType.RandomInAir:
            definitionPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_RandomInAir(requiredSpace));
            break;

        case STPlacementType.MidAir:
            definitionPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_InMidAir(requiredSpace));
            break;

        case STPlacementType.UnderPlatformEdge:
            definitionPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_UnderPlatformEdge(requiredSpace));
            break;

        default:
            return(null);
        }

        if (SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject(QueryName + "_" + placementObject.name, definitionPtr, Rules.Count, rulePtr, Constraints.Count, constraintPtr, SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr()) > 0)
        {
            _hasRun = true;
            Debug.Log("Placing object for query " + QueryName);

            Result = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();

            GameObject resultantObject = GameObject.Instantiate(placementObject, Result.Position, Quaternion.LookRotation(Result.Forward, Result.Up));
            if (resultantObject.GetComponent <STPlacedObject>() == null)
            {
                STPlacedObject placedObject = resultantObject.AddComponent <STPlacedObject>();
                placedObject.PlacedObjectName = QueryName + "_" + placementObject.name;
            }
            // TODO: Add a component to the object to remove it from Spatial Understanding if removed in Unity.
            return(new STPlacementResult(resultantObject, Result));
        }
        else
        {
            Debug.Log("Failed to place object for query " + QueryName);
            _hasRun = true;
            return(null);
        }
    }
Пример #18
0
    private void Update()
    {
        if (m_scanningComplete)
        {
            return;
        }
        switch (m_spatialUnderstandingState)
        {
        case SpatialUnderstandingState.StartScanning:
            // Start spatial mapping (SpatialUnderstanding requires this, too)
            if (!m_spatialMappingManager.IsObserverRunning())
            {
                m_spatialMappingManager.StartObserver();
            }
            m_spatialMappingManager.DrawVisualMeshes = visualizeSpatialMeshes;
            m_spatialUnderstanding.ScanStateChanged += OnScanStateChanged;
            m_spatialUnderstanding.RequestBeginScanning();
            m_spatialMappingManager.SetSurfaceMaterial(renderingMaterial);
            m_spatialUnderstandingState = SpatialUnderstandingState.Scanning;
            break;

        case SpatialUnderstandingState.FinalizeScan:
            //TODO: timeout?
            if (!m_spatialUnderstanding.ScanStatsReportStillWorking)
            {
                Debug.Log("Finalizing scan...");
                m_spatialUnderstanding.RequestFinishScan();
                m_spatialUnderstandingState = SpatialUnderstandingState.WaitingForScanCompletion;
            }
            break;

        case SpatialUnderstandingState.WaitingForMeshImport:
            //TODO: timeout?
            if (m_spatialUnderstanding.UnderstandingCustomMesh.IsImportActive == false)
            {
                Debug.Log("Found " + m_spatialUnderstanding.UnderstandingCustomMesh.GetMeshFilters().Count + " meshes (import active=" + m_spatialUnderstanding.UnderstandingCustomMesh.IsImportActive + ")");
                if (!visualizeSpatialMeshes)
                {
                    DisableSpatialMappingMeshes();
                }
                ApplyVisualizationSettings();
                //SurfacePlaneDeformationManager.Instance.SetSpatialMeshFilters(m_spatialUnderstanding.UnderstandingCustomMesh.GetMeshFilters());
                m_spatialUnderstandingState = SpatialUnderstandingState.WaitingForPlacementSolverInit;
            }
            break;

        case SpatialUnderstandingState.WaitingForPlacementSolverInit:
            //TODO: error checking and timeout?
            if (!m_placementSolverInitialized)
            {
                m_placementSolverInitialized = (SpatialUnderstandingDllObjectPlacement.Solver_Init() == 1);
                Debug.Log("Placement Solver initialization " + (m_placementSolverInitialized ? "succeeded" : "FAILED"));
                if (m_placementSolverInitialized)
                {
                    if (OnScanComplete != null)
                    {
                        OnScanComplete();
                    }
                    m_scanningComplete          = true;
                    m_spatialUnderstandingState = SpatialUnderstandingState.Finished;
                }
            }
            break;

        default:
            break;
        }
    }
Пример #19
0
    private void Update()
    {
        if (m_scanningComplete)
        {
            return;
        }
        SpatialUnderstandingDll.Imports.PlayspaceStats stats;
        switch (m_spatialUnderstandingState)
        {
        case State.StartScanning:
            // Start spatial mapping (SpatialUnderstanding requires this, too)
            if (!m_spatialMappingManager.IsObserverRunning())
            {
                m_spatialMappingManager.StartObserver();
            }
            m_spatialMappingManager.DrawVisualMeshes = visualizeSpatialMeshes;
            m_spatialUnderstanding.ScanStateChanged += OnScanStateChanged;
            m_spatialUnderstanding.RequestBeginScanning();
            m_spatialMappingManager.SetSurfaceMaterial(renderingMaterial);
            m_spatialUnderstandingState = State.Scanning;
            break;

        case State.Scanning:
            //if (GetStats(out stats))
            //  Debug.Log("NumFloor=" + stats.NumFloor + ", NumWallX-=" + stats.NumWall_XNeg + ", NumWallX+=" + stats.NumWall_XPos + ", NumWallZ-=" + stats.NumWall_ZNeg + ", NumWallZ+=" + stats.NumWall_ZPos);
            break;

        case State.FinalizeScan:
            //TODO: timeout?
            // Note: this is pretty subtle -- ScanStatsReportStillWorking is *not*
            // automatically updated. It reuses a cached object. GetStats() will
            // fetch the latest object by calling the appropriate query function.
            GetStats(out stats);
            if (!m_spatialUnderstanding.ScanStatsReportStillWorking)
            {
                Debug.Log("Finalizing scan...");
                m_spatialUnderstanding.RequestFinishScan();
                m_spatialUnderstandingState = State.WaitingForScanCompletion;
            }
            break;

        case State.WaitingForMeshImport:
            //TODO: timeout?
            if (m_spatialUnderstanding.UnderstandingCustomMesh.IsImportActive == false)
            {
                List <MeshFilter> meshFilters = m_spatialUnderstanding.UnderstandingCustomMesh.GetMeshFilters();
                Debug.Log("Found " + meshFilters.Count + " meshes (import active=" + m_spatialUnderstanding.UnderstandingCustomMesh.IsImportActive + ")");
                if (!visualizeSpatialMeshes)
                {
                    DisableSpatialMappingMeshes();
                }
                ApplyVisualizationSettings();
                SurfacePlaneDeformationManager.Instance.SetSpatialMeshFilters(meshFilters);
                if (buildNavMesh)
                {
                    m_navMeshBuilder.AddSourceMeshes(meshFilters, m_spatialUnderstanding.transform);
                }
                m_spatialUnderstandingState = State.WaitingForPlacementSolverInit;
            }
            break;

        case State.WaitingForPlacementSolverInit:
            //TODO: error checking and timeout?
            bool navMeshFinished = !buildNavMesh || (buildNavMesh && m_navMeshBuilder.isFinished);
            if (!m_solverInitCalled)
            {
                m_solverInitCalled = true;
                TaskManager.Instance.Schedule(
                    () =>
                {
                    int retval = SpatialUnderstandingDllObjectPlacement.Solver_Init();
                    return(() =>
                    {
                        Debug.Log("Placement Solver initialization " + (retval == 1 ? "succeeded" : "FAILED"));
                        m_solverInitialized = true;
                    });
                });
                if (buildNavMesh)
                {
                    m_navMeshBuilder.BuildAsync();
                }
            }
            else if (m_solverInitialized && navMeshFinished)
            {
                if (autoApplyStaticBatching)
                {
                    ApplyStaticBatching();
                }
                m_scanningComplete          = true;
                m_spatialUnderstandingState = State.Finished;
                if (OnScanComplete != null)
                {
                    OnScanComplete();
                }
            }
            break;

        default:
            break;
        }
    }