Example #1
0
            //

            public Item(SubMesh subMesh)
            {
                this.subMesh = subMesh;

                subMesh.GetSomeGeometry(out positions, out indices);

                Bounds bounds = Bounds.Cleared;

                foreach (Vec3 pos in positions)
                {
                    bounds.Add(pos);
                }
                bounds.Expand(bounds.GetSize() * .001f);

                OctreeContainer.InitSettings initSettings = new OctreeContainer.InitSettings();
                initSettings.InitialOctreeBounds       = bounds;
                initSettings.OctreeBoundsRebuildExpand = Vec3.Zero;
                initSettings.MinNodeSize = bounds.GetSize() / 50;
                octreeContainer          = new OctreeContainer(initSettings);

                for (int nTriangle = 0; nTriangle < indices.Length / 3; nTriangle++)
                {
                    Vec3 vertex0 = positions[indices[nTriangle * 3 + 0]];
                    Vec3 vertex1 = positions[indices[nTriangle * 3 + 1]];
                    Vec3 vertex2 = positions[indices[nTriangle * 3 + 2]];

                    Bounds triangleBounds = new Bounds(vertex0);
                    triangleBounds.Add(vertex1);
                    triangleBounds.Add(vertex2);

                    int octreeIndex = octreeContainer.AddObject(triangleBounds, 1);
                }
            }
            //
            public Item( SubMesh subMesh )
            {
                this.subMesh = subMesh;

                subMesh.GetSomeGeometry( out positions, out indices );

                Bounds bounds = Bounds.Cleared;
                foreach( Vec3 pos in positions )
                    bounds.Add( pos );
                bounds.Expand( bounds.GetSize() * .001f );

                OctreeContainer.InitSettings initSettings = new OctreeContainer.InitSettings();
                initSettings.InitialOctreeBounds = bounds;
                initSettings.OctreeBoundsRebuildExpand = Vec3.Zero;
                initSettings.MinNodeSize = bounds.GetSize() / 50;
                octreeContainer = new OctreeContainer( initSettings );

                for( int nTriangle = 0; nTriangle < indices.Length / 3; nTriangle++ )
                {
                    Vec3 vertex0 = positions[ indices[ nTriangle * 3 + 0 ] ];
                    Vec3 vertex1 = positions[ indices[ nTriangle * 3 + 1 ] ];
                    Vec3 vertex2 = positions[ indices[ nTriangle * 3 + 2 ] ];

                    Bounds triangleBounds = new Bounds( vertex0 );
                    triangleBounds.Add( vertex1 );
                    triangleBounds.Add( vertex2 );

                    int octreeIndex = octreeContainer.AddObject( triangleBounds, 1 );
                }
            }