Beispiel #1
0
 public LoadCubeRequest(int x, int y, int z, int lod, PyriteQuery query, Action <GameObject> registerCreatedObjects)
 {
     X        = x;
     Y        = y;
     Z        = z;
     LodIndex = lod;
     Query    = query;
     RegisterCreatedObjects = registerCreatedObjects;
 }
Beispiel #2
0
        public LoadCubeRequest(int x, int y, int z, int lod, GameObject obj)
        {
            X          = x;
            Y          = y;
            Z          = z;
            LodIndex   = lod;
            gameObject = obj;

            Query = null;
            RegisterCreatedObjects = null;
        }
        public void SetCubePosition(int x, int y, int z, int lod, PyriteQuery query, PyriteLoader manager)
        {
            _x           = x;
            _y           = y;
            _z           = z;
            _lodIndex    = lod;
            _pyriteQuery = query;
            _manager     = manager;
            var nameBuilder = new StringBuilder("PH_L");

            nameBuilder.Append(_pyriteQuery.DetailLevels[_lodIndex].Value);
            nameBuilder.Append(':');
            nameBuilder.Append(x);
            nameBuilder.Append('_');
            nameBuilder.Append(y);
            nameBuilder.Append('_');
            nameBuilder.Append(z);
            name = nameBuilder.ToString();
        }
        public IEnumerator AddUpgradedDetectorCubes(PyriteQuery pyriteQuery, int x, int y, int z, int lod,
                                                    Action <IEnumerable <GameObject> > registerCreatedDetectorCubes)
        {
            var newLod           = lod - 1;
            var createdDetectors = new List <GameObject>();
            var pyriteLevel      = pyriteQuery.DetailLevels[newLod];

            var cubeFactor = pyriteQuery.GetNextCubeFactor(lod);
            var min        = new Vector3(x * (int)cubeFactor.x + 0.5f, y * (int)cubeFactor.y + 0.5f,
                                         z * (int)cubeFactor.z + 0.5f);
            var max = new Vector3((x + 1) * (int)cubeFactor.x - 0.5f, (y + 1) * (int)cubeFactor.y - 0.5f,
                                  (z + 1) * (int)cubeFactor.z - 0.5f);
            var intersections =
                pyriteQuery.DetailLevels[newLod].Octree.AllIntersections(new BoundingBox {
                Min = min, Max = max
            });

            foreach (var i in intersections)
            {
                var newCube = CreateCubeFromCubeBounds(i.Object);
                var cubePos = pyriteLevel.GetWorldCoordinatesForCube(newCube);

                var newDetectionCube = ObjectPooler.Current.GetPooledObject(PlaceHolderCube);
                newDetectionCube.transform.position = new Vector3(-cubePos.x,
                                                                  cubePos.z + _geometryBufferAltitudeTransform, -cubePos.y);
                newDetectionCube.transform.rotation = Quaternion.identity;
                var meshRenderer = newDetectionCube.GetComponent <MeshRenderer>();
                meshRenderer.enabled = true;
                newDetectionCube.GetComponent <IsRendered>()
                .SetCubePosition(newCube.X, newCube.Y, newCube.Z, newLod, pyriteQuery, this);

                newDetectionCube.transform.localScale = new Vector3(
                    pyriteLevel.WorldCubeScale.x,
                    pyriteLevel.WorldCubeScale.z,
                    pyriteLevel.WorldCubeScale.y);
                newDetectionCube.SetActive(true);
                createdDetectors.Add(newDetectionCube);
            }
            registerCreatedDetectorCubes(createdDetectors);
            yield break;
        }
