public void DrawInstanced(DeviceContext context, HLSLVoxelModelInstanced effect, IList <VoxelModelInstance> instances)
        {
            if (!_initialized)
            {
                return;
            }

            if (instances.Count == 0)
            {
                return;
            }

            if (_model.ColorMapping != null)
            {
                effect.CBPerModel.Values.ColorMapping = _model.ColorMapping.BlockColors;
                effect.CBPerModel.IsDirty             = true;
            }

            effect.Apply(context);

            DrawInstanced(context, instances);
        }
        public void VoxelDraw(DeviceContext context, Matrix viewProjection)
        {
            //Applying Correct Render States
            RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Disabled, DXStates.DepthStencils.DepthReadWriteEnabled);
            _voxelModelEffect.Begin(context);
            _voxelModelEffect.CBPerFrame.Values.SunVector      = _skyDome.LightDirection;
            _voxelModelEffect.CBPerFrame.Values.ViewProjection = Matrix.Transpose(viewProjection);
            _voxelModelEffect.CBPerFrame.IsDirty = true;
            _voxelModelEffect.Apply(context);

            //Draw each buffered Models =====================================
            foreach (var modelAndInstances in _models)
            {
                //For each instance of the model that have received a body
                foreach (var pairs in modelAndInstances.Value.Instances.Where(x => x.Value != null))
                {
                    var entityToRender = _dynamicEntitiesDico[pairs.Key];
                    var modelInstance  = pairs.Value;
                    //Draw only the entities that are in Client view range
                    //if (_visualWorldParameters.WorldRange.Contains(entityToRender.VisualEntity.Position.ToCubePosition()))
                    bool isInRenderingRange = MVector3.Distance2D(entityToRender.VoxelEntity.Position, _camManager.ActiveCamera.WorldPosition.ValueInterp) <= _staticEntityViewRange;
                    //Can only see dead persons if your are dead yourself or if its your own body !
                    bool showCharacters = entityToRender.DynamicEntity.HealthState != DynamicEntityHealthState.Dead || IsLocalPlayer(entityToRender.DynamicEntity.DynamicId) || _playerEntityManager.Player.HealthState == DynamicEntityHealthState.Dead;
                    if (isInRenderingRange && showCharacters)
                    {
                        modelInstance.World      = Matrix.Scaling(1f / 16) * Matrix.Translation(entityToRender.WorldPosition.ValueInterp.AsVector3());
                        modelInstance.LightColor = entityToRender.ModelLight.ValueInterp;
                    }
                    else
                    {
                        modelInstance.World = Matrix.Zero;
                    }
                }

                if (modelAndInstances.Value.VisualModel != null && modelAndInstances.Value.Instances != null)
                {
                    var instancesToDraw = modelAndInstances.Value.Instances.Values.Where(x => x.World != Matrix.Zero).ToList(); //Draw only those where the matrix is different than Zero
                    modelAndInstances.Value.VisualModel.DrawInstanced(_d3DEngine.ImmediateContext, _voxelModelEffect, instancesToDraw);
                }
            }

            _voxelToolEffect.Begin(context);
            _voxelToolEffect.CBPerFrame.Values.LightDirection = _skyDome.LightDirection;
            _voxelToolEffect.CBPerFrame.Values.ViewProjection = Matrix.Transpose(viewProjection);
            _voxelToolEffect.CBPerFrame.IsDirty = true;
            _voxelToolEffect.Apply(context);

            // draw tools ================
            foreach (var pair in _dynamicEntitiesDico)
            {
                var charEntity = pair.Value.DynamicEntity as CharacterEntity;
                if (charEntity != null && pair.Value.ModelInstance != null && pair.Value.ModelInstance.World != Matrix.Zero)
                {
                    //Take the Tool entity equiped in character Right hand
                    if (charEntity.Equipment.RightTool is CubeResource)
                    {
                        DrawCube(context, (CubeResource)charEntity.Equipment.RightTool, charEntity);
                    }
                    else if (charEntity.Equipment.RightTool is IVoxelEntity)
                    {
                        var voxelItem = charEntity.Equipment.RightTool as IVoxelEntity;
                        if (!string.IsNullOrEmpty(voxelItem.ModelName)) //Check if a voxel model is associated with the entity
                        {
                            DrawTool(voxelItem, charEntity);
                        }
                    }
                }
            }
        }