コード例 #1
0
        protected Action checkMasks(OcTree tree, Index p)
        {
            // skip if no masks
            if (tree.masks == null)
                return new Action(false, true);

            // check against each mask
            int voxelSize = 1 << (tree.maximumDetail - p.depth);
            Action action = new Action(false, true);
            foreach (VoxelMask mask in tree.masks) {
                if (mask.active) {

                    // calculate relative position
                    int comparison = (mask.maskAbove)?
                        compareToVoxel((int)mask.yPosition, (int)p.y, voxelSize):
                        -compareToVoxel((int)mask.yPosition, (int)p.y, voxelSize);

                    // evaluate action based on relative position
                    if (comparison == 0)
                        action.doTraverse = true;
                    else if (comparison < 0)
                        return new Action(false, false);
                }
            }
            return action;
        }
コード例 #2
0
        public void InitializeWithRegionAndData()
        {
            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.oneBoundingBox
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = new BoundingBox(new Vector3(3, 3, 3), new Vector3(3, 1, 0))
            });

            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            Assert.IsFalse(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.Zero, testOcTree.Region.Max);

            testOcTree.UpdateTree();

            Assert.IsTrue(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.Zero, testOcTree.Region.Min);
            Assert.AreEqual(new Vector3(4, 4, 4), testOcTree.Region.Max);

            OcTreeUtilities.Dump(testOcTree);
        }
コード例 #3
0
        public void IsEmpty()
        {
            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.oneBoundingBox
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = new BoundingBox(new Vector3(3, 3, 3), new Vector3(3, 1, 0))
            });

            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            // pending insertions also invalidate IsEmpty
            Assert.IsFalse(testOcTree.IsEmpty);

            Assert.IsFalse(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.Zero, testOcTree.Region.Max);

            testOcTree.UpdateTree();

            Assert.IsFalse(testOcTree.IsEmpty);
        }
コード例 #4
0
ファイル: QueryTest.cs プロジェクト: snowfox1939/PyriteServer
        private SetVersion GetLargeDataSet()
        {
            SetVersion setVersion = new SetVersion();

            setVersion.Name    = "Test";
            setVersion.Version = "v1";

            OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>(new BoundingBox(Vector3.Zero, Vector3.Zero), new CubeBounds[] { }, 2);

            using (Stream metadataStream = new FileStream(".\\data\\validdataset2\\v1\\metadata.json", FileMode.Open, FileAccess.Read))
            {
                ocTree = MetadataLoader.Load(metadataStream, ocTree, "L1", new Vector3(1, 1, 1));
            }

            ocTree.UpdateTree();
            Assert.AreEqual(2, ocTree.MinimumSize);
            Assert.IsNotNull(ocTree);
            Assert.IsTrue(ocTree.HasChildren);

            SetVersionLevelOfDetail lod = new SetVersionLevelOfDetail
            {
                Name        = "L1",
                Cubes       = ocTree,
                SetSize     = ocTree.Region.Max - ocTree.Region.Min,
                WorldBounds = new BoundingBox(Vector3.Zero, new Vector3(40, 40, 40))
            };

            setVersion.DetailLevels =
                new SortedDictionary <string, SetVersionLevelOfDetail>(new[] { lod }.ToDictionary(l => l.Name, l => l, StringComparer.OrdinalIgnoreCase));
            return(setVersion);
        }
