/// <summary>
        /// Adds instance of the given model and returns its internal id which can be used for removing the instance. Local matrix specified will be changed to internal packed matrix.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="localMatrix">Local transformation matrix. Changed to internal matrix.</param>
        /// <param name="colorMaskHsv"></param>
        public uint AddInstance(ModelId model, ref Matrix localMatrix, BoundingBox localAabb, Vector4 colorMaskHsv = default(Vector4))
        {
            MyModelInstanceData builderInstanceData;
            if (!m_instanceParts.TryGetValue(model, out builderInstanceData))
            {
                builderInstanceData = new MyModelInstanceData(m_instanceFlags, m_maxViewDistance);
                builderInstanceData.Model = model;
                m_instanceParts.Add(model, builderInstanceData);
            }

            uint instanceId = m_idCounter++;

            var instanceData = new MyCubeInstanceData()
            {
                ColorMaskHSV = colorMaskHsv,
                EnableSkinning = false,
                LocalMatrix = localMatrix
            };
            instanceData.SetColorMaskHSV(colorMaskHsv);

            builderInstanceData.InstanceData.Add(instanceId, instanceData);
            // Matrix has been changed due to packing.
            localMatrix = builderInstanceData.InstanceData[instanceId].LocalMatrix;

            m_AABB = m_AABB.Include(localAabb.Transform(localMatrix));

            return instanceId;
        }