コード例 #1
0
        public unsafe int AddInstances(int model, List <MyInstanceData> instances)
        {
            InstancedModelBuffer buffer;

            if (!m_instancedModels.TryGetValue(model, out buffer))
            {
                buffer = new InstancedModelBuffer(this, model);
                buffer.SetPerInstanceLod(Lod == 0);
                m_instancedModels[model] = buffer;
            }

            buffer.Instances = instances.GetInternalArray();

            var count = instances.Count;

            fixed(MyInstanceData *data = buffer.Instances)
            for (int i = 0; i < count; i++)
            {
                BoundingBox modelBox = buffer.ModelBb.Transform(data[i].LocalMatrix);

                buffer.Bounds.Include(ref modelBox);
            }

            // Fix the unused slot lists
            buffer.UnusedSlots.Clear();
            for (int i = count; i < instances.Capacity; ++i)
            {
                buffer.UnusedSlots.Enqueue((short)(i));
            }

            m_changedBuffers.Add(model);

            return(0);
        }
コード例 #2
0
        public short AddInstance(int modelId, ref MyInstanceData data)
        {
            InstancedModelBuffer buffer;

            if (!m_instancedModels.TryGetValue(modelId, out buffer))
            {
                buffer = new InstancedModelBuffer(this, modelId);
                buffer.SetPerInstanceLod(Lod == 0);
                m_instancedModels[modelId] = buffer;
            }

            short empty;

            if (buffer.UnusedSlots.TryDequeue(out empty))
            {
                buffer.Instances[empty] = data;
            }
            else
            {
                int prevSize = buffer.Instances != null ? buffer.Instances.Length : 0;

                int size = GetExpandedSize(prevSize);
                Array.Resize(ref buffer.Instances, size);

                int diff = size - prevSize;
                empty = (short)prevSize;

                buffer.Instances[empty] = data;

                for (int i = 1; i < diff; ++i)
                {
                    buffer.UnusedSlots.Enqueue((short)(i + empty));
                }
            }

            BoundingBox modelBox = buffer.ModelBb.Transform(data.LocalMatrix);

            buffer.Bounds.Include(ref modelBox);

            m_changedBuffers.Add(modelId);

            return(empty);
        }
コード例 #3
0
        public short AddInstance(int modelId, ref MyInstanceData data)
        {
            InstancedModelBuffer buffer;
            if (!m_instancedModels.TryGetValue(modelId, out buffer))
            {
                buffer = new InstancedModelBuffer(this, modelId);
                buffer.SetPerInstanceLod(Lod == 0);
                m_instancedModels[modelId] = buffer;
            }

            short empty;
            if (buffer.UnusedSlots.TryDequeue(out empty))
            {
                buffer.Instances[empty] = data;
            }
            else
            {
                int prevSize = buffer.Instances != null ? buffer.Instances.Length : 0;

                int size = GetExpandedSize(prevSize);
                Array.Resize(ref buffer.Instances, size);

                int diff = size - prevSize;
                empty = (short)prevSize;

                buffer.Instances[empty] = data;

                for (int i = 1; i < diff; ++i)
                {
                    buffer.UnusedSlots.Enqueue((short)(i + empty));
                }
            }

            BoundingBox modelBox = buffer.ModelBb.Transform(data.LocalMatrix);
            buffer.Bounds.Include(ref modelBox);

            m_changedBuffers.Add(modelId);

            return empty;
        }
コード例 #4
0
        public unsafe int AddInstances(int model, List<MyInstanceData> instances)
        {
            InstancedModelBuffer buffer;
            if (!m_instancedModels.TryGetValue(model, out buffer))
            {
                buffer = new InstancedModelBuffer(this, model);
                buffer.SetPerInstanceLod(Lod == 0);
                m_instancedModels[model] = buffer;
            }

            buffer.Instances = instances.GetInternalArray();

            var count = instances.Count;

            fixed (MyInstanceData* data = buffer.Instances)
                for (int i = 0; i < count; i++)
                {
                    BoundingBox modelBox = buffer.ModelBb.Transform(data[i].LocalMatrix);
                    buffer.Bounds.Include(ref modelBox);
                }

            // Fix the unused slot lists
            buffer.UnusedSlots.Clear();
            for (int i = count; i < instances.Capacity; ++i)
            {
                buffer.UnusedSlots.Enqueue((short)(i));
            }

            m_changedBuffers.Add(model);

            return 0;
        }