コード例 #5
0
        public VoxelRenderer(Index index, OcTree control)
            : this(index, control, new Vector3(
				index.x * control.sizes[index.depth],
				index.y * control.sizes[index.depth],
				index.z * control.sizes[index.depth]))
        {
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: carlhuth/GenXSource
        static void Main(string[] args)
        {
            OcTree <TestObj> tree = new OcTree <TestObj>(20, new Vector3(0, 0, 0));

            tree.Insert(new TestObj(Vector3.Empty, new Vector3(1, 1, 1)));
            tree.Insert(new TestObj(new Vector3(5, 0, 0), new Vector3(1, 1, 1)));
        }
コード例 #7
0
        public void Initialize()
        {
            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>();

            Assert.IsFalse(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.AreEqual(this.zeroBoundingBox, testOcTree.Region);
            OcTreeUtilities.Dump(testOcTree);
        }
コード例 #8
0
        public Character(OcTree octree, IDrawableModel model,
                         Vector2 maxSpeed, int maxLife, int attack)
            : base(octree, model, maxSpeed, true, true)
        {
            _life    = maxLife;
            _maxLife = maxLife;

            _attack = attack;
        }
コード例 #9
0
 /// <summary>
 /// Sets up an Application.
 /// </summary>
 /// <param name="target">the voxel tree to setup for applying to</param>
 /// <returns>the setup Application</returns>
 public virtual Application setup(OcTree target)
 {
     Application app = new Application();
     app.tree = target;
     //uint width = (uint)(1 << (target.maximumDetail)) - 1;
     //app.min = new Index(target.maxDetail);
     //app.max = new Index(target.maxDetail, width, width, width);
     return app;
 }
コード例 #10
0
        public void InitializeWithRegion()
        {
            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.oneBoundingBox);

            Assert.IsFalse(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.One, testOcTree.Region.Max);
            OcTreeUtilities.Dump(testOcTree);
        }
コード例 #11
0
            public TerrainMap(Vector3D center, Vector3D extents)
            {
                pointsAdded_ = 0;
                points_      = new OcTree(center, extents, 0);
                currentTime_ = 0;
                UpDirection  = new Vector3D(0, 0, 0);

                // The radius of a small grid large wheel is 1.25 (2.5 small blocks)
                edgeDetectionCollider_ = new HollowSphereCollider(center, 1.25, 3.0);
            }
コード例 #12
0
        public static void Dump(OcTree <CubeBounds> ocTree)
        {
            Queue <Tuple <OcTree <CubeBounds>, int> > enumeration = new Queue <Tuple <OcTree <CubeBounds>, int> >();

            enumeration.Enqueue(new Tuple <OcTree <CubeBounds>, int>(ocTree, 0));

            int octantCount = 0;
            int objectCount = 0;
            int maxDepth    = 0;

            while (enumeration.Count > 0)
            {
                Tuple <OcTree <CubeBounds>, int> next = enumeration.Dequeue();
                OcTree <CubeBounds> nextOcTree        = next.Item1;
                int indent = next.Item2;

                octantCount++;

                Trace.IndentLevel = indent;
                Trace.WriteLine(nextOcTree.ToString());

                foreach (CubeBounds obj in nextOcTree.Items)
                {
                    objectCount++;
                    Trace.WriteLine(" " + obj.ToString());
                }

                if (nextOcTree.HasChildren)
                {
                    int nextIndent = indent + 1;
                    if (nextIndent > maxDepth)
                    {
                        maxDepth = nextIndent;
                    }

                    byte active = nextOcTree.OctantMask;
                    for (int bit = 0; bit < 8; bit++)
                    {
                        if (((active >> bit) & 0x01) == 0x01)
                        {
                            OcTree <CubeBounds> childNode = nextOcTree.Octants[bit];
                            if (childNode != null)
                            {
                                enumeration.Enqueue(new Tuple <OcTree <CubeBounds>, int>(childNode, nextIndent));
                            }
                        }
                    }
                }
            }

            Trace.IndentLevel = 0;
            Trace.WriteLine(String.Format("Maximum Depth: {0}", maxDepth));
            Trace.WriteLine(String.Format("Octant count: {0}", octantCount));
            Trace.WriteLine(String.Format("Object count: {0}", objectCount));
        }
コード例 #13
0
        /// <summary>
        /// Creates (or finds existing) vertices for the given collection of positions.
        /// As this uses distance queries, stacked positions will only produce one vertex.
        /// The output is not guaranteed to have the same number of elements as the input.
        /// </summary>
        /// <param name="vertexCollection"></param>
        /// <param name="positions"></param>
        /// <returns></returns>
        public static IEnumerable <Vertex> GetVerticesForPositions(OcTree <Vertex> vertexCollection, IEnumerable <Vec3d> positions)
        {
            var vertices = new HashSet <Vertex>();

            foreach (var position in positions)
            {
                vertices.Add(GetVertexForPosition(vertexCollection, position));
            }

            return(vertices);
        }
コード例 #14
0
 public T TraceRay(Vector3 rayOrigin, Vector3 rayDir, out int internalValue)
 {
     OcTree <T> .OcTreeResult result = sceneGraph.RayIntersectFirst(rayOrigin, rayDir);
     if (result != null)
     {
         internalValue = result.InternalValue;
         return((T)result.Item);
     }
     internalValue = -1;
     return(null);
 }
コード例 #15
0
        private async Task <List <SetVersionLevelOfDetail> > ExtractDetailLevels(SetMetadataContract setMetadata, Uri baseUrl)
        {
            List <SetVersionLevelOfDetail> detailLevels = new List <SetVersionLevelOfDetail>();

            foreach (int detailLevel in Enumerable.Range(setMetadata.MinimumLod, setMetadata.MaximumLod - setMetadata.MinimumLod + 1))
            {
                string detailLevelName = "L" + detailLevel;

                Uri lodMetadataUri = new Uri(baseUrl, "L" + detailLevel + "/metadata.json");
                CubeMetadataContract cubeMetadata = await this.Deserialize <CubeMetadataContract>(lodMetadataUri);

                OcTree <CubeBounds> octree = MetadataLoader.Load(cubeMetadata, detailLevelName, new Vector3(1, 1, 1));
                octree.UpdateTree();

                Vector3 cubeBounds = cubeMetadata.SetSize;

                ExtentsContract worldBounds        = cubeMetadata.WorldBounds;
                ExtentsContract virtualWorldBounds = cubeMetadata.VirtualWorldBounds;

                SetVersionLevelOfDetail currentSetLevelOfDetail = new SetVersionLevelOfDetail();
                currentSetLevelOfDetail.Metadata    = lodMetadataUri;
                currentSetLevelOfDetail.Number      = detailLevel;
                currentSetLevelOfDetail.Cubes       = octree;
                currentSetLevelOfDetail.ModelBounds = new BoundingBox(
                    new Vector3(worldBounds.XMin, worldBounds.YMin, worldBounds.ZMin),
                    new Vector3(worldBounds.XMax, worldBounds.YMax, worldBounds.ZMax));

                if (virtualWorldBounds != null)
                {
                    currentSetLevelOfDetail.WorldBounds =
                        new BoundingBox(
                            new Vector3(virtualWorldBounds.XMin, virtualWorldBounds.YMin, virtualWorldBounds.ZMin),
                            new Vector3(virtualWorldBounds.XMax, virtualWorldBounds.YMax, virtualWorldBounds.ZMax));
                }
                else
                {
                    currentSetLevelOfDetail.WorldBounds = new BoundingBox(
                        new Vector3(worldBounds.XMin, worldBounds.YMin, worldBounds.ZMin),
                        new Vector3(worldBounds.XMax, worldBounds.YMax, worldBounds.ZMax));
                }

                currentSetLevelOfDetail.SetSize     = new Vector3(cubeBounds.X, cubeBounds.Y, cubeBounds.Z);
                currentSetLevelOfDetail.Name        = "L" + detailLevel.ToString(CultureInfo.InvariantCulture);
                currentSetLevelOfDetail.VertexCount = cubeMetadata.VertexCount;

                currentSetLevelOfDetail.TextureTemplate = new Uri(lodMetadataUri, "texture/{x}_{y}.jpg");
                currentSetLevelOfDetail.ModelTemplate   = new Uri(lodMetadataUri, "{x}_{y}_{z}.{format}");

                currentSetLevelOfDetail.TextureSetSize = cubeMetadata.TextureSetSize;

                detailLevels.Add(currentSetLevelOfDetail);
            }
            return(detailLevels);
        }
コード例 #16
0
        public static OcTree <CubeBounds> Load(Stream metadata, OcTree <CubeBounds> ocTree, string name, Vector3 cubeSize)
        {
            CubeMetadataContract data;

            using (StreamReader tr = new StreamReader(metadata))
                using (JsonTextReader jr = new JsonTextReader(tr))
                {
                    data = new JsonSerializer().Deserialize <CubeMetadataContract>(jr);
                }

            return(Load(data, ocTree, name, cubeSize));
        }
コード例 #17
0
        public virtual void Unload()
        {
            _correctPosition = Vector3.Zero;

            Speed    = Vector2.Zero;
            MaxSpeed = Vector2.Zero;

            _model.Unload();
            _model = null;

            _octree = null;
        }
コード例 #18
0
        public override Application setup(OcTree target)
        {
            LineApplication app = new LineApplication();
            app.tree = target;
            app.position = target.globalToVoxelPosition(globalPoints[0]);
            app.points = new Vector3[globalPoints.Length];
            for (int i = 0; i < globalPoints.Length; ++i)
                app.points[i] = target.globalToVoxelPosition(globalPoints[i]) -app.position;
            app.childApp = (LocalApplication) child.setup(target);
            // TODO: set min, max and updateMesh.

            return app;
        }
コード例 #19
0
        public GenericSceneManager(Device device, GraphicsDeviceSettings outSettings,
                                   Vector3 origin, int size)
            : base(device)
        {
            this.outSettings = outSettings;

            sceneGraph             = new OcTree <T>(size, origin);
            screenEntities         = new List <IScreenSpaceEntity>();
            postSceneWorldEntities = new List <IWorldEntity>();
            postSceneViewEntities  = new List <ViewSpaceEntity>();
            zCompareViewEntities   = new SortedList <float, ViewSpaceEntity>();
            sceneGraphEntities     = sceneGraph.SceneItems;
        }
コード例 #20
0
        /// <summary>
        /// Creates (or finds an existing) vertex for the given position
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        public static Vertex GetVertexForPosition(OcTree <Vertex> vertexCollection, Vec3d position)
        {
            var vertex = new Vertex {
                Position = position
            };

            if (vertexCollection.Insert(vertex, position))
            {
                return(vertex);
            }

            return(vertexCollection.FindClosest(position));
        }
コード例 #21
0
ファイル: QueryTest.cs プロジェクト: snowfox1939/PyriteServer
        private SetVersionLevelOfDetail GenerateRubikLevelOfDetail(string name, int scale, Vector3 worldBounds)
        {
            int offset = scale / 3;
            int min    = offset;
            int max    = (2 * offset);
            List <CubeBounds>       testBounds = new List <CubeBounds>();
            SetVersionLevelOfDetail lod;

            for (int x = 0; x < scale; x++)
            {
                for (int y = 0; y < scale; y++)
                {
                    for (int z = 0; z < scale; z++)
                    {
                        if (offset != 1)
                        {
                            if ((min <= x && x < max) && (min <= y && y < max) && (min <= z && z < max))
                            {
                                testBounds.Add(new ValidCube {
                                    BoundingBox = this.MakeCube(new Vector3(x, y, z), 1)
                                });
                            }
                            else
                            {
                                testBounds.Add(new InvalidCube {
                                    BoundingBox = this.MakeCube(new Vector3(x, y, z), 1)
                                });
                            }
                        }
                        else
                        {
                            testBounds.Add(new ValidCube {
                                BoundingBox = this.MakeCube(new Vector3(x, y, z), 1)
                            });
                        }
                    }
                }
            }
            OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            ocTree.UpdateTree();
            lod = new SetVersionLevelOfDetail
            {
                Name        = name,
                Cubes       = ocTree,
                SetSize     = new Vector3(scale, scale, scale),
                WorldBounds = new BoundingBox(Vector3.Zero, worldBounds)
            };
            return(lod);
        }
コード例 #22
0
        /// <summary>
        /// Applies mutator as configured to a voxel tree.
        /// </summary>
        /// <param name="target">the voxel tree to apply the mutator to</param>
        public void apply(OcTree target)
        {
            Application app = setup(target);
            //applyMasksToApplication(app, target);

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            apply(app, target.getHead(), new Index());
            watch.Stop();
            UnityEngine.MonoBehaviour.print("Mutator Apply Time: " +watch.Elapsed.TotalSeconds);
            foreach(VoxelJob job in app.jobs)
                job.execute();
            target.dirty = true;
        }
コード例 #23
0
        public MoveableObject(OcTree octree, IDrawableModel model, Vector2 maxSpeed,
                              bool checkGravity = true, bool checkCollision = true)
        {
            _octree = octree;

            _model = model;

            _speed    = new Vector2(0.1f, 0.1f);
            _maxSpeed = maxSpeed;

            _correctPosition = _model.Position;

            _checkGravity   = checkGravity;
            _checkCollision = checkCollision;
        }
コード例 #24
0
 public VoxelRenderer(Index index, OcTree control, Vector3 localPosition)
 {
     this.index = index;
     this.position = localPosition;
     this.control = control;
     size = 0;
     ++rendCount;
     vertices = new Dictionary<int, int>();
     VERTS = new Vector3[0];
     NORMS = new Vector3[0];
     TRIS = new int[0];
     lock(control) {
         control.renderers[index] = this;
     }
 }
コード例 #25
0
        public override Application setup(OcTree target)
        {
            Vector3 halfDimension = worldDimensions / target.voxelSize() /2f;
            Vector3 center = target.transform.InverseTransformPoint(worldPosition) / target.voxelSize();
            Vector3 exactMin = center - halfDimension;
            Vector3 exactMax = center + halfDimension;

            CubeApp app = new CubeApp();
            app.tree = target;
            app.halfDimension = halfDimension;
            app.min = new Index(target.maximumDetail, (uint)exactMin.x, (uint)exactMin.y, (uint)exactMin.z);
            app.max = new Index(target.maximumDetail, (uint)exactMax.x, (uint)exactMax.y, (uint)exactMax.z);
            app.position = center;
            return app;
        }
コード例 #26
0
 public override Application setup(OcTree target)
 {
     float radius = worldRadius / target.voxelSize();
     Vector3 radiusCube = new Vector3(radius, radius, radius);
     Vector3 center = target.globalToVoxelPosition(worldPosition);
     Vector3 exactMin = center - radiusCube;
     Vector3 exactMax = center + radiusCube;
     SphereApp app = new SphereApp();
     app.tree = target;
     app.min = new Index(target.maximumDetail, (uint)exactMin.x, (uint)exactMin.y, (uint)exactMin.z);
     app.max = new Index(target.maximumDetail, (uint)exactMax.x, (uint)exactMax.y, (uint)exactMax.z);
     app.position = center;
     app.radius = radius;
     return app;
 }
コード例 #27
0
        public void LoadLargeSet()
        {
            OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>(new BoundingBox(Vector3.Zero, Vector3.Zero), new CubeBounds[] { }, 2);

            using (Stream metadataStream = new FileStream(".\\data\\validdataset2\\v1\\metadata.json", FileMode.Open, FileAccess.Read))
            {
                ocTree = MetadataLoader.Load(metadataStream, ocTree, "L1", new Vector3(1, 1, 1));
            }

            ocTree.UpdateTree();
            Assert.AreEqual(2, ocTree.MinimumSize);
            Assert.IsNotNull(ocTree);
            Assert.IsTrue(ocTree.HasChildren);

            OcTreeUtilities.Dump(ocTree);
        }
コード例 #28
0
        public static OcTree <CubeBounds> Load(CubeMetadataContract data, OcTree <CubeBounds> ocTree, string name, Vector3 cubeSize)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (ocTree == null)
            {
                throw new ArgumentNullException("ocTree");
            }

            ocTree.Add(LoadCubeBounds(data, name, cubeSize));

            return(ocTree);
        }
