public static string GetPreviewFileName(MyPrefabConfiguration config, MyMwcObjectBuilder_Prefab_TypesEnum enumValue)
        {
            if (config.BuildType == BuildTypesEnum.MODULES && config.CategoryType == CategoryTypesEnum.WEAPONRY)
            {
                MyModelsEnum baseModelEnum, barelModelEnum;
                if (MyLargeShipGunBase.GetModelEnums(enumValue, out baseModelEnum, out barelModelEnum))
                {
                    return(Path.GetFileName(MyModels.GetModelAssetName(baseModelEnum)));
                }
            }

            return(Path.GetFileName(MyModels.GetModelAssetName(config.ModelLod0Enum)));
        }
        /// <summary>
        /// IMPORTANT: using Lod1Normals here, since this is done in a separate time to normal rendering
        /// </summary>
        public RenderTarget2D RenderPreview(MyMwcObjectBuilder_Prefab_TypesEnum enumValue, MyPrefabConfiguration config, int width, int height)
        {
            m_fullSizeRT = MyRender.GetRenderTarget(MyRenderTargets.Lod1Normals);

            if (m_fullSizeRT == null || MyGuiScreenGamePlay.Static == null)
            {
                return(null);
            }

            m_setup.RenderTargets[0] = new RenderTargetBinding(m_fullSizeRT);

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.Visible = false;
            }

            GraphicsDevice device = MyMinerGame.Static.GraphicsDevice;

            RenderTarget2D renderTarget = new RenderTarget2D(device, width, height, true, SurfaceFormat.Color, DepthFormat.Depth24, 0, RenderTargetUsage.DiscardContents);

            m_setup.RenderElementsToDraw.Clear();
            m_setup.TransparentRenderElementsToDraw.Clear();

            // make actual viewport one pixel larger in order to remove the deformed border caused by antialiasing
            m_setup.Viewport    = new Viewport(0, 0, 2 * renderTarget.Width, 2 * renderTarget.Height);
            m_setup.AspectRatio = 1;
            m_setup.Fov         = MathHelper.ToRadians(70);

            MyRender.Sun.Direction = new Vector3(.5f, -.3f, -1);
            MyRender.Sun.Direction.Normalize();
            MyRender.Sun.Color = Vector4.One;
            MyRender.EnableSun = true;
            float previousSunIntensityMultiplier = MyRender.SunIntensityMultiplier;

            MyRender.SunIntensityMultiplier = 1.2f;

            if (config.BuildType == BuildTypesEnum.MODULES && config.CategoryType == CategoryTypesEnum.WEAPONRY)
            {
                MyModel baseModel    = null;
                MyModel barrelModel  = null;
                Matrix  baseMatrix   = Matrix.Identity;
                Matrix  barrelMatrix = Matrix.Identity;

                bool result = MyLargeShipGunBase.GetVisualPreviewData(enumValue, ref baseModel, ref barrelModel, ref baseMatrix, ref barrelMatrix);

                if (result)
                {
                    m_setup.ViewMatrix = Matrix.Identity;

                    setupRenderElement(baseModel, baseMatrix);
                    setupRenderElement(barrelModel, barrelMatrix);

                    setupLights(baseModel);

                    MyRender.PushRenderSetup(m_setup);
                    MyRender.Draw();
                    MyRender.PopRenderSetup();

                    BlitToThumbnail(device, renderTarget);
                }
            }
            else
            {
                //load new model from prefab config
                MyModel model = MyModels.GetModelForDraw(config.ModelLod0Enum);

                float distance = 1.85f;

                Matrix viewMatrix = Matrix.Identity;
                m_setup.ViewMatrix = viewMatrix;

                //generate world matrix
                Matrix worldMatrix = Matrix.Identity;
                worldMatrix.Translation  = -model.BoundingSphere.Center;
                worldMatrix             *= Matrix.CreateRotationY(-.85f * MathHelper.PiOver4);
                worldMatrix             *= Matrix.CreateRotationX(.35f * MathHelper.PiOver4);
                worldMatrix.Translation += new Vector3(0, 0, -model.BoundingSphere.Radius * distance);

                setupRenderElement(model, worldMatrix);

                setupLights(model);

                MyRender.PushRenderSetup(m_setup);
                MyRender.Draw();
                MyRender.PopRenderSetup();

                BlitToThumbnail(device, renderTarget);
            }

            MyRender.SunIntensityMultiplier = previousSunIntensityMultiplier;

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.Visible = true;
            }

            return(renderTarget);
        }
 public MyMwcObjectBuilder_Prefab(MyMwcObjectBuilder_Prefab_TypesEnum prefabType, MyMwcObjectBuilder_Prefab_AppearanceEnum appearance,
     MyMwcVector3Short position, Vector3 anglesInContainer, float? prefabMaxHealth, float prefabHealthRatio, string displayName, float electricCapacity, bool? causesAlarm, int aiPriority)
     : base((int)prefabType, appearance, position, anglesInContainer, prefabMaxHealth, prefabHealthRatio, displayName, electricCapacity, causesAlarm, aiPriority)
 {
 }
Exemple #4
0
 public MyMwcObjectBuilder_Prefab(MyMwcObjectBuilder_Prefab_TypesEnum prefabType, MyMwcObjectBuilder_Prefab_AppearanceEnum appearance,
                                  MyMwcVector3Short position, Vector3 anglesInContainer, float?prefabMaxHealth, float prefabHealthRatio, string displayName, float electricCapacity, bool?causesAlarm, int aiPriority)
     : base((int)prefabType, appearance, position, anglesInContainer, prefabMaxHealth, prefabHealthRatio, displayName, electricCapacity, causesAlarm, aiPriority)
 {
 }
 public static void WriteObjectBuilderPrefabTypesEnum(MyMwcObjectBuilder_Prefab_TypesEnum val, BinaryWriter binaryWriter)
 {
     binaryWriter.Write((ushort)val);
 }