private void ModelLoaded(String name, PositionedModel model) { if (this.InvokeRequired) { ModelLoadedCallback d = new ModelLoadedCallback(ModelLoaded); this.Invoke(d, new object[] { name, model }); } else { // Add the new model if (mModelDictionary.ContainsKey(name)) { mModelDictionary[name] = model; } else { mModelDictionary.Add(name, model); } // Repopulate the model list, and select the newest addition modelSelectionBox.Items.Clear(); foreach (String key in mModelDictionary.Keys) { modelSelectionBox.Items.Add(key); } // Add "Load Model..." item modelSelectionBox.Items.Add("Load Model..."); modelSelectionBox.SelectedIndex = modelSelectionBox.Items.IndexOf(name); } }
private void UpdateObjectOverMarker() { SECursor cursor = GameData.Cursor; float polygonScaleX = (float)mObjectOverMarker.Points[0].X; float polygonScaleY = (float)mObjectOverMarker.Points[0].Y; mModelOverHighlight.Visible = false; if (cursor.SpritesOver.Count != 0) { mObjectOverMarker.Visible = true; mObjectOverMarker.Position = cursor.SpritesOver[0].Position; mObjectOverMarker.RotationMatrix = cursor.SpritesOver[0].RotationMatrix; mObjectOverMarker.ScaleBy(cursor.SpritesOver[0].ScaleX / polygonScaleX, cursor.SpritesOver[0].ScaleY / polygonScaleY); } else if (cursor.SpriteFramesOver.Count != 0) { mObjectOverMarker.Visible = true; mObjectOverMarker.Position = cursor.SpriteFramesOver[0].Position; mObjectOverMarker.RotationMatrix = cursor.SpriteFramesOver[0].RotationMatrix; mObjectOverMarker.ScaleBy(cursor.SpriteFramesOver[0].ScaleX / polygonScaleX, cursor.SpriteFramesOver[0].ScaleY / polygonScaleY); } else if (cursor.PositionedModelsOver.Count != 0) { PositionedModel modelOver = cursor.PositionedModelsOver[0]; mModelOverHighlight.Visible = true; mModelOverHighlight.SetDataFrom(modelOver); mModelOverHighlight.Position = modelOver.Position; mModelOverHighlight.RotationMatrix = modelOver.RotationMatrix; mModelOverHighlight.ScaleX = modelOver.ScaleX; mModelOverHighlight.ScaleY = modelOver.ScaleY; mModelOverHighlight.ScaleZ = modelOver.ScaleZ; } else if (cursor.TextsOver.Count != 0) { mObjectOverMarker.Visible = true; mObjectOverMarker.Position = cursor.TextsOver[0].Position; mObjectOverMarker.Position.X = cursor.TextsOver[0].HorizontalCenter; mObjectOverMarker.Position.Y = cursor.TextsOver[0].VerticalCenter; mObjectOverMarker.RotationMatrix = cursor.TextsOver[0].RotationMatrix; mObjectOverMarker.ScaleBy(cursor.TextsOver[0].ScaleX / polygonScaleX, cursor.TextsOver[0].ScaleY / polygonScaleY); } else { mObjectOverMarker.Visible = false; } }
public StateEditor(int Row, int Column) : base(StateID.Editor) { //Draw Cursor m_VisibleCursor = true; //Set Values BoardRow = Row; BoardColumn = Column; SelectedHeight = 1; SelectedWidth = 1; //Nulling Stuffs m_Data = null; m_Buttons = null; m_MenuButtons = null; m_Sky = null; m_SkyLayer = null; m_Arrow = null; m_Ships = null; m_Board = null; m_SideBar = null; m_SideBarPanel = null; m_Window = null; m_Help = null; }
/// <summary> /// Loads all models currently queued for loading /// </summary> #endregion public void LoadModels() { // loop until disposing while (!Disposing && !IsDisposed) { while (mModelsToLoad.Count > 0) { // Load the next model string modelToLoad = mModelsToLoad.Dequeue(); SetStatus("Loading \"" + System.IO.Path.GetFileName(modelToLoad) + "\"..."); // Load the model from disk Model xnaModel = FlatRedBallServices.LoadModelFromFile( modelToLoad, "Global"); // When loaded, add to model manager PositionedModel model = ModelManager.AddModel(xnaModel); // Report the successful load string modelName = System.IO.Path.GetFileNameWithoutExtension(modelToLoad); ModelLoaded(modelName, model); SetStatus(String.Empty); } } }
private void modelSelectionBox_SelectedIndexChanged(object sender, EventArgs e) { foreach (PositionedModel model in mModelDictionary.Values) { model.Visible = false; } String selectedName = (string)modelSelectionBox.Items[modelSelectionBox.SelectedIndex]; // Check if the value is "Load Model..." if (selectedName == "Load Model...") { if (openModelFileDialog.ShowDialog() == DialogResult.OK) { foreach (String file in openModelFileDialog.FileNames) { modelViewPanel.AddModel(file); } } } else { // Set visible, and set effect properties PositionedModel selectedModel = mModelDictionary[selectedName]; selectedModel.Visible = true; modelViewPanel.CurrentModel = selectedModel; SelectModel(selectedModel); } }
public void CopyCurrentObjects() { // for now ignore attachments - just copy whatever's selected. foreach (Sprite sprite in mCurrentSprites) { Sprite newSprite = sprite.Clone(); StringFunctions.MakeNameUnique <Sprite>(newSprite, EditorData.BlockingScene.Sprites); EditorData.BlockingScene.Sprites.Add(newSprite); SpriteManager.AddSprite(newSprite); } foreach (SpriteFrame spriteFrame in mCurrentSpriteFrames) { SpriteFrame newSpriteFrame = spriteFrame.Clone(); StringFunctions.MakeNameUnique <SpriteFrame>(newSpriteFrame, EditorData.BlockingScene.SpriteFrames); EditorData.BlockingScene.SpriteFrames.Add(newSpriteFrame); SpriteManager.AddSpriteFrame(newSpriteFrame); } foreach (PositionedModel positionedModel in mCurrentPositionedModels) { PositionedModel newPositionedModel = positionedModel.Clone(EditorData.ContentManagerName); StringFunctions.MakeNameUnique <PositionedModel>(newPositionedModel, EditorData.BlockingScene.PositionedModels); EditorData.BlockingScene.PositionedModels.Add(newPositionedModel); ModelManager.AddModel(newPositionedModel); } foreach (Text text in mCurrentTexts) { Text newText = text.Clone(); StringFunctions.MakeNameUnique <Text>(newText, EditorData.BlockingScene.Texts); EditorData.BlockingScene.Texts.Add(newText); TextManager.AddText(newText); } }
public static void DeleteModel(PositionedModel positionedModel) { if (mEditorLogic.CurrentPositionedModels.Contains(positionedModel)) { DeselectObject(positionedModel); } ModelManager.RemoveModel(positionedModel); }
/// <summary> /// Create goal arrow. /// </summary> private void CreateArrow() { //Create arrow model m_Arrow = ModelManager.AddModel(Global.MODEL_FOLDER + "Arrow", FlatRedBallServices.GlobalContentManager, true); m_Arrow.CurrentAnimation = "Default"; ModelManager.AddToLayer(m_Arrow, m_Layer); //Move arrow to goal m_Arrow.X = (Global.GAMETILE_WIDTH + (Global.GAMEGAP_WIDTH * 2)) * (m_Data.Goal + 1.0f); m_Arrow.Y = -50.0f; m_Arrow.Z = 0.0f; }
/// <summary> /// Class constructor. /// </summary> protected Playable(Layer layer) { //Set layer m_Layer = layer; //Empties variables m_Model = null; //Initialize variables CalculateAABB(); m_Active = false; m_Camera = new Camera(FlatRedBallServices.GlobalContentManager); }
public static PositionedModel CopyModelHierarchy(PositionedModel modelToCopy, PositionedModel parentModel, float pixelSize) { // Create the new Sprite by cloning the spriteToCopy PositionedModel newModel = modelToCopy.Clone( ); // Add the new SpriteFrame to the SpriteManager ModelManager.AddModel(newModel); // Fix its name newModel.Name = GetUniqueNameForObject <SpriteFrame>(modelToCopy.Name, null); Scene.PositionedModels.Add(newModel); return(newModel); }
/// <summary> /// Initialize the entity by loading and placing its model. /// </summary> /// <param name="model">Path to the entity's model.</param> /// <param name="animated">Is the model animated?</param> /// <param name="x">Entity's model's X position</param> /// <param name="y">Entity's model's Y position</param> /// <param name="z">Entity's model's Z position</param> public virtual void Initialize(string model, bool animated, float x, float y, float z) { //Create and add model to layer m_Model = ModelManager.AddModel( Global.MODEL_FOLDER + model, FlatRedBallServices.GlobalContentManager, animated); ModelManager.AddToLayer(m_Model, m_Layer); //Calculate model's bounding box CalculateAABB(); //Place the model in position m_Model.X = x; m_Model.Y = y; m_Model.Z = z; }
public static void RecordInstructions(InstructionList listToRecordTo, double timeToExecute, List<string> membersToIgnore, PositionedModel modelToRecord) { foreach (string member in EditorData.CurrentPositionedModelMembersWatching) { if (membersToIgnore.Contains(member) == false) { Type memberType = InstructionManager.GetTypeForMember(mPositionedModelType, member); Type genericType = typeof(Instruction<,>).MakeGenericType( mPositionedModelType, memberType); object value = FlatRedBall.Instructions.Reflection.LateBinder<PositionedModel>.Instance[modelToRecord, member]; Instruction instruction = Activator.CreateInstance(genericType, modelToRecord, member, value, timeToExecute) as Instruction; listToRecordTo.Add(instruction); } } }
public static void RecordInstructions(InstructionList listToRecordTo, double timeToExecute, List <string> membersToIgnore, PositionedModel modelToRecord) { foreach (string member in EditorData.CurrentPositionedModelMembersWatching) { if (membersToIgnore.Contains(member) == false) { Type memberType = InstructionManager.GetTypeForMember(mPositionedModelType, member); Type genericType = typeof(Instruction <,>).MakeGenericType( mPositionedModelType, memberType); object value = FlatRedBall.Instructions.Reflection.LateBinder <PositionedModel> .Instance[modelToRecord, member]; Instruction instruction = Activator.CreateInstance(genericType, modelToRecord, member, value, timeToExecute) as Instruction; listToRecordTo.Add(instruction); } } }
void SelectModel(PositionedModel selectingmodel) { #region Store and set the model // store the current model mCurrentModel = selectingmodel; mModelEditor = new ModelEditor(mCurrentModel); modelPropGrid.SelectedObject = mModelEditor; // Set the model foreach (PositionedModel model in mModelDictionary.Values) { model.Visible = (model == mCurrentModel); } modelViewControl1.CurrentModel = mCurrentModel; #endregion #region Create the material mMaterial = new MaterialEditor(mCurrentModel.XnaModel); InitializeAssets(); #endregion #region Mesh part selection meshPartBox.Items.Clear(); for (int i = 0; i < mMaterial.PartCount; i++) { meshPartBox.Items.Add(i); } meshPartBox.SelectedIndex = 0; #endregion }
private void ModelLoaded(String name, PositionedModel model) { if (this.InvokeRequired) { ModelLoadedCallback d = new ModelLoadedCallback(ModelLoaded); this.Invoke(d, new object[] { name, model }); } else { // Add the new model if (mModelDictionary.ContainsKey(name)) { mModelDictionary[name] = model; } else { mModelDictionary.Add(name, model); } SelectModel(model); } }
public static void AddModel(string fileName) { try { PositionedModel model = ModelManager.AddModel(fileName, GameData.SceneContentManager); model.X = SpriteManager.Camera.X; model.Y = SpriteManager.Camera.Y; // If the model is already part of the Model Manager, this call does nothing ModelManager.AddModel(model); model.Name = GetUniqueNameForObject <PositionedModel> (model.Name, model); Scene.PositionedModels.Add(model); } catch (Exception e) { GuiManager.ShowMessageBox("Error loading model:\n\n" + e.ToString(), "Error"); } //model.GetVerts(0); }
public void CopyCurrentObjects(Window callingWindow) { if ((GameData.EditorLogic.CurrentSprites.Count != 0) || (GameData.EditorLogic.CurrentSpriteFrames.Count != 0) || (GameData.EditorLogic.CurrentPositionedModels.Count != 0) || (GameData.EditorLogic.CurrentTexts.Count != 0)) { int instructionNum = 0; #region Copy Sprites if (SpriteEditorSettings.EditingSprites) { // remove the in-screen markers and axes so they don't get touched by the copying GameData.EditorLogic.EditAxes.CurrentObject = null; Sprite topSpriteAdded = null; AttachableList <Sprite> oldestParents = AttachableList <Sprite> .GetTopParents <Sprite, Sprite>(GameData.EditorLogic.CurrentSprites); SpriteList addedSprites = new SpriteList(); // The appendedNumbers variable is used for improving performance when copying large groups. When a Sprite // is copied, it is given a number at the end of its name or if there is already a number present, // it is incremented. However, copying large groups can result in a lot of string checking which // can hurt performance. // Consider copying 100 Sprites with the same texture. Their names will likely be redball1, redball2, // redball3, ... redball100. Let's say redball1 gets copied first. The SpriteEditor increments the // number at the end to redball2, then checks to see if there is already a Sprite with that name. If // there is, it increments to redball3 and so on. This must be conducted on average 10,000 times and each // iteration requires string copying, concatenation, and parsing for integers. To cut this down, the // appendedNumbers variable associates a given name (in this case redball) with the last integer appended // to that particular name. Therefore, when the first Sprite is created, it will loop through 1 - 100 and // eventually end up at redball101. It will then associate the number 101 with the name redball. The next // Sprite (named redball2) will know to begin at redball101. This increases the performance of // copying large groups from O(n^2) to O(n). Dictionary <string, int> appendedNumbers = new Dictionary <string, int>(); foreach (Sprite s in oldestParents) { if (s is ISpriteEditorObject) { if (GuiData.ToolsWindow.groupHierarchyControlButton.IsPressed) { topSpriteAdded = GameData.copySpriteHierarchy( s, s.Parent as Sprite, GameData.EditorProperties.PixelSize, addedSprites, appendedNumbers); } else { topSpriteAdded = GameData.copySpriteHierarchy( s.TopParent as Sprite, null, GameData.EditorProperties.PixelSize, addedSprites, appendedNumbers); } } SpriteList tempSpriteArray = new SpriteList(); topSpriteAdded.GetAllDescendantsOneWay(tempSpriteArray); tempSpriteArray.Add(topSpriteAdded); } GameData.EditorLogic.EditAxes.CurrentObject = GameData.EditorLogic.CurrentSprites[0]; GameData.Cursor.ClickSprite(null); foreach (Sprite s in AttachableList <Sprite> .GetTopParents <Sprite, Sprite>(addedSprites)) { // the 2nd true forces selection of all Sprites GameData.Cursor.ClickObject <Sprite>(s, GameData.EditorLogic.CurrentSprites, true, true); } GameData.Cursor.VerifyAndUpdateGrabbedAgainstCurrent(); } #endregion #region Copy SpriteGrids else if (SpriteEditorSettings.EditingSpriteGrids) { SpriteGrid sg = SESpriteGridManager.CurrentSpriteGrid.Clone(); FlatRedBall.Utilities.StringFunctions.MakeNameUnique <SpriteGrid>(sg, GameData.Scene.SpriteGrids); this.sesgMan.PopulateAndAddGridToEngine(sg, GameData.EditorLogic.CurrentSprites[0]); sg.RefreshPaint(); } #endregion #region Copy SpriteFrames else if (SpriteEditorSettings.EditingSpriteFrames) { GameData.EditorLogic.EditAxes.CurrentObject = null; AttachableList <SpriteFrame> oldestParents = AttachableList <SpriteFrame> .GetTopParents <SpriteFrame, SpriteFrame>(GameData.EditorLogic.CurrentSpriteFrames); foreach (SpriteFrame sf in oldestParents) { SpriteFrame topSpriteFrameAdded = GameData.CopySpriteFrameHierarchy(sf, null, GameData.EditorProperties.PixelSize); GameData.Cursor.ClickSpriteFrame(topSpriteFrameAdded); } } #endregion #region Copy Models else if (SpriteEditorSettings.EditingModels) { GameData.EditorLogic.EditAxes.CurrentObject = null; AttachableList <PositionedModel> oldestParents = AttachableList <PositionedModel> .GetTopParents <PositionedModel, PositionedModel>(GameData.EditorLogic.CurrentPositionedModels); foreach (PositionedModel model in oldestParents) { PositionedModel topSpriteFrameAdded = GameData.CopyModelHierarchy(model, null, GameData.EditorProperties.PixelSize); // GameData.cursor.ClickSpriteFrame(topSpriteFrameAdded); } } #endregion #region Copy Texts else if (SpriteEditorSettings.EditingTexts) { GameData.EditorLogic.EditAxes.CurrentObject = null; AttachableList <Text> oldestParents = AttachableList <Text> .GetTopParents <Text, Text>(GameData.EditorLogic.CurrentTexts); foreach (Text text in oldestParents) { Text topText = GameData.CopyTextHierarchy(text, null, GameData.EditorProperties.PixelSize); // GameData.cursor.ClickSpriteFrame(topSpriteFrameAdded); } } #endregion } }
private static void RenderCustomModel(PositionedModel model) { //There are three things that need to happen here // The first one is common to all CustomModels // The second is code that is unique to unskinned CustomModels // The third is code that is unique to skinned CustomModels bool isSkinned = model.CustomModel.IsSkinnedMesh; bool isAnimated = model.AnimationController != null && model.AnimationController.Matrices != null; if (!isSkinned) //unskinned { if (isAnimated) { int matrixCount = model.AnimationController.Matrices.Length; for (int i = 0; i < matrixCount; i++) { transforms[i] = model.AnimationController.Matrices[i].Transform; } } } else //Skinned { if (isAnimated) { model.CustomModel.SetBones(model.AnimationController.Matrices); } else { model.CustomModel.ResetVertexBuffers(); } } FlatRedBall.Content.Model.Helpers.CustomModel customModel = model.CustomModel; int meshCount = customModel.Meshes.Count; FlatRedBall.Content.Model.Helpers.ModelMesh mesh; #if !WINDOWS_PHONE BasicEffect effect; #else GenericEffect effect; #endif if (customModel.SharesEffects) { #if WINDOWS_PHONE effect = customModel.Meshes[0].MeshParts[0].Effect; #else effect = (BasicEffect)customModel.Meshes[0].MeshParts[0].Effect; #endif PrepareEffectForRendering(model, effect); } Matrix transformationMatrixFlippedAsNeeded = model.TransformationMatrix; for (int meshIndex = 0; meshIndex < meshCount; meshIndex++) { mesh = customModel.Meshes[meshIndex]; if (!isSkinned && isAnimated && mesh.BoneIndex == -1) { int boneCount = model.AnimationController.Matrices.Length; for (int boneIndex = 0; boneIndex < boneCount; boneIndex++) { FlatRedBall.Graphics.Animation3D.Animation3DJoint boneInfo = model.AnimationController.Matrices[boneIndex]; if (mesh.Name == boneInfo.Name) { mesh.BoneIndex = boneIndex; } } } #if !WINDOWS_PHONE && XNA4 //foreach(ModelMeshPart meshPart in mesh.MeshParts) for(int partIndex = 0; partIndex < mesh.MeshParts.Count; partIndex++) { effect = mesh.MeshParts[partIndex].Effect as BasicEffect; #else for (int effectIndex = 0; effectIndex < mesh.Effects.Count; effectIndex++) { #if !WINDOWS_PHONE || !XNA4 effect = (BasicEffect)mesh.Effects[effectIndex]; #else effect = mesh.Effects[effectIndex]; #endif #endif if (!customModel.SharesEffects) { PrepareEffectForRendering(model, effect); } if (!isSkinned && isAnimated && mesh.BoneIndex != -1) { effect.World = transforms[mesh.BoneIndex]; effect.World *= transformationMatrixFlippedAsNeeded; } else effect.World = transformationMatrixFlippedAsNeeded; } mesh.Draw(model.RenderOverrides); } #if false //Copy bone matrices. bool hasBones = model.CustomModel.Bones != null; Matrix[] transforms = null; if (model.AnimationController != null && model.AnimationController.Matrices != null) { model.CustomModel.SetBones(model.AnimationController.Matrices); } else { model.CustomModel.ResetVertexBuffers(); } #if XNA4 if (hasBones) { transforms = new Matrix[model.CustomModel.Bones.Count]; //model.CustomModel.CopyAbsoluteBoneTransformsTo(transforms); for (int i = 0; i < model.CustomModel.Bones.Count; i++) { transforms[i] = model.AnimationController.Matrices[i].Transform; } } FlatRedBallServices.GraphicsDevice.DepthStencilState = DepthStencilState.Default; #endif FlatRedBall.Content.Model.Helpers.CustomModel customModel = model.CustomModel; int meshCount = customModel.Meshes.Count; FlatRedBall.Content.Model.Helpers.ModelMesh mesh; BasicEffect effect; for(int meshIndex = 0; meshIndex < meshCount; meshIndex++) { mesh = customModel.Meshes[meshIndex]; for(int effectIndex = 0; effectIndex < mesh.Effects.Count; effectIndex++) { effect = (BasicEffect)mesh.Effects[effectIndex]; if (AvailableLights != null && AvailableLights.Count > 0) { effect.EnableDefaultLighting(); //Start by turning off all the lights. effect.DirectionalLight0.Enabled = effect.DirectionalLight1.Enabled = effect.DirectionalLight2.Enabled = false; //This tracks which directional light in the shader we are working with. int effectLightIndex = 0; //Loop through all lights for (int i = 0; i < AvailableLights.Count; i++) { LightBase baseLight = AvailableLights[i]; if (baseLight.Enabled) { if (baseLight is AmbientLight) { SetAmbientLight(effect, baseLight); } else { #if XNA4 Microsoft.Xna.Framework.Graphics.DirectionalLight directionalLight; if (effectLightIndex == 0) directionalLight = effect.DirectionalLight0; else if (effectLightIndex == 1) directionalLight = effect.DirectionalLight1; else directionalLight = effect.DirectionalLight2; SetDirectionalLight(directionalLight, baseLight, model.Position); effectLightIndex++; #endif } } } } else { effect.EnableDefaultLighting(); effect.DirectionalLight0.Enabled = effect.DirectionalLight1.Enabled = effect.DirectionalLight2.Enabled = false; effect.AmbientLightColor = Vector3.Zero; } // Set this to false and all is fixed magically! effect.VertexColorEnabled = false; ApplyColorOperation(model, effect); effect.World = model.TransformationMatrix; if (hasBones && mesh.ParentBone != null) { effect.World *= transforms[mesh.ParentBone.Index]; } SpriteManager.Camera.SetDeviceViewAndProjection(effect, false); } mesh.Draw(model.RenderOverrides); } #endif }
private static void SetCullStateForModel(PositionedModel model, bool flipped) { switch (model.FaceCullMode) { case ModelFaceCullMode.CullClockwiseFace: if (!flipped) Renderer.GraphicsDevice.RasterizerState = RasterizerState.CullClockwise; else Renderer.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; break; case ModelFaceCullMode.CullCounterClockwiseFace: if (!flipped) Renderer.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; else Renderer.GraphicsDevice.RasterizerState = RasterizerState.CullClockwise; break; case ModelFaceCullMode.None: Renderer.GraphicsDevice.RasterizerState = RasterizerState.CullNone; break; } }
static void UpdateSelectionUI() { #region Handle Text, Sprite, and SpriteFrame selection #region Get the number of objects needed int numberOfRectangles = GameData.EditorLogic.CurrentSprites.Count + GameData.EditorLogic.CurrentSpriteFrames.Count;// + //GameData.EditorLogic.CurrentTexts.Count; #endregion #region Create and destroy to get the number needed while (numberOfRectangles < mCurrentSelectionRectangles.Count) { mCurrentSelectionRectangles[0].Destroy(); } while (numberOfRectangles > mCurrentSelectionRectangles.Count) { mCurrentSelectionRectangles.Add(new ScalableSelector()); } #endregion int currentIndex = 0; foreach (Sprite sprite in GameData.EditorLogic.CurrentSprites) { mCurrentSelectionRectangles[currentIndex].UpdateToObject(sprite, SpriteManager.Camera); currentIndex++; } foreach (SpriteFrame spriteFrame in GameData.EditorLogic.CurrentSpriteFrames) { mCurrentSelectionRectangles[currentIndex].UpdateToObject(spriteFrame, SpriteManager.Camera); currentIndex++; } //foreach (Text text in GameData.EditorLogic.CurrentTexts) //{ // mCurrentSelectionRectangles[currentIndex].UpdateToObject(text, SpriteManager.Camera); // currentIndex++; //} #endregion #region Handle PositionedModel selection mSelectedModelHighlight.Visible = GameData.EditorLogic.CurrentPositionedModels.Count > 0; if (mSelectedModelHighlight.Visible) { PositionedModel selectedModel = GameData.EditorLogic.CurrentPositionedModels[0]; mSelectedModelHighlight.SetDataFrom(selectedModel); mSelectedModelHighlight.Position = selectedModel.Position; mSelectedModelHighlight.RotationMatrix = selectedModel.RotationMatrix; mSelectedModelHighlight.ScaleX = selectedModel.ScaleX; mSelectedModelHighlight.ScaleY = selectedModel.ScaleY; mSelectedModelHighlight.ScaleZ = selectedModel.ScaleZ; } #endregion }
public ModelEditor(PositionedModel model) { ModelEditor.CurrentModel = model; mSelectedModel = model; mCurrentAnimation = String.Empty; }
private void DrawMesh(Camera camera, PositionedModel model, int meshIndex, RenderMode renderMode) { #if XNA4 throw new NotImplementedException(); #else //TimeManager.SumTimeSection("Start of DrawMesh"); ModelMeshXna mesh = model.XnaModel.Meshes[meshIndex]; if (model.CustomEffect != null) { #region Draw using custom effect model.CustomEffect.Effect.Begin(SaveStateMode.None); FlatRedBallServices.GraphicsDevice.Indices = mesh.IndexBuffer; for (int i = 0; i < model.CustomEffect.Effect.CurrentTechnique.Passes.Count; i++) { EffectPass pass = model.CustomEffect.Effect.CurrentTechnique.Passes[i]; pass.Begin(); for (int partIndex = 0; partIndex < mesh.MeshParts.Count; partIndex++) { ModelMeshPartXna part = mesh.MeshParts[partIndex]; // Set parameters //SetPartEffectParameters(model, model.CustomEffect.Effect, meshIndex, part); #region Set the world matrix for the World Effect Parameter // Get parameters EffectParameter worldParameter = model.mEffectCache[model.CustomEffect.Effect, EffectCache.EffectParameterNames[(int)EffectCache.EffectParameterNamesEnum.World]]; if (worldParameter != null) worldParameter.SetValue(model.mBoneWorldTransformations[meshIndex]); #endregion model.CustomEffect.Effect.CommitChanges(); // Just draw the part - the effect has been taken care of already DrawMeshPart(mesh, part); } pass.End(); } model.CustomEffect.Effect.End(); #endregion } else { #region Draw parts with their own effects Effect effect; FlatRedBallServices.GraphicsDevice.Indices = mesh.IndexBuffer; for (int i = 0; i < mesh.MeshParts.Count; i++) { ModelMeshPartXna part = mesh.MeshParts[i]; effect = part.Effect; //TimeManager.SumTimeSection("Start of meshpart loop"); // Check if the effect has the required technique EffectTechnique technique = null;// = model.EffectCache.GetTechnique( //effect, Renderer.EffectTechniqueNames[(int)renderMode]); //if (Renderer.LightingEnabled) //{ // switch (model.LightingMethod) // { // case PositionedModel.LightingType.None: // technique = model.EffectCache.GetTechnique(effect, "Default"); // break; // case PositionedModel.LightingType.Ambient: // technique = model.EffectCache.GetTechnique(effect, "AmbientOnly"); // break; // case PositionedModel.LightingType.Diffuse: // technique = model.EffectCache.GetTechnique(effect, "DiffuseOnly"); // break; // case PositionedModel.LightingType.Specular: // technique = model.EffectCache.GetTechnique(effect, "SpecularOnly"); // break; // case (PositionedModel.LightingType.Ambient | PositionedModel.LightingType.Diffuse): // technique = model.EffectCache.GetTechnique(effect, "AmbientAndDiffuse"); // break; // case (PositionedModel.LightingType.Ambient | PositionedModel.LightingType.Specular): // technique = model.EffectCache.GetTechnique(effect, "AmbientAndSpecular"); // break; // case (PositionedModel.LightingType.Diffuse | PositionedModel.LightingType.Specular): // technique = model.EffectCache.GetTechnique(effect, "DiffuseAndSpecular"); // break; // case PositionedModel.LightingType.All: // technique = model.EffectCache.GetTechnique(effect, "AmbientDiffuseSpecular"); // break; // } //} //else { technique = model.EffectCache.GetTechnique(effect, "Default"); } if (technique == null && renderMode == RenderMode.Default) { technique = model.EffectCache.GetTechnique(effect, "Default");// effect.Techniques[0]; } //TimeManager.SumTimeSection("Get technique"); if (technique != null) { // Set the technique and draw the part effect.CurrentTechnique = technique; if (!model.mHasClonedEffects) { #region Set the world matrix for the World Effect Parameter // Get parameters EffectParameter worldParameter = model.mEffectCache[effect, EffectCache.EffectParameterNames[(int)EffectCache.EffectParameterNamesEnum.World]]; if (worldParameter != null) worldParameter.SetValue(model.mBoneWorldTransformations[meshIndex]); #endregion } /// This code, is the old Drawing code. This is all done in the mesh.Draw() method and is not needed. /// However vic would like to keep this code here, incase something isn't right after release. /// then we can go back and return it to it's original state. #region OldCode //// Pulled this out of the foreach loop since it looks like it only //// has to be done once //FlatRedBallServices.GraphicsDevice.Vertices[0].SetSource( // mesh.VertexBuffer, part.StreamOffset, part.VertexStride); //TimeManager.SumTimeSection("Set effect Parameters"); // Draw the part //effect.Begin(SaveStateMode.None); //for (int passIndex = 0; passIndex < effect.CurrentTechnique.Passes.Count; passIndex++) //{ // EffectPass pass = effect.CurrentTechnique.Passes[passIndex]; // pass.Begin(); // // Contents of DrawMeshPart are below and just outside // // of the foreach for performance reasons. // // DrawMeshPart(mesh, part); // //if (part.NumVertices > 0) // //{ // // FlatRedBallServices.GraphicsDevice.DrawIndexedPrimitives( // // PrimitiveType.TriangleList, // // part.BaseVertex, // // 0, // // part.NumVertices, // // part.StartIndex, // // part.PrimitiveCount); // //} // pass.End(); //} //effect.End(); mesh.Draw(SaveStateMode.None); #endregion //TimeManager.SumTimeSection("DrawMeshPart"); } } #endregion } #endif }
public ModelAnimationControlWindow(PositionedModel model) : base(GuiManager.Cursor) { // Set Window properties HasMoveBar = true; Resizable = true; HasCloseButton = true; // Set scaling ScaleX = 20f; // Add combo boxes mCurrentAnimation = new ComboBox(mCursor); AddWindow(mCurrentAnimation); mBlendAnimation = new ComboBox(mCursor); AddWindow(mBlendAnimation); mCurrentAnimation.ItemClick += new GuiMessage(mCurrentAnimation_ItemClick); mBlendAnimation.ItemClick += new GuiMessage(mBlendAnimation_ItemClick); // Add text mCurrentAnimationText = new TextDisplay(mCursor); AddWindow(mCurrentAnimationText); mBlendAnimationText = new TextDisplay(mCursor); AddWindow(mBlendAnimationText); mCurrentAnimationText.Text = "Current Animation"; mBlendAnimationText.Text = "Blend Animation"; // Blend controller mBlendController = new TimeLine(GuiManager.Cursor); this.AddWindow(mBlendController); mBlendController.ScaleX = 18f; mBlendController.MinimumValue = 0.0; mBlendController.MaximumValue = 1.0; mBlendController.Start = 0.0; mBlendController.ValueWidth = 1.0; mBlendController.VerticalBarIncrement = 0.1; mBlendController.CurrentValue = 0.0; mBlendController.GuiChange += new GuiMessage(mBlendController_onGUIChange); // Animation timings mAnimationTime = new TimeLine(GuiManager.Cursor); this.AddWindow(mAnimationTime); mAnimationTime.ScaleX = 9f; mAnimationTime.VerticalBarIncrement = 0.2; mAnimationTime.SmallVerticalBarIncrement = 0.1; mAnimationTime.ValueWidth = 1; mAnimationTime.GuiChange += new GuiMessage(mAnimationTime_onGUIChange); mBlendTime = new TimeLine(GuiManager.Cursor); this.AddWindow(mBlendTime); mBlendTime.ScaleX = 9f; mBlendTime.VerticalBarIncrement = 0.2; mBlendTime.SmallVerticalBarIncrement = 0.1; mBlendTime.ValueWidth = 1; mBlendTime.GuiChange += new GuiMessage(mBlendTime_onGUIChange); // Animation speeds mAnimationSpeed = new TimeLine(GuiManager.Cursor); this.AddWindow(mAnimationSpeed); mAnimationSpeed.ScaleX = 9f; mAnimationSpeed.MinimumValue = 0.0; mAnimationSpeed.MaximumValue = 2.0; mAnimationSpeed.Start = 0.0; mAnimationSpeed.ValueWidth = 2.0; mAnimationSpeed.VerticalBarIncrement = 0.5; mAnimationSpeed.SmallVerticalBarIncrement = 0.1; mAnimationSpeed.CurrentValue = 1.0; mAnimationSpeed.GuiChange += new GuiMessage(mAnimationSpeed_onGUIChange); mBlendSpeed = new TimeLine(GuiManager.Cursor); this.AddWindow(mBlendSpeed); mBlendSpeed.ScaleX = 9f; mBlendSpeed.MinimumValue = 0.0; mBlendSpeed.MaximumValue = 2.0; mBlendSpeed.Start = 0.0; mBlendSpeed.ValueWidth = 2.0; mBlendSpeed.VerticalBarIncrement = 0.5; mBlendSpeed.SmallVerticalBarIncrement = 0.1; mBlendSpeed.CurrentValue = 1.0; mBlendSpeed.GuiChange += new GuiMessage(mBlendSpeed_onGUIChange); mAnimationStopStart = new Button(GuiManager.Cursor); this.AddWindow(mAnimationStopStart); mAnimationStopStart.ScaleX = 5f; mAnimationStopStart.Text = "Stop"; mAnimationStopStart.Click += new GuiMessage(mAnimationStopStart_Click); // Set scaling mCurrentAnimation.ScaleX = 9f; mBlendAnimation.ScaleX = 9f; mCurrentAnimationText.ScaleY = 1f; // mCurrentAnimation.ScaleY; mCurrentAnimationText.ScaleX = mCurrentAnimation.ScaleX; mBlendAnimationText.ScaleY = 1f; // mBlendAnimation.ScaleY; mBlendAnimationText.ScaleX = mBlendAnimation.ScaleX; ScaleY = mCurrentAnimationText.ScaleY + mCurrentAnimation.ScaleY + 2f * mBlendController.ScaleY + 2f * mAnimationTime.ScaleY + 2f * mAnimationSpeed.ScaleY + 2f * mAnimationStopStart.ScaleY + .5f; ScaleX = (mCurrentAnimation.ScaleX + mBlendAnimation.ScaleX) + 4.5f / 2f; PositionUIElements(); Resizing += new GuiMessage(AnimationEditor_Resizing); // Add model PositionedModel = model; }
private static void PrepareEffectForRendering(PositionedModel model, GenericEffect effect)
private static void ApplyLighting(PositionedModel model, GenericEffect effect) { if (!LightManager.EnableLighting) { effect.LightingEnabled = false; } else if (AvailableLights != null && AvailableLights.Count > 0) { //effect.EnableDefaultLighting(); //Start by turning off all the lights. effect.LightingEnabled = true; effect.DirectionalLight0.Enabled = effect.DirectionalLight1.Enabled = effect.DirectionalLight2.Enabled = false; //This tracks which directional light in the shader we are working with. int effectLightIndex = 0; //Loop through all lights for (int i = 0; i < AvailableLights.Count; i++) { LightBase baseLight = AvailableLights[i]; if (baseLight.Enabled) { if (baseLight is AmbientLight) { SetAmbientLight(effect, baseLight); } else { Microsoft.Xna.Framework.Graphics.DirectionalLight directionalLight; if (effectLightIndex == 0) directionalLight = effect.DirectionalLight0; else if (effectLightIndex == 1) directionalLight = effect.DirectionalLight1; else directionalLight = effect.DirectionalLight2; SetDirectionalLight(directionalLight, baseLight, model.Position); effectLightIndex++; } } } } else { effect.EnableDefaultLighting(); effect.DirectionalLight0.Enabled = effect.DirectionalLight1.Enabled = effect.DirectionalLight2.Enabled = false; effect.AmbientLightColor = Vector3.Zero; } }
public static void SelectModel(PositionedModel modelToSelect) { Cursor.ClickObject <PositionedModel>(modelToSelect, mEditorLogic.CurrentPositionedModels, false); }
private static void PrepareEffectForRendering(PositionedModel model, BasicEffect effect) #endif { ApplyLighting(model, effect); // Set this to false and all is fixed magically! effect.VertexColorEnabled = false; ApplyColorOperation(model, effect); SpriteManager.Camera.SetDeviceViewAndProjection(effect, false); }
private void DrawModel(Camera camera, PositionedModel model, RenderMode renderMode) { #if PROFILE ModelsDrawnThisFrame++; #endif //TimeManager.SumTimeSection("Draw Model Start"); bool flipped = model.FlipX ^ model.FlipY ^ model.FlipZ; #if XNA4 SetCullStateForModel(model, flipped); #else if (model.mDrawWireframe) FlatRedBallServices.GraphicsDevice.RenderState.FillMode = FillMode.WireFrame; switch (model.FaceCullMode) { case ModelFaceCullMode.CullClockwiseFace: if (!flipped) Renderer.GraphicsDevice.RenderState.CullMode = CullMode.CullClockwiseFace; else Renderer.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace; break; case ModelFaceCullMode.CullCounterClockwiseFace: if (!flipped) Renderer.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace; else Renderer.GraphicsDevice.RenderState.CullMode = CullMode.CullClockwiseFace; break; case ModelFaceCullMode.None: Renderer.GraphicsDevice.RenderState.CullMode = CullMode.None; break; } #region Reset device settings if they've changed - They may change in a shader FlatRedBallServices.GraphicsDevice.RenderState.DepthBufferEnable = true; FlatRedBallServices.GraphicsDevice.RenderState.DepthBufferWriteEnable = true; #endregion #endif //TimeManager.SumTimeSection("Set depth states"); #if XNA4 // I don't think we need to worry about vertex declarations #else #region Set Vertex Declaration if (model.XnaModel != null) { if (model.XnaModel.Meshes.Count != 0 && model.XnaModel.Meshes[0].MeshParts.Count != 0) { // The assumption is that each mesh part is using the same vertex declaration for the // whole model. Instead of setting the vertex declaration in the DrawMeshPart method we'll // set it up here to save on the number of method calls on the 360. FlatRedBallServices.GraphicsDevice.VertexDeclaration = model.XnaModel.Meshes[0].MeshParts[0].VertexDeclaration; } } #endregion #endif //TimeManager.SumTimeSection("Set vertex declaration"); #region Set Point Light // Find the closest light //int lightIndex = 0; //float distance; Vector3 meshCenter = (model == null) ? Vector3.Zero : model.Position; #endregion #region Draw Model #if WINDOWS_PHONE if (model.XnaModel != null) { model.XnaModel.CopyAbsoluteBoneTransformsTo(transforms); Matrix transformationMatrixFlippedAsNeeded = model.TransformationMatrix; foreach (ModelMeshXna mesh in model.XnaModel.Meshes) { for( int iCurEffect = 0; iCurEffect < mesh.Effects.Count; ++iCurEffect ) { GenericEffect effect = new GenericEffect( mesh.Effects[ iCurEffect ] ); ApplyColorOperation(model, effect); effect.EnableDefaultLighting(); // Set this to false and all is fixed magically! effect.VertexColorEnabled = false; SpriteManager.Camera.SetDeviceViewAndProjection(effect, false); // World can be used to set the mesh's transform effect.World = transforms[mesh.ParentBone.Index] * transformationMatrixFlippedAsNeeded; } mesh.Draw(); } } else if (model.CustomModel != null) { RenderCustomModel(model); } #else #region If using Custom Effect if (model.CustomEffect != null) { // Set technique here if using custom effect model.CustomEffect.SetParameterValues(); EffectTechnique technique = model.EffectCache.GetTechnique( model.CustomEffect.Effect, Renderer.EffectTechniqueNames[(int)renderMode]); if (technique == null && renderMode == RenderMode.Default) { technique = model.CustomEffect.Effect.Techniques[0]; } if (technique != null) { // Draw meshes only if custom effect has the required technique model.CustomEffect.Effect.CurrentTechnique = technique; DrawModelMeshes(camera, model, renderMode); } } #endregion else if (model.CustomModel != null) { RenderCustomModel(model); } else { // Just draw the meshes DrawModelMeshes(camera, model, renderMode); } #endif #endregion //TimeManager.SumTimeSection("DrawModelMeshes"); if (model.mDrawWireframe) { #if XNA4 throw new NotImplementedException(); #else FlatRedBallServices.GraphicsDevice.RenderState.FillMode = FillMode.Solid; #endif } }
public ModelAnimationControlWindow(PositionedModel model) : base(GuiManager.Cursor) { // Set Window properties HasMoveBar = true; Resizable = true; HasCloseButton = true; // Set scaling ScaleX = 20f; // Add combo boxes mCurrentAnimation = new ComboBox(mCursor); AddWindow(mCurrentAnimation); mBlendAnimation = new ComboBox(mCursor); AddWindow(mBlendAnimation); mCurrentAnimation.ItemClick += new GuiMessage(mCurrentAnimation_ItemClick); mBlendAnimation.ItemClick += new GuiMessage(mBlendAnimation_ItemClick); // Add text mCurrentAnimationText = new TextDisplay(mCursor); AddWindow(mCurrentAnimationText); mBlendAnimationText = new TextDisplay(mCursor); AddWindow(mBlendAnimationText); mCurrentAnimationText.Text = "Current Animation"; mBlendAnimationText.Text = "Blend Animation"; // Blend controller mBlendController = new TimeLine(GuiManager.Cursor); this.AddWindow(mBlendController); mBlendController.ScaleX = 18f; mBlendController.MinimumValue = 0.0; mBlendController.MaximumValue = 1.0; mBlendController.Start = 0.0; mBlendController.ValueWidth = 1.0; mBlendController.VerticalBarIncrement = 0.1; mBlendController.CurrentValue = 0.0; mBlendController.GuiChange += new GuiMessage(mBlendController_onGUIChange); // Animation timings mAnimationTime = new TimeLine(GuiManager.Cursor); this.AddWindow(mAnimationTime); mAnimationTime.ScaleX = 9f; mAnimationTime.VerticalBarIncrement = 0.2; mAnimationTime.SmallVerticalBarIncrement = 0.1; mAnimationTime.ValueWidth = 1; mAnimationTime.GuiChange += new GuiMessage(mAnimationTime_onGUIChange); mBlendTime = new TimeLine(GuiManager.Cursor); this.AddWindow(mBlendTime); mBlendTime.ScaleX = 9f; mBlendTime.VerticalBarIncrement = 0.2; mBlendTime.SmallVerticalBarIncrement = 0.1; mBlendTime.ValueWidth = 1; mBlendTime.GuiChange += new GuiMessage(mBlendTime_onGUIChange); // Animation speeds mAnimationSpeed = new TimeLine(GuiManager.Cursor); this.AddWindow(mAnimationSpeed); mAnimationSpeed.ScaleX = 9f; mAnimationSpeed.MinimumValue = 0.0; mAnimationSpeed.MaximumValue = 2.0; mAnimationSpeed.Start = 0.0; mAnimationSpeed.ValueWidth = 2.0; mAnimationSpeed.VerticalBarIncrement = 0.5; mAnimationSpeed.SmallVerticalBarIncrement = 0.1; mAnimationSpeed.CurrentValue = 1.0; mAnimationSpeed.GuiChange += new GuiMessage(mAnimationSpeed_onGUIChange); mBlendSpeed = new TimeLine(GuiManager.Cursor); this.AddWindow(mBlendSpeed); mBlendSpeed.ScaleX = 9f; mBlendSpeed.MinimumValue = 0.0; mBlendSpeed.MaximumValue = 2.0; mBlendSpeed.Start = 0.0; mBlendSpeed.ValueWidth = 2.0; mBlendSpeed.VerticalBarIncrement = 0.5; mBlendSpeed.SmallVerticalBarIncrement = 0.1; mBlendSpeed.CurrentValue = 1.0; mBlendSpeed.GuiChange += new GuiMessage(mBlendSpeed_onGUIChange); mAnimationStopStart = new Button(GuiManager.Cursor); this.AddWindow(mAnimationStopStart); mAnimationStopStart.ScaleX = 5f; mAnimationStopStart.Text = "Stop"; mAnimationStopStart.Click += new GuiMessage(mAnimationStopStart_Click); // Set scaling mCurrentAnimation.ScaleX = 9f; mBlendAnimation.ScaleX = 9f; mCurrentAnimationText.ScaleY = 1f;// mCurrentAnimation.ScaleY; mCurrentAnimationText.ScaleX = mCurrentAnimation.ScaleX; mBlendAnimationText.ScaleY = 1f;// mBlendAnimation.ScaleY; mBlendAnimationText.ScaleX = mBlendAnimation.ScaleX; ScaleY = mCurrentAnimationText.ScaleY + mCurrentAnimation.ScaleY + 2f * mBlendController.ScaleY + 2f * mAnimationTime.ScaleY + 2f * mAnimationSpeed.ScaleY + 2f * mAnimationStopStart.ScaleY + .5f; ScaleX = (mCurrentAnimation.ScaleX + mBlendAnimation.ScaleX) + 4.5f / 2f; PositionUIElements(); Resizing += new GuiMessage(AnimationEditor_Resizing); // Add model PositionedModel = model; }
private void DrawModelMeshes(Camera camera, PositionedModel model, RenderMode renderMode) { switch (model.LodType) { case PositionedModel.LodTypes.Mesh: #region Mesh-Based LOD // Get the mesh index int l = model.LodMeshOrder.Count - 1; float dist = Vector3.Distance(camera.Position, model.Position); while (model.LodMeshOrder[l].LodDistance > dist && l > 0) { l--; } // Set parameters and draw the mesh ModelMeshXna lodMesh = model.XnaModel.Meshes[model.LodMeshOrder[l].MeshId]; // Draw the mesh DrawMesh(camera, model, model.LodMeshOrder[l].MeshId, renderMode); #endregion break; case PositionedModel.LodTypes.None: default: #region No LOD (Draw whole model) int meshCount = model.XnaModel.Meshes.Count; for (int i = 0; i < meshCount; i++) { DrawMesh(camera, model, i, renderMode); } #endregion break; } }
private static void ApplyColorOperation(PositionedModel model, BasicEffect effect)
void SelectModel(PositionedModel model) { mModelEditor = new ModelEditor(model); modelPropertyGrid.SelectedObject = mModelEditor; }
//GenericEffect lastEffect = null; #endif // private void RenderMmprList(List<ModelMeshPartRender> list) // { //#if XNA4 && WINDOWS_PHONE && USING_EMULATOR && DEBUG // if (list.Count != 0) // { // GenericEffect effectToUse = list[0].ModelMeshPart.Effect; // FlatRedBall.Content.Model.Helpers.ModelMeshPart modelMeshPart = // list[0].ModelMeshPart; // GraphicsDevice graphicsDevice = Renderer.GraphicsDevice; // // temporary to test things out: // Renderer.GraphicsDevice.RasterizerState = RasterizerState.CullNone; // // TODO: Apply lighting // if (!LightManager.EnableLighting) // { // effectToUse.LightingEnabled = false; // } // // This causes problems // // effectToUse.VertexColorEnabled = true; // /* // // TODO: ApplyColorOperation // effectToUse.EmissiveColor = Vector3.Zero; // effectToUse.DiffuseColor = Vector3.One; // */ // int indexIncrementPerModelMeshPart = modelMeshPart.PrimitiveCount * 3; // for (int i = 0; i < indexIncrementPerModelMeshPart; i++) // { // mPerInstanceIndexBuffer[i] = modelMeshPart.mIndexList[i + modelMeshPart.StartIndex]; // } // // Assumes 1 pass // if( effectToUse.GetCurrentTechnique(true).Passes.Count > 1 ) // { // throw new InvalidOperationException("The new efficient rendering system only supports effects with 1 render pass"); // } // BlendState previousState = FlatRedBallServices.GraphicsDevice.BlendState; // EffectPass effectPass; // if (lastEffect != effectToUse) // { // SpriteManager.Camera.SetDeviceViewAndProjection(effectToUse, false); // effectPass = effectToUse.GetCurrentTechnique( true ).Passes[0]; // effectPass.Apply(); // lastEffect = effectToUse; // } // int reusableIndex = 0; // VertexPositionNormalTexture tempVertex = new VertexPositionNormalTexture(); // Vector3 tempVector = new Vector3(); // Matrix matrix; // int mmprIndex = 0; // VertexPositionNormalTexture[] verticesToCopy = modelMeshPart.CpuVertices; // foreach (ModelMeshPartRender mmpr in list) // { // if (mmpr.PreCalculatedVerts != null) // { // mmpr.PreCalculatedVerts.CopyTo( // mReusableVertexList, reusableIndex); // reusableIndex += mmpr.PreCalculatedVerts.Length; // //for (int i = 0; i < verticesToCopy.Length; i++) // //{ // // mReusableVertexList[reusableIndex] = mmpr.PreCalculatedVerts[i]; // // reusableIndex++; // //} // } // else // { // matrix = mmpr.World; // for (int i = 0; i < verticesToCopy.Length; i++) // { // tempVertex = verticesToCopy[i]; // tempVector.X = tempVertex.Position.X; // tempVector.Y = tempVertex.Position.Y; // tempVector.Z = tempVertex.Position.Z; // MathFunctions.TransformVector(ref tempVector, ref matrix); // tempVertex.Position.X = tempVector.X; // tempVertex.Position.Y = tempVector.Y; // tempVertex.Position.Z = tempVector.Z; // mReusableVertexList[reusableIndex] = tempVertex; // reusableIndex++; // } // } // ushort extraAmountDestination = (ushort)(mmprIndex * indexIncrementPerModelMeshPart); // ushort extraAmountSource = (ushort)(mmprIndex * verticesToCopy.Length); // for (int i = indexIncrementPerModelMeshPart - 1; i > -1; i--) // //for (int i = 0; i < indexIncrementPerModelMeshPart; i++) // { // mReusableIndexList[i + extraAmountDestination] = (ushort)(mPerInstanceIndexBuffer[i] + extraAmountSource); // } // //graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, modelMeshPart.numVertices, modelMeshPart.startIndex, modelMeshPart.primitiveCount); // mmprIndex++; // /* // if (mmpr.RenderOverrides != null) // { // for (int i = 0; i < mmpr.RenderOverrides.Count; i++) // { // mmpr.RenderOverrides[i].Apply(ref modelMeshPart.vertexBuffer); // graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, modelMeshPart.numVertices, modelMeshPart.startIndex, modelMeshPart.primitiveCount); // } // } // */ // } // int numberOfVerts = reusableIndex; // int numberOfIndices = mmprIndex * indexIncrementPerModelMeshPart; // int numberOfPrimitives = numberOfIndices / 3; // mReusableVertexBuffer.SetData<VertexPositionNormalTexture>(mReusableVertexList, 0, numberOfVerts); // mReusableIndexBuffer.SetData<ushort>(mReusableIndexList, 0, numberOfIndices); // FlatRedBallServices.GraphicsDevice.SetVertexBuffer(mReusableVertexBuffer); // FlatRedBallServices.GraphicsDevice.Indices = mReusableIndexBuffer; // graphicsDevice.DrawIndexedPrimitives( // PrimitiveType.TriangleList, 0, 0, numberOfVerts, 0, numberOfPrimitives); // FlatRedBallServices.GraphicsDevice.SetVertexBuffer(null); // FlatRedBallServices.GraphicsDevice.Indices = null; // FlatRedBallServices.GraphicsDevice.BlendState = previousState; // } //#else // throw new NotImplementedException(); //#endif // } private void DrawModelOrAddToSortedDictionary(Camera camera, RenderMode renderMode, PositionedModel model) { if (model.Visible && (camera.CameraModelCullMode == CameraModelCullMode.None || camera.IsModelInView(model))) { if (model.AnimationController == null && model.CustomModel != null && AllowQuickRender) { #if XNA4 Matrix transformationMatrixFlippedAsNeeded = model.TransformationMatrix; foreach (FlatRedBall.Content.Model.Helpers.ModelMesh mesh in model.CustomModel.Meshes) { foreach (FlatRedBall.Content.Model.Helpers.ModelMeshPart meshPart in mesh.MeshParts) { // It's okay if we call this over and over, // it has a bool which it uses internally to // make sure there isn't unnecessary copying of // verts. meshPart.ResetVertexBuffer(); ModelMeshPartRender mmpr = new ModelMeshPartRender(); mmpr.ModelMeshPart = meshPart; if (model.RenderOverrides != null && model.RenderOverrides.ContainsKey(meshPart)) { mmpr.RenderOverrides = model.RenderOverrides[meshPart]; } mmpr.World = transformationMatrixFlippedAsNeeded; if (!model.IsAutomaticallyUpdated) { mmpr.PreCalculatedVerts = model.mPrecalculatedVertices[meshPart]; } if (mSortedModelMeshes.ContainsKey(meshPart)) { mSortedModelMeshes[meshPart].Add(mmpr); } else { List<ModelMeshPartRender> newList = new List<ModelMeshPartRender>(); newList.Add(mmpr); mSortedModelMeshes.Add(meshPart, newList); } } } #endif } else { DrawModel(camera, model, renderMode); } } }
private static void ApplyColorOperation(PositionedModel model, GenericEffect effect) #endif { switch (model.ColorOperation) { case ColorOperation.None: effect.EmissiveColor = Vector3.Zero; effect.DiffuseColor = Vector3.One; effect.Alpha = model.Alpha; effect.TextureEnabled = true; break; case ColorOperation.Add: effect.EmissiveColor = new Vector3(model.Red, model.Green, model.Blue); effect.DiffuseColor = Vector3.Zero; effect.Alpha = model.Alpha; effect.TextureEnabled = true; break; case ColorOperation.Modulate: effect.EmissiveColor = Vector3.Zero; effect.DiffuseColor = new Vector3(model.Red, model.Green, model.Blue); effect.Alpha = model.Alpha; effect.TextureEnabled = true; break; case ColorOperation.Color: effect.EmissiveColor = Vector3.Zero; effect.DiffuseColor = new Vector3(model.Red, model.Green, model.Blue); effect.Alpha = model.Alpha; effect.TextureEnabled = false; break; default: throw new NotImplementedException("Models do not support the color operation " + model.ColorOperation); //break; } }
public HeightMapRenderer(string contentManagerName, int width, int height, Model model, HeightMap heightMap, Matrix transformationMatrix) { mHeightMap = heightMap; // Create camera mCamera = new Camera(contentManagerName, width, height); #if !XNA4 // Set up rendering mode mCamera.RenderOrder.Clear(); mCamera.RenderOrder.Add(FlatRedBall.Graphics.RenderMode.Position); mCamera.DrawsCameraLayer = true; mCamera.DrawsWorld = false; mCamera.DrawToScreen = false; #endif // Get bounds GetMinMax(model, transformationMatrix); // Set up camera orthogonality mCamera.Orthogonal = true; mCamera.OrthogonalWidth = mMax.X - mMin.X; mCamera.OrthogonalHeight = mMax.Y - mMin.Y; mCamera.FarClipPlane = 3f + mMax.Z - mMin.Z; mCamera.NearClipPlane = 1f; // Set up camera position mCamera.Position = new Vector3( (mMax.X + mMin.X) / 2f, (mMax.Y + mMin.Y) / 2f, (mMax.Z + 2f)); // Add post-processing mCamera.PostProcessing.EffectCombineOrder.Clear(); mCamera.PostProcessing.EffectCombineOrder.Add(new HeightMapPostProcessor(heightMap)); // Add the camera to the engine Renderer.Cameras.Add(mCamera); // Add model to camera layer mModel = ModelManager.AddModel(model); ModelManager.AddToLayer(mModel, mCamera.Layer); }
private void ModelListBoxClick(Window callingWindow) { PositionedModel model = this.mModelListBox.GetFirstHighlightedObject() as PositionedModel; GameData.SelectModel(model); }
public HeightMapRenderer(string contentManagerName, int width, int height, PositionedModel model, HeightMap heightMap) : this(contentManagerName, width, height, model.XnaModel, heightMap, Matrix.CreateScale(model.ScaleX, model.ScaleY, model.ScaleZ) * model.RotationMatrix) { mModel.ScaleX = model.ScaleX; mModel.ScaleY = model.ScaleY; mModel.ScaleZ = model.ScaleZ; mModel.RotationX = model.RotationX; mModel.RotationY = model.RotationY; mModel.RotationZ = model.RotationZ; }