コード例 #29
0
ファイル: OcTreeNode.cs プロジェクト: nathanaeljones/GifLib
 /// <summary>
 /// �˲����Ĺ��캯��
 /// </summary>
 /// <param name="leaf">�Ƿ���Ҷ�ӽڵ�</param>
 /// <param name="level">�㼶</param>
 /// <param name="parent">���ڵ�</param>
 internal OcTreeNode(int colorDepth,int level,OcTree tree)
 {
     this.ColorDepth = colorDepth;
     this.Leaf = (colorDepth==level);
     this.Level = level;
     if (!Leaf)
     {
         NextReducible = tree.ReducibleNodes[level];
         tree.ReducibleNodes[level] = this;
         Children = new OcTreeNode[8];
     }
     else
     {
         tree.IncrementLeaves();
     }
 }
コード例 #30
0
        public void RayIntersectionTest()
        {
            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(Vector3.Zero, 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(1, 1, 1), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(2, 2, 2), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(3, 3, 3), 1)
            });

            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            testOcTree.UpdateTree();
            OcTreeUtilities.Dump(testOcTree);

            Assert.IsTrue(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.Zero, testOcTree.Region.Min);
            Assert.AreEqual(new Vector3(4, 4, 4), testOcTree.Region.Max);

            Assert.AreEqual(0, testOcTree.Items.Count);

            // Ray Intersects
            Ray ray1 = new Ray(new Vector3(0, 0, 0), new Vector3(1, 1, 1));

            Assert.AreEqual(4, testOcTree.AllIntersections(ray1).Count());

            Ray ray2 = new Ray(new Vector3(0, 0, 0), new Vector3(0, 0, 1));

            Assert.AreEqual(1, testOcTree.AllIntersections(ray2).Count());

            // No Intersects
            Ray ray3 = new Ray(new Vector3(3, 0, 0), new Vector3(1, 1, 1));

            Assert.AreEqual(0, testOcTree.AllIntersections(ray3).Count());
        }