Beispiel #5
0
        IEnumerator Load()
        {
            tempPosition       = transform.position;
            transform.position = Vector3.zero;

            pyriteQuery = new PyriteQuery(this,
                                          SetName,
                                          ModelVersion,
                                          PyriteServer,
                                          UpgradeFactor,
                                          UpgradeConstant,
                                          DowngradeFactor,
                                          DowngradeConstant);
            yield return(StartCoroutine(pyriteQuery.LoadAll(FilterDetailLevels ? DetailLevelsToFilter : null)));

            pyriteLevel = pyriteQuery.DetailLevels[DetailLevel];
            var setSize = pyriteLevel.SetSize;

            if (DebugLogs)
            {
                Debug.Log("Set Size " + setSize);
            }

            var adjustedPos = new Vector3(
                -CameraRig.transform.position.x,
                -CameraRig.transform.position.z,
                CameraRig.transform.position.y - WorldYOffset);

            cubeCamPos = pyriteLevel.GetCubeForWorldCoordinates(adjustedPos);

            var worldObject = new GameObject("OctreeParent") as GameObject;

            worldObject.transform.position = Vector3.zero;
            worldObject.transform.rotation = Quaternion.identity;
            OctreeTracking = new GameObject("OctreeTracking") as GameObject;
            OctreeTracking.transform.position = Vector3.zero;
            OctreeTracking.transform.rotation = Quaternion.identity;

            if (ShowCubes)
            {
                foreach (var i in pyriteLevel.Octree.AllItems())
                {
                    var pCube   = CreateCubeFromCubeBounds(i);
                    var cubePos = pyriteLevel.GetWorldCoordinatesForCube(pCube);

                    var adjustedCubePos = new Vector3(
                        -cubePos.x,
                        cubePos.z + WorldYOffset,
                        -cubePos.y);
                    var loc = Instantiate(TranslucentCube, adjustedCubePos, Quaternion.identity) as GameObject;
                    loc.name = string.Format("Mesh:{0},{1},{2}", pCube.X, pCube.Y, pCube.Z);
                    loc.transform.localScale = new Vector3(
                        pyriteLevel.WorldCubeScale.x,
                        pyriteLevel.WorldCubeScale.z,
                        pyriteLevel.WorldCubeScale.y);
                    loc.transform.parent = worldObject.transform;
                }
            }

            transform.position = tempPosition;
            LoadCamCubes();
        }
        protected virtual IEnumerator Load()
        {
            _pyriteQuery = new PyriteQuery(this, SetName, ModelVersion, PyriteServer, UpgradeFactor, UpgradeConstant,
                                           DowngradeFactor, DowngradeConstant);
            yield return(StartCoroutine(_pyriteQuery.LoadAll(FilterDetailLevels ? DetailLevelsToFilter : null)));

            var initialDetailLevelIndex = DetailLevel - 1;

            if (UseCameraDetection)
            {
                initialDetailLevelIndex = _pyriteQuery.DetailLevels.Length - 1;
            }

            _pyriteLevel = _pyriteQuery.DetailLevels[initialDetailLevelIndex];

            var allOctCubes = _pyriteQuery.DetailLevels[initialDetailLevelIndex].Octree.AllItems();

            foreach (var octCube in allOctCubes)
            {
                var pCube   = CreateCubeFromCubeBounds(octCube);
                var x       = pCube.X;
                var y       = pCube.Y;
                var z       = pCube.Z;
                var cubePos = _pyriteLevel.GetWorldCoordinatesForCube(pCube);
                _geometryBufferAltitudeTransform = 0 - _pyriteLevel.ModelBoundsMin.z;

                if (UseCameraDetection)
                {
                    var detectionCube = ObjectPooler.Current.GetPooledObject(PlaceHolderCube);
                    detectionCube.transform.position = new Vector3(-cubePos.x,
                                                                   cubePos.z + _geometryBufferAltitudeTransform, -cubePos.y);
                    detectionCube.transform.rotation = Quaternion.identity;
                    var meshRenderer = detectionCube.GetComponent <MeshRenderer>();
                    meshRenderer.enabled = true;
                    detectionCube.GetComponent <IsRendered>()
                    .SetCubePosition(x, y, z, initialDetailLevelIndex, _pyriteQuery, this);

                    detectionCube.transform.localScale = new Vector3(
                        _pyriteLevel.WorldCubeScale.x,
                        _pyriteLevel.WorldCubeScale.z,
                        _pyriteLevel.WorldCubeScale.y);

                    detectionCube.SetActive(true);
                }
                else
                {
                    var loadRequest = new LoadCubeRequest(x, y, z, initialDetailLevelIndex, _pyriteQuery, null);
                    yield return(StartCoroutine(EnqueueLoadCubeRequest(loadRequest)));
                }
            }

            if (CameraRig != null)
            {
                // Hardcodes the coordinate inversions which are parameterized on the geometry buffer

                var min = new Vector3(
                    -_pyriteLevel.ModelBoundsMin.x,
                    _pyriteLevel.ModelBoundsMin.z + _geometryBufferAltitudeTransform,
                    -_pyriteLevel.ModelBoundsMin.y);
                var max = new Vector3(
                    -_pyriteLevel.ModelBoundsMax.x,
                    _pyriteLevel.ModelBoundsMax.z + _geometryBufferAltitudeTransform,
                    -_pyriteLevel.ModelBoundsMax.y);

                //Kainiemi: Some mechanism needed to inform InputManager about the transform change
                var inputManager = CameraRig.GetComponent <PyriteDemoClient.InputManager>();
                if (inputManager != null)
                {
                    // Give input manager position limits based on model bounds
                    var highestLod = _pyriteQuery.DetailLevels.First();
                    var lowestLod  = _pyriteQuery.DetailLevels.Last();
                    inputManager.SetInputLimits(
                        new Vector3(highestLod.ModelBoundsMin.x + lowestLod.WorldCubeScale.x / 2,
                                    highestLod.ModelBoundsMin.z + _geometryBufferAltitudeTransform +
                                    lowestLod.WorldCubeScale.z / 3,
                                    highestLod.ModelBoundsMin.y + lowestLod.WorldCubeScale.y / 2),
                        new Vector3(highestLod.ModelBoundsMax.x - lowestLod.WorldCubeScale.x / 2,
                                    highestLod.ModelBoundsMax.z + _geometryBufferAltitudeTransform +
                                    (lowestLod.WorldCubeScale.z * 1.5f),
                                    highestLod.ModelBoundsMax.y - lowestLod.WorldCubeScale.y / 2));

                    if (AutomateCameraPositionOnLoad)
                    {
                        var newCameraPosition = min + (max - min) / 1.5f;
                        newCameraPosition           += new Vector3(0, (max - min).y * 2f, 0);
                        CameraRig.transform.position = newCameraPosition;
                        inputManager.NotifyOnTransformChange(CameraRig.transform.position);
                    }
                    else
                    {
                        inputManager.NotifyReadyForControl();
                    }
                }
            }
        }
        protected override IEnumerator Load()
        {
            var pyriteQuery = new PyriteQuery(this, SetName, ModelVersion, PyriteServer);

            if (TargetGameObject != null)
            {
                var transformedPosition = new Vector3(
                    -TargetGameObject.transform.position.x,
                    -TargetGameObject.transform.position.z,
                    TargetGameObject.transform.position.y - 600
                    );

                yield return(StartCoroutine(pyriteQuery.Load3X3(Reference, transformedPosition)));
            }
            else
            {
                yield return(StartCoroutine(pyriteQuery.Load3X3(Reference, QueryPosition)));
            }

            var xmin = pyriteQuery.DetailLevels[0].WorldBoundsMax.x;
            var ymin = pyriteQuery.DetailLevels[0].WorldBoundsMax.y;
            var zmin = pyriteQuery.DetailLevels[0].WorldBoundsMax.z;
            var xmax = pyriteQuery.DetailLevels[0].WorldBoundsMin.x;
            var ymax = pyriteQuery.DetailLevels[0].WorldBoundsMin.y;
            var zmax = pyriteQuery.DetailLevels[0].WorldBoundsMin.z;

            var cubesToSkip = new Dictionary <int, HashSet <PyriteCube> >();

            foreach (var pyriteLevel in pyriteQuery.DetailLevels)
            {
                xmin = pyriteLevel.WorldBoundsMax.x;
                ymin = pyriteLevel.WorldBoundsMax.y;
                zmin = pyriteLevel.WorldBoundsMax.z;
                xmax = pyriteLevel.WorldBoundsMin.x;
                ymax = pyriteLevel.WorldBoundsMin.y;
                zmax = pyriteLevel.WorldBoundsMin.z;
                cubesToSkip[pyriteLevel.Value + 1] = new HashSet <PyriteCube>();
                if (!cubesToSkip.ContainsKey(pyriteLevel.Value))
                {
                    cubesToSkip[pyriteLevel.Value] = new HashSet <PyriteCube>();
                }

                for (var i = 0; i < pyriteLevel.Cubes.Length; i++)
                {
                    var x          = pyriteLevel.Cubes[i].X;
                    var y          = pyriteLevel.Cubes[i].Y;
                    var z          = pyriteLevel.Cubes[i].Z;
                    var cubeFactor = pyriteQuery.GetPreviousCubeFactor(pyriteLevel.Value - 1);
                    cubesToSkip[pyriteLevel.Value + 1].Add(new PyriteCube
                    {
                        X = x / (int)cubeFactor.x,
                        Y = y / (int)cubeFactor.y,
                        Z = z / (int)cubeFactor.z
                    });
                    if (cubesToSkip[pyriteLevel.Value].Contains(new PyriteCube {
                        X = x, Y = y, Z = z
                    }))
                    {
                        if (SkipLowerDetailedCubes)
                        {
                            continue;
                        }
                    }
                    var cubePos = pyriteLevel.GetWorldCoordinatesForCube(pyriteLevel.Cubes[i]);
                    xmin = Math.Min(cubePos.x, xmin);
                    ymin = Math.Min(cubePos.y, ymin);
                    zmin = Math.Min(cubePos.z, zmin);

                    xmax = Math.Max(cubePos.x, xmax);
                    ymax = Math.Max(cubePos.y, ymax);
                    zmax = Math.Max(cubePos.z, zmax);
                    var loadRequest = new LoadCubeRequest(x, y, z, pyriteLevel.Value - 1, pyriteQuery, null);
                    yield return(StartCoroutine(EnqueueLoadCubeRequest(loadRequest)));
                }
            }

            if (CameraRig != null)
            {
                // Hardcoding some values for now
                var min = new Vector3(xmin, ymin, zmin);
                var max = new Vector3(xmax, ymax, zmax);
                var newCameraPosition = min + (max - min) / 2.0f;
                newCameraPosition           += new Vector3(0, 0, (max - min).z * 1.4f);
                CameraRig.transform.position = newCameraPosition;

                CameraRig.transform.rotation = Quaternion.Euler(0, 180, 0);
            }
        }