Ejemplo n.º 1
0
        private void DrawTool(IVoxelEntity voxelTool, CharacterEntity charEntity)
        {
            if (charEntity.ModelInstance == null)
            {
                return;
            }

            // get the model and instance
            KeyValuePair <VisualVoxelModel, VoxelModelInstance> mPair;

            if (!_toolsModels.TryGetValue(voxelTool.ModelName, out mPair))
            {
                var model = _voxelModelManager.GetModel(voxelTool.ModelName, false);
                mPair = new KeyValuePair <VisualVoxelModel, VoxelModelInstance>(model, model.VoxelModel.CreateInstance());
                mPair.Value.SetState(model.VoxelModel.GetMainState());
                _toolsModels.Add(voxelTool.ModelName, mPair);
            }

            var instance = mPair.Value;

            var   voxelBB = instance.State.BoundingBox.GetSize();
            float scale   = MathHelper.Min(1.0f, 32 / MathHelper.Max(MathHelper.Max(voxelBB.X, voxelBB.Y), voxelBB.Z));

            scale *= 0.70f;

            // setup the tool instance
            instance.World      = Matrix.Scaling(scale) * charEntity.ModelInstance.GetToolTransform();
            instance.LightColor = charEntity.ModelInstance.LightColor;

            // draw it
            mPair.Key.Draw(_d3DEngine.ImmediateContext, _voxelToolEffect, instance);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a VisualVoxelEntity ready to render
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="wrapped">wrapped VoxelEntity from server</param>
        public VisualVoxelEntity(IVoxelEntity wrapped, VoxelModelManager manager)
            : base(wrapped.DefaultSize, wrapped)
        {
            _voxelEntity = wrapped;
            _manager     = manager;

            //Create the world position of the Voxel Entity, based on its initial position

            if (wrapped.ModelInstance == null)
            {
                return;
            }

            var model = manager.GetModel(wrapped.ModelName);

            // set the model or wait for it
            if (model == null)
            {
                _manager.VoxelModelAvailable += ManagerVoxelModelReceived;
            }
            else
            {
                _visualVoxelModel = model;

                BoundingBox voxelModelBB;
                if (Entity is IOrientedSlope)
                {
                    //Use a forced boundingbox for the slope to work properly, this will be a 16*16*16 BB
                    voxelModelBB = new BoundingBox(new Vector3(-8, 0, -8), new Vector3(8, 16, 8));
                }
                else
                {
                    //Use the computed Bounding box from the model
                    voxelModelBB = _voxelEntity.ModelInstance.State.BoundingBox;
                }

                var scaleFactor = GetModelScale(wrapped);

                LocalBBox = new BoundingBox(voxelModelBB.Minimum * scaleFactor, voxelModelBB.Maximum * scaleFactor);

                //Add instance rotation, if existing
                if (Entity is IStaticEntity)
                {
                    LocalBBox = LocalBBox.Transform(Matrix.RotationQuaternion(((IStaticEntity)Entity).Rotation));
                }

                ComputeWorldBoundingBox(Entity.Position, out WorldBBox);
            }
        }