コード例 #31
0
        public Player(OcTree octree, string modelName, Vector3 position, Vector3 rotation,
                      Vector3 scale, Vector2 maxSpeed, int maxLife, int attack)
            : base(octree, new AnimatedModel((GameModel)ModelManager.GetModel(modelName),
                                             position, rotation, scale, 0), maxSpeed, maxLife, attack)
        {
            _jump    = false;
            _endJump = true;

            _lastPlayerState = State.Waiting;
            _playerState     = State.Waiting;

            _lastPlayerAction = Action.None;
            _playerAction     = Action.None;

            _lastPlayerXDirection = XDirection.Right;
            _playerXDirection     = XDirection.Right;
            _lastPlayerYDirection = YDirection.None;
            _playerYDirection     = YDirection.None;

            ((AnimatedModel)this.DModel).Animation.StartClip("Waiting", true);
        }
コード例 #32
0
        public void SphereIntersectionTest()
        {
            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(Vector3.Zero, 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(1, 1, 1), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(2, 2, 2), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(3, 3, 3), 1)
            });

            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            testOcTree.UpdateTree();
            OcTreeUtilities.Dump(testOcTree);

            Assert.IsTrue(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.Zero, testOcTree.Region.Min);
            Assert.AreEqual(new Vector3(4, 4, 4), testOcTree.Region.Max);

            Assert.AreEqual(0, testOcTree.Items.Count);

            // Sphere Intersects - unlike bounding box, surface intersections are ignored
            BoundingSphere sphere1 = new BoundingSphere(new Vector3(2, 2, 2), 0.5f);

            Assert.AreEqual(2, testOcTree.AllIntersections(sphere1).Count());

            BoundingSphere sphere2 = new BoundingSphere(new Vector3(2, 2, 2), 1f);

            Assert.AreEqual(2, testOcTree.AllIntersections(sphere2).Count());
        }
コード例 #33
0
        public void  ItemsTest()
        {
            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(Vector3.Zero, 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(1, 1, 1), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(2, 2, 2), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(3, 3, 3), 1)
            });

            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            testOcTree.UpdateTree();
            OcTreeUtilities.Dump(testOcTree);

            Assert.IsTrue(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);

            var allItems = testOcTree.AllItems();

            Assert.AreEqual(4, allItems.Count());

            var octants = testOcTree.Octants.Where(o => o != null);

            foreach (var octant in octants)
            {
                var childItems = octant.AllItems();
                Assert.AreEqual(2, childItems.Count());
            }
        }
コード例 #34
0
ファイル: QueryTest.cs プロジェクト: snowfox1939/PyriteServer
        private SetVersion Get4x4x4DataSet1()
        {
            SetVersion setVersion = new SetVersion();

            setVersion.Name    = "Test";
            setVersion.Version = "v1";

            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(Vector3.Zero, 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(1, 1, 1), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(2, 2, 2), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(3, 3, 3), 1)
            });

            OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            ocTree.UpdateTree();

            SetVersionLevelOfDetail lod = new SetVersionLevelOfDetail
            {
                Name        = "L1",
                Cubes       = ocTree,
                SetSize     = ocTree.Region.Max - ocTree.Region.Min,
                WorldBounds = new BoundingBox(Vector3.Zero, new Vector3(40, 40, 40))
            };

            setVersion.DetailLevels =
                new SortedDictionary <string, SetVersionLevelOfDetail>(new[] { lod }.ToDictionary(l => l.Name, l => l, StringComparer.OrdinalIgnoreCase));
            return(setVersion);
        }
コード例 #35
0
 public static bool isRenderLod(float x, float y, float z, float size, OcTree control)
 {
     if (!control.useLod)
         return size == control.sizes[control.maximumDetail];
     return getDistSquare(control.getLocalCamPosition(), new Vector3(x + 0.5f, y + 0.5f, z + 0.5f), size) >= size * size * control.getLodDetail();
 }
