This is a quick fix to allow a user to scale models along the X, Y, and Z axes. That said Do not expect pretty code, for it to be error handled, or for it to work perfectly.
How to use the it:
The code creates components that can be added to existing models.
ChangeRelativeModelScale
When added to the model it changes the model from static to dynamic; and you will see 3 text boxes in the editor labeled with the axis they handle and containing the value 1.0000. In general it works like the scale in the Apply relative transform dialog. The model is scaled based on the values entered tin the text boxes. So, values above 1 scale the model up along the specified axis; and values below 1 scale the model down along the specified axis.
ScaleValueManipulation
When added to the model it changes the model from static to dynamic; and you will see 3 text boxes in the editor labeled with the axis they handle and containing the actual scale values extracted from the model's matrix. changing these values will actually replace the scale of the matrix with the values in the 3 text boxes.
The reason they change the model to dynamic is so that the onUpdate method will get called so that the changes in the scale will be made visible in the editor.
After the components are used they can be removed and the scaling changes will persist , because the scaling info is saved in the matrix and not the component it self.
trouble shooting
If you make a change to the scale of a model and you do not see any changes.
The model is still there but moved.
by posting it here i am looking for ways to better the components (maybe so they do not have to be dynamic to show changes).
Thank you for your time
Ion_21
the code ------------------------------------------------------------
//ScaleValueManipulation---------------------------------------------------------------
using System;
using Microsoft.Xna.Framework;
using SynapseGaming.LightingSystem.Core;
using SynapseGaming.LightingSystem.Editor;
using SynapseGaming.LightingSystem.Rendering;
using SynapseGaming.LightingSystem.Serialization;
namespace greatness.Components
{
[Serializable]
class ScaleValueManipulation : BaseComponentAutoSerialization<ISceneEntity>
/// <summary>
/// The scale of the model.
/// The EditorProperty and EditorNumberPadOptions attributes define
/// how the editor control for this property will behave.
/// The reason the max value you can put in the ere in 0.9999999 is
/// past that pion things start to happen that i do not know about.
/// This alco changes the ObjectType to dynamic, because if it is not
/// the OnUpdate will not be called and changes you want to make will
/// not be done. - Travis
/// </summary>
[SerializeMember]
[EditorProperty(true, Description = "Model X Scale", ToolTipText = "Model's X scale in relation to the world.")]
[EditorNumberPadOptions(8, 0.00000001, 0.9999999, 0.00000001)]
public float f_XmodelScale { get; set; }
[EditorProperty(true, Description = "Model Y Scale", ToolTipText = "Model's Y scale in relation to the world.")]
public float f_YmodelScale { get; set; }
[EditorProperty(true, Description = "Model Z Scale", ToolTipText = "Model's Z scale in relation to the world.")]
public float f_ZmodelScale { get; set; }
/// Initializes the component to have the scale from the matrix and sets it to dynamic.
/// (gets the current values of the model's matrix and from that gets the curent scales along the 3 asixs)
public override void OnInitialize()
if (!(ParentObject is ISceneObject))
return;
Vector3 v3_currentScale = new Vector3(1f);
Vector3 v3_currentTanslation;
Quaternion quat_currentRotation;
ISceneObject obj = ParentObject as ISceneObject;
if (obj.World.Decompose(out v3_currentScale, out quat_currentRotation, out v3_currentTanslation))
f_XmodelScale = v3_currentScale.X;
f_YmodelScale = v3_currentScale.Y;
f_ZmodelScale = v3_currentScale.Z;
}
obj.ObjectType = ObjectType.Dynamic;
/// ovreides the update method and calls the DoScaling() method to do the calculations
public override void OnUpdate(GameTime gametime)
if (!v3_currentScale.Equals(new Vector3(f_XmodelScale, f_YmodelScale, f_ZmodelScale)))
DoScaling();
///replaces the origional scale with the scale from the editor' UI
public void DoScaling()
obj.World = Matrix.CreateScale(f_XmodelScale, f_YmodelScale, f_ZmodelScale) * Matrix.CreateFromQuaternion(quat_currentRotation) * Matrix.CreateTranslation(v3_currentTanslation);
Hi Ion,
Nice work, that looks great. I'm sure a lot of people will find this very helpful, thanks for contributing it to the community!
Follow me on Twitter – development and personal tweetsAwesome XNA Videos – Lighting, Rendering, and game videos
That's a great idea: I can imagine adding features as hacks to the SunBurn Editor this way :p