コード例 #36
0
 public static bool isRenderSize(float size, OcTree control)
 {
     return control.sizes[control.maximumDetail - VoxelRenderer.VOXEL_COUNT_POWER] == size;
 }
コード例 #37
0
 public UpdateCheckJob(VoxelBlock block, OcTree control, byte detailLevel)
 {
     this.block = block;
     this.control = control;
     this.detailLevel = detailLevel;
     control.addUpdateCheckJob();
 }
コード例 #38
0
 /// <summary>
 /// Constructor of the <c>EnemyContext</c> class.
 /// </summary>
 /// <param name="mainScene">Reference to the OcTree where the enemy moves</param>
 /// <param name="player">Reference to the main player.</param>
 /// <param name="enemy">Reference to the current enemy.</param>
 public EnemyContext(OcTree mainScene, Player player, Enemy enemy)
 {
     _mainScene = mainScene;
     _player    = player;
     _enemy     = enemy;
 }
コード例 #39
0
        public void BoundingBoxIntersectionTest()
        {
            List <CubeBounds> testBounds = new List <CubeBounds>();

            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(Vector3.Zero, 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(1, 1, 1), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(2, 2, 2), 1)
            });
            testBounds.Add(new CubeBounds {
                BoundingBox = this.MakeCube(new Vector3(3, 3, 3), 1)
            });

            OcTree <CubeBounds> testOcTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds);

            testOcTree.UpdateTree();
            OcTreeUtilities.Dump(testOcTree);

            Assert.IsTrue(testOcTree.HasChildren);
            Assert.IsTrue(testOcTree.IsRoot);
            Assert.IsNotNull(testOcTree.Region);
            Assert.AreEqual(Vector3.Zero, testOcTree.Region.Min);
            Assert.AreEqual(new Vector3(4, 4, 4), testOcTree.Region.Max);

            Assert.AreEqual(0, testOcTree.Items.Count);

            // Box Intersects
            BoundingBox box1 = this.MakeCube(new Vector3(-0.5f, -0.5f, -0.5f), 1);

            Assert.AreEqual(1, testOcTree.AllIntersections(box1).Count());

            BoundingBox box2 = this.MakeCube(new Vector3(0.5f, 0.5f, 0.5f), 1);

            Assert.AreEqual(2, testOcTree.AllIntersections(box2).Count());

            BoundingBox box3 = this.MakeCube(new Vector3(1.5f, 1.5f, 1.5f), 1);

            Assert.AreEqual(2, testOcTree.AllIntersections(box3).Count());

            BoundingBox box4 = this.MakeCube(new Vector3(2.5f, 2.5f, 2.5f), 1);

            Assert.AreEqual(2, testOcTree.AllIntersections(box4).Count());

            BoundingBox box5 = this.MakeCube(new Vector3(3.5f, 3.5f, 3.5f), 1);

            Assert.AreEqual(1, testOcTree.AllIntersections(box5).Count());

            // Box Contains & Intersects
            BoundingBox box6 = this.MakeCube(new Vector3(-0.5f, -0.5f, -0.5f), 2);

            Assert.AreEqual(2, testOcTree.AllIntersections(box6).Count());

            BoundingBox box7 = this.MakeCube(new Vector3(0.5f, 0.5f, 0.5f), 2);

            Assert.AreEqual(3, testOcTree.AllIntersections(box7).Count());

            // Box Contains
            BoundingBox box8 = this.MakeCube(new Vector3(3, 3, 3), 2);

            Assert.AreEqual(2, testOcTree.AllIntersections(box8).Count());

            // Box No Intersection
            BoundingBox box9 = this.MakeCube(new Vector3(0, 0, 3), 1);

            Assert.AreEqual(0, testOcTree.AllIntersections(box9).Count());
        }
コード例 #40
0
        public void OnNewDataSource(IAtom[] atoms, IBond[] bonds, Vector3 origin, Bounds3D bounds)
        {
            sceneGraph = new OcTree <ChemEntity>((int)bounds.radius * 2, -bounds.min);

            /*screenEntities.Add(new BondAngle(device, atoms[0], atoms[1], atoms[2]));
             * screenEntities[0].Init(device);
             *
             * postSceneWorldEntities.Add(new BoundingBoxEntity(new BoundingBox(bounds.min, bounds.max), false, Color.LightGray.ToArgb()));
             * postSceneWorldEntities[0].Init(device);
             * postSceneWorldEntities.Add(new SphereAxis3D());
             * postSceneWorldEntities[1].Init(device);*/

            sceneGraphEntities = sceneGraph.SceneItems;

            // create molecule entities
            foreach (IAtom atom in atoms)
            {
                AtomEntity aentity = AtomEntity.BuildEntity(atom);
                sceneGraph.Insert(aentity);

                /*ScreenLabelVSpaceEntity entity = new ScreenLabelVSpaceEntity(atom.ID + ":" + aentity.UId.ToString(), (Vector3)aentity.Position3D);
                 * entity.Init(device);
                 * screenEntities.Add(entity);*/
                /*AtomSymbolEntity entity = new AtomSymbolEntity(aentity);
                 * entity.Init(device);
                 * postSceneViewEntities.Add(entity);*/
            }

            //foreach (IBond bond in bonds)
            //{
            //sceneGraph.Insert(new BondE);
            //}

            scheme.SetOutputDescription(coDesc);
            scheme.SetupScene(origin, bounds.radius);

            // pass throught scheme & effects
            IGeometryCreator[] schStreams = scheme.GetAtomStreams();
            DataFields[]       efxFields  = null;
            //effect.DesiredData(out efxFields, false);

            DataFields[][] allStreams = new DataFields[1 + (efxFields != null ? 1 : 0)][];
            //if (efxFields != null)
            //    allStreams[1] = efxFields;
            if (scheme.HandlesAtoms && atoms != null)
            {
                GeomDataBufferStream[] geomStream = new GeomDataBufferStream[schStreams.Length];
                for (int i = 0; i < geomStream.Length; i++)
                {
                    allStreams[0] = schStreams[i].Fields;
                    GeomDataTransformer.CreateBufferStream(allStreams, out geomStream[i]);
                }
                // fill buffer stream
                scheme.SetAtomData(atoms, geomStream);
            }

            schStreams = scheme.GetBondStreams();
            if (scheme.HandlesBonds && bonds != null)
            {
                GeomDataBufferStream[] geomStream = new GeomDataBufferStream[schStreams.Length];
                for (int i = 0; i < geomStream.Length; i++)
                {
                    allStreams[0] = schStreams[i].Fields;
                    GeomDataTransformer.CreateBufferStream(allStreams, out geomStream[i]);
                }
                // fill buffer stream
                scheme.SetBondData(bonds, geomStream);
            }
        }
コード例 #41
0
 public GenMeshJob(VoxelBlock block, OcTree control, byte detailLevel)
 {
     this.block = block;
     this.control = control;
     this.detailLevel = detailLevel;
 }
コード例 #42
0
ファイル: Program.cs プロジェクト: xuchuansheng/GenXSource
 static void Main(string[] args)
 {
     OcTree<TestObj> tree = new OcTree<TestObj>(20, new Vector3(0, 0, 0));
     tree.Insert(new TestObj(Vector3.Empty, new Vector3(1, 1, 1)));
     tree.Insert(new TestObj(new Vector3(5, 0, 0), new Vector3(1, 1, 1)));
 }
コード例 #43
0
 public void set(byte detailLevel, int x, int y, int z, Voxel value, OcTree control)
 {
     if (detailLevel > 0) {
         short factor = (short)(1 << (detailLevel - CHILD_COUNT_POWER));
         byte xi = (byte)(x / factor);
         byte yi = (byte)(y / factor);
         byte zi = (byte)(z / factor);
         if (detailLevel == CHILD_COUNT_POWER) {
             children[xi, yi, zi] = value;
         } else {
             if (children[xi, yi, zi].GetType() == typeof(Voxel)) {
                 if (children[xi, yi, zi].Equals(value)) { ++skippedSubdivisions; return; }
                 children[xi, yi, zi] = new VoxelBlock((Voxel)children[xi, yi, zi]);
             }
             ((VoxelBlock)children[xi, yi, zi]).set((byte)(detailLevel - CHILD_COUNT_POWER), x - xi * factor, y - yi * factor, z - zi * factor, value, control);
         }
     } else
         set(value);
 }
コード例 #44
0
        public void OnNewDataSource(IAtom[] atoms, IBond[] bonds, Vector3 origin, Bounds3D bounds)
        {
            sceneGraph = new OcTree<ChemEntity>((int)bounds.radius * 2, -bounds.min);
            /*screenEntities.Add(new BondAngle(device, atoms[0], atoms[1], atoms[2]));
            screenEntities[0].Init(device);

            postSceneWorldEntities.Add(new BoundingBoxEntity(new BoundingBox(bounds.min, bounds.max), false, Color.LightGray.ToArgb()));
            postSceneWorldEntities[0].Init(device);
            postSceneWorldEntities.Add(new SphereAxis3D());
            postSceneWorldEntities[1].Init(device);*/
            
            sceneGraphEntities = sceneGraph.SceneItems;

            // create molecule entities
            foreach (IAtom atom in atoms)
            {
                AtomEntity aentity = AtomEntity.BuildEntity(atom);
                sceneGraph.Insert(aentity);
                /*ScreenLabelVSpaceEntity entity = new ScreenLabelVSpaceEntity(atom.ID + ":" + aentity.UId.ToString(), (Vector3)aentity.Position3D);
                entity.Init(device);
                screenEntities.Add(entity);*/
                /*AtomSymbolEntity entity = new AtomSymbolEntity(aentity);
                entity.Init(device);
                postSceneViewEntities.Add(entity);*/
            }
            
            //foreach (IBond bond in bonds)
            //{
                //sceneGraph.Insert(new BondE);
            //}

            scheme.SetOutputDescription(coDesc);
            scheme.SetupScene(origin, bounds.radius);

            // pass throught scheme & effects
            IGeometryCreator[] schStreams = scheme.GetAtomStreams();
            DataFields[] efxFields = null;
            //effect.DesiredData(out efxFields, false);

            DataFields[][] allStreams = new DataFields[1 + (efxFields != null ? 1 : 0 )][];
            //if (efxFields != null)
            //    allStreams[1] = efxFields;
            if (scheme.HandlesAtoms && atoms != null)
            {
                GeomDataBufferStream[] geomStream = new GeomDataBufferStream[schStreams.Length];
                for (int i = 0; i < geomStream.Length; i++)
                {
                    allStreams[0] = schStreams[i].Fields;
                    GeomDataTransformer.CreateBufferStream(allStreams, out geomStream[i]);
                }
                // fill buffer stream
                scheme.SetAtomData(atoms, geomStream);
            }

            schStreams = scheme.GetBondStreams();
            if (scheme.HandlesBonds && bonds != null)
            {
                GeomDataBufferStream[] geomStream = new GeomDataBufferStream[schStreams.Length];
                for (int i = 0; i < geomStream.Length; i++)
                {
                    allStreams[0] = schStreams[i].Fields;
                    GeomDataTransformer.CreateBufferStream(allStreams, out geomStream[i]);
                }
                // fill buffer stream
                scheme.SetBondData(bonds, geomStream);
            }
        }
コード例 #45
0
        public void setToHeightmap(byte detailLevel, int x, int y, int z, ref float[,] map, byte material, OcTree control)
        {
            if (detailLevel <= CHILD_COUNT_POWER) {
                for (int xi = 0; xi < CHILD_DIMENSION; ++xi) {
                    for (int zi = 0; zi < CHILD_DIMENSION; ++zi) {
                        for (int yi = 0; yi < CHILD_DIMENSION; ++yi) {
                            if (yi + y >= map[x + xi, z + zi])
                                break;
                            else if (material == byte.MaxValue) {
                                children[xi, yi, zi] = Voxel.empty;
                            } else {
                                if (yi + y >= map[x + xi, z + zi] - 1) {
                                    byte opacity = (byte)((map[x + xi, z + zi] - yi - y) * byte.MaxValue);
                                    if (opacity > control.isoLevel || children[xi, yi, zi].averageOpacity() <= opacity)
                                        children[xi, yi, zi] = new Voxel(material, opacity);
                                } else {
                                    children[xi, yi, zi] = new Voxel(material, byte.MaxValue);
                                }
                            }
                        }
                    }
                }
            } else {
                int multiplier = (1 << (detailLevel - CHILD_COUNT_POWER));
                for (int xi = 0; xi < CHILD_DIMENSION; ++xi) {
                    for (int zi = 0; zi < CHILD_DIMENSION; ++zi) {
                        int xMax = x + (xi + 1) * multiplier;
                        int zMax = z + (zi + 1) * multiplier;
                        float yMin = float.MaxValue;
                        float yMax = 0;
                        for (int xPos = x + xi * multiplier; xPos < xMax; ++xPos) {
                            for (int zPos = z + zi * multiplier; zPos < zMax; ++zPos) {
                                if (map[xPos, zPos] < yMin) yMin = map[xPos, zPos];
                                if (map[xPos, zPos] > yMax) yMax = map[xPos, zPos];
                            }
                        }

                        int firstUnsolidBlock = Mathf.Min(((int)(yMin - y)) / multiplier, CHILD_DIMENSION);
                        int lastUnsolidBlock = Mathf.Min(((int)(yMax - y)) / multiplier, CHILD_DIMENSION - 1);
                        int yi = 0;
                        for (; yi < firstUnsolidBlock; ++yi) {
                            if (material == byte.MaxValue)
                                children[xi, yi, zi] = Voxel.empty;
                            else
                                children[xi, yi, zi] = new Voxel(material, byte.MaxValue);
                        }
                        if (lastUnsolidBlock < 0) continue;
                        for (; yi <= lastUnsolidBlock; ++yi) {
                            if (children[xi, yi, zi].GetType() == typeof(Voxel))
                                children[xi, yi, zi] = new VoxelBlock((Voxel)children[xi, yi, zi]);
                            ((VoxelBlock)children[xi, yi, zi]).setToHeightmap((byte)(detailLevel - CHILD_COUNT_POWER), x + xi * multiplier, y + yi * multiplier, z + zi * multiplier, ref map, material, control);
                        }
                    }
                }
            }
            control.dirty = true;
        }
コード例 #46
0
 public CubeMutator(OcTree control, Vector3 worldPosition, Vector3 worldDimensions, VoxelHolder value, bool updateMesh)
 {
     this.worldPosition = worldPosition;
     this.worldDimensions = worldDimensions;
     this.value = value.toVoxel();
 }
コード例 #47
0
        public void setToHeightmap(byte detailLevel, int x, int y, int z, ref float[,] map, byte[,] mats, OcTree control)
        {
            if (detailLevel <= CHILD_COUNT_POWER) {
                for (int xi = 0; xi < CHILD_DIMENSION; ++xi) {
                    for (int zi = 0; zi < CHILD_DIMENSION; ++zi) {
                        for (int yi = 0; yi < CHILD_DIMENSION; ++yi) {
                            if (yi + y >= map[x + xi, z + zi])
                                break;
                            else if (yi + y >= map[x + xi, z + zi] - 1) {
                                if (mats[x + xi, z + zi] == byte.MaxValue)
                                    children[xi, yi, zi] = Voxel.empty;
                                else
                                    children[xi, yi, zi] = new Voxel(mats[x + xi, z + zi], (byte)((map[x + xi, z + zi] - yi - y) * byte.MaxValue));
                            } else {
                                if (mats[x + xi, z + zi] == byte.MaxValue)
                                    children[xi, yi, zi] = Voxel.empty;
                                else
                                    children[xi, yi, zi] = new Voxel(mats[x + xi, z + zi], byte.MaxValue);
                            }
                        }
                    }
                }
            } else {
                int multiplier = (1 << (detailLevel - CHILD_COUNT_POWER));
                for (int xi = 0; xi < CHILD_DIMENSION; ++xi) {
                    for (int zi = 0; zi < CHILD_DIMENSION; ++zi) {
                        int xMax = x + (xi + 1) * multiplier;
                        int zMax = z + (zi + 1) * multiplier;
                        float yMin = float.MaxValue;
                        float yMax = 0;
                        bool multipleMaterials = false;
                        byte material = mats[x, z];
                        for (int xPos = x + xi * multiplier; xPos < xMax; ++xPos) {
                            for (int zPos = z + zi * multiplier; zPos < zMax; ++zPos) {
                                if (map[xPos, zPos] < yMin) yMin = map[xPos, zPos];
                                if (map[xPos, zPos] > yMax) yMax = map[xPos, zPos];
                                if (mats[xPos, zPos] != material) multipleMaterials = true;
                            }
                        }

                        if (multipleMaterials) yMin = 0;
                        int firstUnsolidBlock = Mathf.Min(((int)(yMin - y)) / multiplier, CHILD_DIMENSION);
                        int lastUnsolidBlock = Mathf.Min(((int)(yMax - y)) / multiplier, CHILD_DIMENSION - 1);
                        int yi = 0;
                        for (; yi < firstUnsolidBlock; ++yi) {
                            if (mats[x + xi * multiplier, z + zi * multiplier] == byte.MaxValue)
                                children[xi, yi, zi] = Voxel.empty;
                            else
                                children[xi, yi, zi] = new Voxel(mats[x + xi * multiplier, z + zi * multiplier], byte.MaxValue);
                        }
                        if (lastUnsolidBlock < 0) continue;
                        for (; yi <= lastUnsolidBlock; ++yi) {
                            VoxelBlock newChild = new VoxelBlock();
                            newChild.setToHeightmap((byte)(detailLevel - CHILD_COUNT_POWER), x + xi * multiplier, y + yi * multiplier, z + zi * multiplier, ref map, mats, control);
                            children[xi, yi, zi] = newChild;
                        }
                    }
                }
            }
            control.dirty = true;
        }
コード例 #48
0
ファイル: OcTreeNode.cs プロジェクト: nathanaeljones/GifLib
 internal void AddColor(Color32* pixel, int level,OcTree tree)
 {
     //�������Ҷ�ˣ���ʾһ����ɫ����������
     if (this.Leaf)
     {
         Increment(pixel);
         tree.TracePrevious(this);
         return;
     }
     int shift = 7 - level;
     int index = ((pixel->Red & mask[level]) >> (shift - 2)) |
                   ((pixel->Green & mask[level]) >> (shift - 1)) |
                   ((pixel->Blue & mask[level]) >> (shift));
     OcTreeNode child = Children[index];
     if (child == null)
     {
         child = new OcTreeNode(ColorDepth, level+1, tree);
         Children[index] = child;
     }
     child.AddColor(pixel, ++level,tree);
 }
コード例 #49
0
        public void updateAll(uint x, uint y, uint z, byte detailLevel, OcTree control, bool force = false)
        {
            // check if this is a high enough detail level.  If not, call the childrens' update methods
            VoxelRenderer renderer = control.getRenderer(new Index(detailLevel, x, y, z));
            if (!isRenderSize(control.sizes[detailLevel], control) && (!isRenderLod(x, y, z, control.sizes[detailLevel], control))) {
                for (byte xi = 0; xi < CHILD_DIMENSION; ++xi) {
                    for (byte yi = 0; yi < CHILD_DIMENSION; ++yi) {
                        for (byte zi = 0; zi < CHILD_DIMENSION; ++zi) {
                            if (children[xi, yi, zi].GetType() == typeof(Voxel)) {
                                children[xi, yi, zi] = new VoxelBlock((Voxel)children[xi, yi, zi]);
                            }
                            UpdateCheckJob job = new UpdateCheckJob((VoxelBlock)children[xi, yi, zi], control, (byte)(detailLevel + 1));
                            job.setOffset((byte)(x * CHILD_DIMENSION + xi), (byte)(y * CHILD_DIMENSION + yi), (byte)(z * CHILD_DIMENSION + zi));
                            control.enqueueCheck(job);
                        }
                    }
                }
                return;
            }

            // check if we already have a mesh
            if (renderer == null) {
                renderer = new VoxelRenderer(new Index(detailLevel, x, y, z), control);
            } else if (!force) {
                return;
            }

            // We should generate a mesh
            GenMeshJob updateJob = new GenMeshJob(this, control, detailLevel);
            updateJob.setOffset(x, y, z);
            control.enqueueUpdate(updateJob);
        }
コード例 #50
0
 public LinkRenderersJob(OcTree control)
 {
     this.control = control;
 }
コード例 #51
0
        private async Task <List <SetVersionLevelOfDetail> > ExtractDetailLevels2(SetMetadataContract setMetadata, Uri baseUrl)
        {
            OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>();

            List <LoaderSet> lods = new List <LoaderSet>();

            foreach (int detailLevel in Enumerable.Range(setMetadata.MinimumLod, setMetadata.MaximumLod - setMetadata.MinimumLod + 1))
            {
                // Allow exceptions to propagate here for logging in ELMAH
                string detailLevelName            = "L" + detailLevel;
                Uri    lodMetadataUri             = new Uri(baseUrl, detailLevelName + "/metadata.json");
                CubeMetadataContract cubeMetadata = await this.Deserialize <CubeMetadataContract>(lodMetadataUri);

                lods.Add(new LoaderSet {
                    CubeMetadataContract = cubeMetadata, Name = detailLevelName, DetailLevel = detailLevel, MetadataUrl = lodMetadataUri
                });
            }

            Vector3 maxSetSize = new Vector3(0, 0, 0);

            foreach (var loaderSet in lods)
            {
                if (loaderSet.CubeMetadataContract.SetSize.X > maxSetSize.X)
                {
                    maxSetSize.X = loaderSet.CubeMetadataContract.SetSize.X;
                }

                if (loaderSet.CubeMetadataContract.SetSize.Y > maxSetSize.Y)
                {
                    maxSetSize.Y = loaderSet.CubeMetadataContract.SetSize.Y;
                }

                if (loaderSet.CubeMetadataContract.SetSize.Z > maxSetSize.Z)
                {
                    maxSetSize.Z = loaderSet.CubeMetadataContract.SetSize.Z;
                }
            }

            List <SetVersionLevelOfDetail> detailLevels = new List <SetVersionLevelOfDetail>();

            foreach (LoaderSet loaderSet in lods)
            {
                var cubeMetadata = loaderSet.CubeMetadataContract;

                Vector3 cubeSize = maxSetSize / loaderSet.CubeMetadataContract.SetSize;

                ocTree.Add(MetadataLoader.LoadCubeBounds(loaderSet.CubeMetadataContract, loaderSet.Name, cubeSize));

                Vector3 cubeBounds = cubeMetadata.SetSize;

                ExtentsContract worldBounds        = cubeMetadata.WorldBounds;
                ExtentsContract virtualWorldBounds = cubeMetadata.VirtualWorldBounds;

                SetVersionLevelOfDetail currentSetLevelOfDetail = new SetVersionLevelOfDetail();
                currentSetLevelOfDetail.Metadata    = loaderSet.MetadataUrl;
                currentSetLevelOfDetail.Number      = loaderSet.DetailLevel;
                currentSetLevelOfDetail.Cubes       = ocTree;
                currentSetLevelOfDetail.ModelBounds = new BoundingBox(
                    new Vector3(worldBounds.XMin, worldBounds.YMin, worldBounds.ZMin),
                    new Vector3(worldBounds.XMax, worldBounds.YMax, worldBounds.ZMax));

                if (virtualWorldBounds != null)
                {
                    currentSetLevelOfDetail.WorldBounds =
                        new BoundingBox(
                            new Vector3(virtualWorldBounds.XMin, virtualWorldBounds.YMin, virtualWorldBounds.ZMin),
                            new Vector3(virtualWorldBounds.XMax, virtualWorldBounds.YMax, virtualWorldBounds.ZMax));
                }
                else
                {
                    currentSetLevelOfDetail.WorldBounds = new BoundingBox(
                        new Vector3(worldBounds.XMin, worldBounds.YMin, worldBounds.ZMin),
                        new Vector3(worldBounds.XMax, worldBounds.YMax, worldBounds.ZMax));
                }

                currentSetLevelOfDetail.SetSize     = new Vector3(cubeBounds.X, cubeBounds.Y, cubeBounds.Z);
                currentSetLevelOfDetail.Name        = "L" + loaderSet.DetailLevel.ToString(CultureInfo.InvariantCulture);
                currentSetLevelOfDetail.VertexCount = cubeMetadata.VertexCount;

                currentSetLevelOfDetail.TextureTemplate = new Uri(loaderSet.MetadataUrl, "texture/{x}_{y}.jpg");
                currentSetLevelOfDetail.ModelTemplate   = new Uri(loaderSet.MetadataUrl, "{x}_{y}_{z}.{format}");

                currentSetLevelOfDetail.TextureSetSize = cubeMetadata.TextureSetSize;

                detailLevels.Add(currentSetLevelOfDetail);
            }

            ocTree.UpdateTree();

            return(detailLevels);
        }