/// <summary> /// Reads an animation track. /// </summary> protected void ReadAnimationTrack(BinaryMemoryReader reader, Animation anim) { // read the bone handle to apply this track to ushort boneHandle = ReadUShort(reader); // get a reference to the target bone Bone targetBone = skeleton.GetBone(boneHandle); // create an animation track for this bone NodeAnimationTrack track = anim.CreateNodeTrack(boneHandle, targetBone); // keep reading all keyframes for this track if (!IsEOF(reader)) { SkeletonChunkID chunkID = ReadChunk(reader); while (!IsEOF(reader) && (chunkID == SkeletonChunkID.KeyFrame)) { // read the key frame ReadKeyFrame(reader, track); // read the next chunk id // If we're not end of file get the next chunk ID if (!IsEOF(reader)) { chunkID = ReadChunk(reader); } } // backpedal to the start of the chunk if (!IsEOF(reader)) { Seek(reader, -ChunkOverheadSize); } } }
protected void TransformTrack(Matrix4 exportTransform, NodeAnimationTrack newTrack, NodeAnimationTrack track, Bone bone) { Matrix4 invExportTransform = exportTransform.Inverse(); Bone oldNode = (Bone)track.TargetNode; Bone newNode = (Bone)newTrack.TargetNode; for (int i = 0; i < track.KeyFrames.Count; ++i) { TransformKeyFrame keyFrame = track.GetTransformKeyFrame(i); TransformKeyFrame newKeyFrame = newTrack.CreateNodeKeyFrame(keyFrame.Time); Quaternion oldOrientation = oldNode.Orientation * keyFrame.Rotation; Vector3 oldTranslation = oldNode.Position + keyFrame.Translate; Matrix4 oldTransform = Multiverse.MathLib.MathUtil.GetTransform(oldOrientation, oldTranslation); Matrix4 newTransform = exportTransform * oldTransform * invExportTransform; Quaternion newOrientation = GetRotation(newTransform); Vector3 newTranslation = newTransform.Translation; newKeyFrame.Rotation = newNode.Orientation.Inverse() * newOrientation; newKeyFrame.Translate = newTranslation - newNode.Position; //if (oldNode.Name == "Lower_Torso_BIND_jjj") { // log.DebugFormat("New translation: {0}; New Position: {1}", newTranslation, newNode.Position); //} } }
/// <summary> /// Reads an animation track section. /// </summary> protected void ReadKeyFrame(BinaryReader reader, NodeAnimationTrack track) { var time = ReadFloat(reader); // create a new keyframe with the specified length var keyFrame = track.CreateNodeKeyFrame(time); // read orientation var rotate = ReadQuat(reader); keyFrame.Rotation = rotate; // read translation var translate = ReadVector3(reader); keyFrame.Translate = translate; // read scale if it is in there if (currentChunkLength >= 50) { var scale = ReadVector3(reader); keyFrame.Scale = scale; } else { keyFrame.Scale = Vector3.UnitScale; } }
public static void DuplicateKeyFrame(NodeAnimationTrack track, TransformKeyFrame orig) { TransformKeyFrame newKeyFrame = (TransformKeyFrame)track.CreateKeyFrame(orig.Time); newKeyFrame.Scale = orig.Scale; newKeyFrame.Rotation = orig.Rotation; newKeyFrame.Translate = orig.Translate; }
/// <summary> /// /// </summary> protected override void SetupContent() { this.ptex = TextureManager.Instance.CreateManual("DynaTex", ResourceGroupManager.DefaultResourceGroupName, TextureType.ThreeD, 64, 64, 64, 0, Media.PixelFormat.A8R8G8B8, TextureUsage.Default, null); SceneManager.AmbientLight = new ColorEx(0.6f, 0.6f, 0.6f); SceneManager.SetSkyBox(true, "Examples/MorningSkyBox", 50); Light light = SceneManager.CreateLight("VolumeTextureSampleLight"); light.Diffuse = new ColorEx(0.75f, 0.75f, 0.80f); light.Specular = new ColorEx(0.9f, 0.9f, 1); light.Position = new Vector3(-100, 80, 50); SceneManager.RootSceneNode.AttachObject(light); // Create volume renderable this.snode = SceneManager.RootSceneNode.CreateChildSceneNode(Vector3.Zero); this.vrend = new VolumeRendable(32, 750, "DynaTex"); this.snode.AttachObject(this.vrend); this.trend = new ThingRendable(90, 32, 7.5f); this.trend.Material = (Material)MaterialManager.Instance.GetByName("Examples/VTDarkStuff"); this.trend.Material.Load(); this.snode.AttachObject(this.trend); this.fnode = SceneManager.RootSceneNode.CreateChildSceneNode(); Entity head = SceneManager.CreateEntity("head", "ogrehead.mesh"); this.fnode.AttachObject(head); Animation anim = SceneManager.CreateAnimation("OgreTrack", 10); anim.InterpolationMode = InterpolationMode.Spline; NodeAnimationTrack track = anim.CreateNodeTrack(0, this.fnode); TransformKeyFrame key = track.CreateNodeKeyFrame(0); key.Translate = new Vector3(0, -15, 0); key = track.CreateNodeKeyFrame(5); key.Translate = new Vector3(0, 15, 0); key = track.CreateNodeKeyFrame(10); key.Translate = new Vector3(0, -15, 0); this.animState = SceneManager.CreateAnimationState("OgreTrack"); this.animState.IsEnabled = true; this.globalReal = 0.4f; this.globalImag = 0.6f; this.globalTheta = 0.0f; CreateControls(); DragLook = true; Generate(); }
public override void CreateScene() { SceneNode node1 = base.sceneMgr.RootSceneNode.CreateChildSceneNode("Tutorial10Node"); // Create a point light Light l = base.sceneMgr.CreateLight("MainLight"); // Accept default settings: point light, white diffuse, just set position // Add light to the scene node SceneNode lightNode = base.sceneMgr.RootSceneNode.CreateChildSceneNode(); lightNode.CreateChildSceneNode(new Vector3(10, 10, 10)).AttachObject(l); MeshPtr pMesh = MeshManager.Singleton.Load("knot.mesh", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, HardwareBuffer.Usage.HBU_DYNAMIC_WRITE_ONLY, HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY, true, true);//can still read it //ushort src, dest; //if (!pMesh.SuggestTangentVectorBuildParams(VertexElementSemantic.VES_TANGENT, out src, out dest)) // pMesh.BuildTangentVectors(VertexElementSemantic.VES_TANGENT, src, dest); //create entity Entity entity = sceneMgr.CreateEntity("Tutorial10Entity", "knot.mesh"); entity.SetMaterialName("CgTutorials/C5E2_Material"); //attach to main node node1.AttachObject(entity); // set up spline animation of node Animation anim = sceneMgr.CreateAnimation("LightTrack", 10F); // Spline it for nice curves anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE); // Create a track to animate the camera's node NodeAnimationTrack track = anim.CreateNodeTrack(0, lightNode); // Setup keyframes TransformKeyFrame key = track.CreateNodeKeyFrame(0F); // startposition key = track.CreateNodeKeyFrame(2.5F); key.Translate = new Vector3(500F, 500F, -1000F); key = track.CreateNodeKeyFrame(5F); key.Translate = new Vector3(-1500F, 1000F, -600F); key = track.CreateNodeKeyFrame(7.5F); key.Translate = new Vector3(0F, 100F, 0F); key = track.CreateNodeKeyFrame(10F); key.Translate = new Vector3(0F, 0F, 0F); // Create a new animation state to track this animState = sceneMgr.CreateAnimationState("LightTrack"); animState.Enabled = true; }
public NodeAnimationTrack _clone(Animation newParent) { global::System.IntPtr cPtr = OgrePINVOKE.NodeAnimationTrack__clone(swigCPtr, Animation.getCPtr(newParent)); NodeAnimationTrack ret = (cPtr == global::System.IntPtr.Zero) ? null : new NodeAnimationTrack(cPtr, false); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public NodeAnimationTrack createNodeTrack(ushort handle) { global::System.IntPtr cPtr = OgrePINVOKE.Animation_createNodeTrack__SWIG_0(swigCPtr, handle); NodeAnimationTrack ret = (cPtr == global::System.IntPtr.Zero) ? null : new NodeAnimationTrack(cPtr, false); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
protected void TransformAnimation(Matrix4 exportTransform, Animation newAnim, Animation anim, Skeleton newSkeleton) { foreach (NodeAnimationTrack track in anim.NodeTracks.Values) { NodeAnimationTrack newTrack = newAnim.CreateNodeTrack(track.Handle); Bone targetBone = (Bone)track.TargetNode; newTrack.TargetNode = newSkeleton.GetBone(targetBone.Handle); TransformTrack(exportTransform, newTrack, track, targetBone); } }
protected void WriteAnimationTrack(BinaryWriter writer, NodeAnimationTrack track) { var start_offset = writer.Seek(0, SeekOrigin.Current); WriteChunk(writer, SkeletonChunkID.AnimationTrack, 0); WriteUShort(writer, (ushort)track.Handle); for (ushort i = 0; i < track.KeyFrames.Count; i++) { var keyFrame = track.GetNodeKeyFrame(i); WriteKeyFrame(writer, keyFrame); } var end_offset = writer.Seek(0, SeekOrigin.Current); writer.Seek((int)start_offset, SeekOrigin.Begin); WriteChunk(writer, SkeletonChunkID.AnimationTrack, (int)(end_offset - start_offset)); writer.Seek((int)end_offset, SeekOrigin.Begin); }
public override void CreateScene() { SceneNode node1 = base.sceneMgr.RootSceneNode.CreateChildSceneNode("Tutorial08Node"); Entity entity = base.sceneMgr.CreateEntity("Tutorial08Entity", SceneManager.PrefabType.PT_SPHERE); entity.SetMaterialName("CgTutorials/C4E1_Material"); node1.AttachObject(entity); // Make sure the camera track this node camera.SetAutoTracking(true, node1); // Create the camera node & attach camera SceneNode camNode = sceneMgr.RootSceneNode.CreateChildSceneNode(); camNode.AttachObject(camera); // set up spline animation of node Animation anim = sceneMgr.CreateAnimation("CameraTrack", 10F); // Spline it for nice curves anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE); // Create a track to animate the camera's node NodeAnimationTrack track = anim.CreateNodeTrack(0, camNode); // Setup keyframes TransformKeyFrame key = track.CreateNodeKeyFrame(0F); // startposition key = track.CreateNodeKeyFrame(2.5F); key.Translate = new Vector3(500F, 500F, -1000F); key = track.CreateNodeKeyFrame(5F); key.Translate = new Vector3(-1500F, 1000F, -600F); key = track.CreateNodeKeyFrame(7.5F); key.Translate = new Vector3(0F, 100F, 0F); key = track.CreateNodeKeyFrame(10F); key.Translate = new Vector3(0F, 0F, 0F); // Create a new animation state to track this animState = sceneMgr.CreateAnimationState("CameraTrack"); animState.Enabled = true; camera.PolygonMode = PolygonMode.PM_WIREFRAME; }
/// <summary> /// /// </summary> protected override void SetupContent() { // setup some basic lighting for our scene SceneManager.AmbientLight = new ColorEx(0.3f, 0.3f, 0.3f); SceneManager.CreateLight("CameraTrackLight").Position = new Vector3(20, 80, 50); SceneManager.SetSkyBox(true, "Examples/MorningSkyBox", 5000); // create an ogre head entity and attach it to a node Entity head = SceneManager.CreateEntity("Head", "ogrehead.mesh"); SceneNode headNode = SceneManager.RootSceneNode.CreateChildSceneNode(); headNode.AttachObject(head); CameraManager.setStyle(CameraStyle.Manual); // we will be controlling the camera ourselves, so disable the camera man Camera.SetAutoTracking(true, headNode); // make the camera face the head // create a camera node and attach camera to it SceneNode camNode = SceneManager.RootSceneNode.CreateChildSceneNode(); camNode.AttachObject(Camera); // set up a 10 second animation for our camera, using spline interpolation for nice curves Animation anim = SceneManager.CreateAnimation("CameraTrack", 10); anim.InterpolationMode = InterpolationMode.Spline; // create a track to animate the camera's node NodeAnimationTrack track = anim.CreateNodeTrack(0, camNode); // create keyframes for our track track.CreateNodeKeyFrame(0).Translate = new Vector3(200, 0, 0); track.CreateNodeKeyFrame(2.5f).Translate = new Vector3(0, -50, 100); track.CreateNodeKeyFrame(5).Translate = new Vector3(-500, 100, 0); track.CreateNodeKeyFrame(7.5f).Translate = new Vector3(0, 200, -300); track.CreateNodeKeyFrame(10).Translate = new Vector3(200, 0, 0); // create a new animation state to track this this.animState = SceneManager.CreateAnimationState("CameraTrack"); this.animState.IsEnabled = true; base.SetupContent(); }
protected XmlElement WriteTrack(NodeAnimationTrack track) { XmlElement node = document.CreateElement("track"); XmlAttribute attr; attr = document.CreateAttribute("bone"); attr.Value = track.TargetNode.Name; node.Attributes.Append(attr); XmlElement keyFramesNode = document.CreateElement("keyframes"); foreach (KeyFrame baseKeyFrame in track.KeyFrames) { TransformKeyFrame keyFrame = (TransformKeyFrame)baseKeyFrame; //if (track.TargetNode.Parent != null) // Debug.Assert(keyFrame.Translate.LengthSquared < .01); XmlElement keyFrameNode = WriteKeyFrame(keyFrame); keyFramesNode.AppendChild(keyFrameNode); } node.AppendChild(keyFramesNode); return(node); }
protected void buildFloatAnimation(SceneNode animationNode, float duration, bool sidewaysOnly) { Animation animation = framework.SceneMgr.CreateAnimation(animationNode.Name + "_FloatAnimation", duration); animation.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE); NodeAnimationTrack track = animation.CreateNodeTrack(0, animationNode); TransformKeyFrame key; Radian depth; depth = sidewaysOnly ? new Radian(new Degree(0)) : new Radian(new Degree(-2)); Quaternion baseQ = Quaternion.IDENTITY; key = track.CreateNodeKeyFrame(0.0f); key.Rotation = Quaternion.IDENTITY * baseQ; key = track.CreateNodeKeyFrame(2.0f); key.Rotation = new Quaternion(new Radian(new Degree(-5)), Vector3.UNIT_Z) * baseQ; // bok key = track.CreateNodeKeyFrame(5.0f); key.Rotation = new Quaternion(new Radian(new Degree(0)), Vector3.UNIT_Z) * new Quaternion(depth, Vector3.UNIT_X) * baseQ; // gora / dol key = track.CreateNodeKeyFrame(7.0f); key.Rotation = new Quaternion(new Radian(new Degree(4)), Vector3.UNIT_Z) * new Quaternion(new Radian(new Degree(-0)), Vector3.UNIT_X) * baseQ; // bok key = track.CreateNodeKeyFrame(10.0f); key.Rotation = Quaternion.IDENTITY * baseQ; shipAnimationState = framework.SceneMgr.CreateAnimationState(animationNode.Name + "_FloatAnimation"); shipAnimationState.Enabled = true; shipAnimationState.Loop = true; }
protected void ReadTrack(XmlNode node, Animation anim) { string boneName = node.Attributes["bone"].Value; // get a reference to the target bone Bone targetBone = skeleton.GetBone(boneName); // create an animation track for this bone NodeAnimationTrack track = anim.CreateNodeTrack(targetBone.Handle, targetBone); foreach (XmlNode childNode in node.ChildNodes) { switch (childNode.Name) { case "keyframes": ReadKeyFrames(childNode, track); break; default: DebugMessage(childNode); break; } } }
protected override void CreateScene() { // setup some basic lighting for our scene _sceneManager.AmbientLight = new ColourValue(0.3f, 0.3f, 0.3f); var lightNode = _sceneManager.RootSceneNode.CreateChildSceneNode(); lightNode.SetPosition(20, 80, 50); lightNode.AttachObject(_sceneManager.CreateLight()); _sceneManager.SetSkyBox(true, "Examples/SpaceSkyBox"); // create an ogre head entity and attach it to a node Entity head = _sceneManager.CreateEntity("ogrehead.mesh"); head.Name = "Head"; SceneNode headNode = _sceneManager.GetRootSceneNode().CreateChildSceneNode(); headNode.Translate(0, 40, 0); headNode.AttachObject(head); // create a camera node and attach camera to it SceneNode camNode = _sceneManager.GetRootSceneNode().CreateChildSceneNode(); _camera.DetachFromParent(); camNode.AttachObject(_camera); // set up a 10 second animation for our camera, using spline interpolation for nice curves Animation anim = _sceneManager.CreateAnimation("CameraTrack", 10); anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE); // create a track to animate the camera's node NodeAnimationTrack track = anim.CreateNodeTrack(camNode); // create keyframes for our track track.CreateNodeKeyFrame(0).Translate = new Vector3(200, 0, 0); track.CreateNodeKeyFrame(2.5f).Translate = new Vector3(0, -50, 100); track.CreateNodeKeyFrame(5).Translate = new Vector3(-500, 100, 0); track.CreateNodeKeyFrame(7.5f).Translate = new Vector3(0, 200, -300); track.CreateNodeKeyFrame(10).Translate = new Vector3(200, 0, 0); // create a new animation state to track this _animState = _sceneManager.CreateAnimationState("CameraTrack"); _animState.Enabled = true; // Now create another scene manager with only _rttSceneManager = CreateSceneManager(); // Create the RenderTargetTexture _rttCamera = _rttSceneManager.CreateCamera("RttCamera"); _rttCamera.Position = new Vector3(0f, 10f, 500f); _rttCamera.LookAt(new Vector3(0f, 0f, -300f)); _rttCamera.AutoAspectRatio = true; _rttCamera.NearClipDistance = 5.0f; // Penguin Entity penguin = _rttSceneManager.CreateEntity("penguin.mesh"); _penguinNode = _rttSceneManager.RootSceneNode.CreateChildSceneNode(); _penguinNode.AttachObject(penguin); penguin.Name = "Penguin"; MaterialPtr penguinMaterial = MaterialManager.Singleton.Create("PenguinMaterial", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); penguinMaterial.GetTechnique(0).GetPass(0).LightingEnabled = false; penguinMaterial.GetTechnique(0).GetPass(0).CreateTextureUnitState("penguin.jpg"); penguin.SetMaterialName(penguinMaterial.Name); var screenTexture0 = TextureManager.Singleton.CreateManual( "screenTexture0", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, TextureType.TEX_TYPE_2D, 640, 480, 0, PixelFormat.PF_R8G8B8, (int)TextureUsage.TU_RENDERTARGET ); CompositorManager2 compositorManager = _root.CompositorManager2; string workspaceName = GetType().Name + "RttWorkspace"; if (!compositorManager.HasWorkspaceDefinition(workspaceName)) { compositorManager.CreateBasicWorkspaceDef(workspaceName, new ColourValue(1.0f, 0.0f, 0.0f, 1.0f)); } _rttWorkspace = _root.CompositorManager2.AddWorkspace( _rttSceneManager, screenTexture0.GetBuffer().GetRenderTarget(), _rttCamera, workspaceName, true); MaterialPtr renderMat = MaterialManager.Singleton.Create("RttMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); var pass = renderMat.GetTechnique(0).GetPass(0); pass.LightingEnabled = false; var textureUnit = pass.CreateTextureUnitState(); textureUnit.SetContentType(TextureUnitState.ContentType.CONTENT_COMPOSITOR); textureUnit.SetTextureName("screenTexture0", TextureType.TEX_TYPE_2D); textureUnit.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_WRAP); Plane plane = new Plane(Vector3.UNIT_Y, 0); MeshManager.Singleton.CreatePlane( "planeMesh", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, 700.0f, 1300.0f, 10, 10, true, 1, 4.0f, 4.0f, Vector3.UNIT_Z); Entity planeEntity = _sceneManager.CreateEntity("planeMesh"); planeEntity.SetMaterialName("RttMat"); planeEntity.CastShadows = false; _sceneManager.RootSceneNode.CreateChildSceneNode().AttachObject(planeEntity); }
void SetupTrailLights() { sceneMgr.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f); Vector3 dir = new Vector3(-1, -1, 0.5f); dir.Normalise(); Light l = sceneMgr.CreateLight("light1"); l.Type = Light.LightTypes.LT_DIRECTIONAL; l.Direction = dir; NameValuePairList pairList = new NameValuePairList(); pairList["numberOfChains"] = "2"; pairList["maxElements"] = "80"; RibbonTrail trail = (RibbonTrail)( sceneMgr.CreateMovableObject("1", "RibbonTrail", pairList)); trail.MaterialName = "Examples/LightRibbonTrail"; trail.TrailLength = 400; sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(trail); // Create 3 nodes for trail to follow SceneNode animNode = sceneMgr.RootSceneNode.CreateChildSceneNode(); animNode.Position = new Vector3(50, 30, 0); Animation anim = sceneMgr.CreateAnimation("an1", 14); anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE); NodeAnimationTrack track = anim.CreateNodeTrack(1, animNode); TransformKeyFrame kf = track.CreateNodeKeyFrame(0); kf.Translate = new Vector3(50, 30, 0); kf = track.CreateNodeKeyFrame(2); kf.Translate = new Vector3(100, -30, 0); kf = track.CreateNodeKeyFrame(4); kf.Translate = new Vector3(120, -100, 150); kf = track.CreateNodeKeyFrame(6); kf.Translate = new Vector3(30, -100, 50); kf = track.CreateNodeKeyFrame(8); kf.Translate = new Vector3(-50, 30, -50); kf = track.CreateNodeKeyFrame(10); kf.Translate = new Vector3(-150, -20, -100); kf = track.CreateNodeKeyFrame(12); kf.Translate = new Vector3(-50, -30, 0); kf = track.CreateNodeKeyFrame(14); kf.Translate = new Vector3(50, 30, 0); AnimationState animState = sceneMgr.CreateAnimationState("an1"); animState.Enabled = true; mAnimStateList.Add(animState); trail.SetInitialColour(0, 1.0f, 0.8f, 0); trail.SetColourChange(0, 0.5f, 0.5f, 0.5f, 0.5f); trail.SetInitialWidth(0, 5); trail.AddNode(animNode); // Add light Light l2 = sceneMgr.CreateLight("l2"); l2.DiffuseColour = (trail.GetInitialColour(0)); animNode.AttachObject(l2); // Add billboard BillboardSet bbs = sceneMgr.CreateBillboardSet("bb", 1); bbs.CreateBillboard(Vector3.ZERO, trail.GetInitialColour(0)); bbs.MaterialName = "Examples/Flare"; animNode.AttachObject(bbs); animNode = sceneMgr.RootSceneNode.CreateChildSceneNode(); animNode.Position = new Vector3(-50, 100, 0); anim = sceneMgr.CreateAnimation("an2", 10); anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE); track = anim.CreateNodeTrack(1, animNode); kf = track.CreateNodeKeyFrame(0); kf.Translate = new Vector3(-50, 100, 0); kf = track.CreateNodeKeyFrame(2); kf.Translate = new Vector3(-100, 150, -30); kf = track.CreateNodeKeyFrame(4); kf.Translate = new Vector3(-200, 0, 40); kf = track.CreateNodeKeyFrame(6); kf.Translate = new Vector3(0, -150, 70); kf = track.CreateNodeKeyFrame(8); kf.Translate = new Vector3(50, 0, 30); kf = track.CreateNodeKeyFrame(10); kf.Translate = new Vector3(-50, 100, 0); animState = sceneMgr.CreateAnimationState("an2"); animState.Enabled = true; mAnimStateList.Add(animState); trail.SetInitialColour(1, 0.0f, 1.0f, 0.4f); trail.SetColourChange(1, 0.5f, 0.5f, 0.5f, 0.5f); trail.SetInitialWidth(1, 5); trail.AddNode(animNode); // Add light l2 = sceneMgr.CreateLight("l3"); l2.DiffuseColour = trail.GetInitialColour(1); animNode.AttachObject(l2); // Add billboard bbs = sceneMgr.CreateBillboardSet("bb2", 1); bbs.CreateBillboard(Vector3.ZERO, trail.GetInitialColour(1)); bbs.MaterialName = "Examples/Flare"; animNode.AttachObject(bbs); }
protected override void CreateScene() { // setup some basic lighting for our scene _sceneManager.AmbientLight = new ColourValue(0.3f, 0.3f, 0.3f); var lightNode = _sceneManager.RootSceneNode.CreateChildSceneNode(); lightNode.SetPosition(20, 80, 50); lightNode.AttachObject(_sceneManager.CreateLight()); _sceneManager.SetSkyBox(true, "Examples/SpaceSkyBox"); // create an ogre head entity and attach it to a node Entity head = _sceneManager.CreateEntity("ogrehead.mesh"); head.Name = "Head"; SceneNode headNode = _sceneManager.GetRootSceneNode().CreateChildSceneNode(); headNode.Translate(0, 40, 0); headNode.AttachObject(head); // create a camera node and attach camera to it SceneNode camNode = _sceneManager.GetRootSceneNode().CreateChildSceneNode(); _camera.DetachFromParent(); camNode.AttachObject(_camera); // set up a 10 second animation for our camera, using spline interpolation for nice curves Animation anim = _sceneManager.CreateAnimation("CameraTrack", 10); anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE); // create a track to animate the camera's node NodeAnimationTrack track = anim.CreateNodeTrack(camNode); // create keyframes for our track track.CreateNodeKeyFrame(0).Translate = new Vector3(200, 0, 0); track.CreateNodeKeyFrame(2.5f).Translate = new Vector3(0, -50, 100); track.CreateNodeKeyFrame(5).Translate = new Vector3(-500, 100, 0); track.CreateNodeKeyFrame(7.5f).Translate = new Vector3(0, 200, -300); track.CreateNodeKeyFrame(10).Translate = new Vector3(200, 0, 0); // create a new animation state to track this _animState = _sceneManager.CreateAnimationState("CameraTrack"); _animState.Enabled = true; // Now create another scene manager with only _rttSceneManager = CreateSceneManager(); // Create the RenderTargetTexture _rttCamera = _rttSceneManager.CreateCamera("RttCamera"); _rttCamera.Position = new Vector3(0f, 10f, 500f); _rttCamera.LookAt(new Vector3(0f, 0f, -300f)); _rttCamera.AutoAspectRatio = true; _rttCamera.NearClipDistance = 5.0f; // Penguin Entity penguin = _rttSceneManager.CreateEntity("penguin.mesh"); _penguinNode = _rttSceneManager.RootSceneNode.CreateChildSceneNode(); _penguinNode.AttachObject(penguin); penguin.Name = "Penguin"; MaterialPtr penguinMaterial = MaterialManager.Singleton.Create("PenguinMaterial", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); penguinMaterial.GetTechnique(0).GetPass(0).LightingEnabled = false; penguinMaterial.GetTechnique(0).GetPass(0).CreateTextureUnitState("penguin.jpg"); penguin.SetMaterialName(penguinMaterial.Name); var screenTexture0 = TextureManager.Singleton.CreateManual( "screenTexture0", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, TextureType.TEX_TYPE_2D, 640, 480, 0, PixelFormat.PF_R8G8B8, (int)TextureUsage.TU_RENDERTARGET ); CompositorManager2 compositorManager = _root.CompositorManager2; string workspaceName = GetType().Name + "RttWorkspace"; if (!compositorManager.HasWorkspaceDefinition(workspaceName)) { compositorManager.CreateBasicWorkspaceDef(workspaceName, new ColourValue(1.0f, 0.0f, 0.0f, 1.0f)); } _rttWorkspace = _root.CompositorManager2.AddWorkspace( _rttSceneManager, screenTexture0.GetBuffer().GetRenderTarget(), _rttCamera, workspaceName, true); MaterialPtr renderMat = MaterialManager.Singleton.Create("RttMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); var pass = renderMat.GetTechnique(0).GetPass(0); pass.LightingEnabled = false; var textureUnit = pass.CreateTextureUnitState(); textureUnit.SetContentType(TextureUnitState.ContentType.CONTENT_COMPOSITOR); textureUnit.SetTextureName("screenTexture0", TextureType.TEX_TYPE_2D); textureUnit.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_WRAP); Plane plane = new Plane(Vector3.UNIT_Y, 0); MeshManager.Singleton.CreatePlane( "planeMesh", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, 700.0f, 1300.0f, 10, 10, true, 1, 4.0f, 4.0f, Vector3.UNIT_Z); Entity planeEntity = _sceneManager.CreateEntity("planeMesh"); planeEntity.SetMaterialName("RttMat"); planeEntity.CastShadows = false; _sceneManager.RootSceneNode.CreateChildSceneNode().AttachObject(planeEntity); // Test Miyagi // Init MiyagiSystem _miyagiSystem = new MiyagiSystem("Mogre", (int)_window.Width, (int)_window.Height); //const string PluginPath = @"..\..\..\debug\Plugins"; //this.miyagiSystem.PluginManager.LoadPlugin(Path.Combine(PluginPath, "Miyagi.Plugin.Input.Mois.dll"), this.inputKeyboard, this.inputMouse); Resources.Create(_miyagiSystem); //Utilities.CreateCursor(system.GUIManager); // create a default GUI var gui = new GUI(); // A Button is a simple skinned control capable of changing its current texture automatically on certain mouse events // (MouseDown/MouseEnter/MouseLeave/MouseUp). Those subskins are optinal, if a subskin is not defined, Miyagi will fall // back to an appropriate alternative. // Since Button inherits from Label it provides the same TextStyle options. var button1 = new Miyagi.UI.Controls.Button { Text = "HELLO WORLD", Location = new Point(140, 140), Size = new Size(200, 50), Skin = Resources.Skins["ButtonSkin"], TextStyle = { Alignment = Alignment.MiddleCenter, ForegroundColour = Colours.White } }; // add the Buttons to the GUI gui.Controls.Add(button1); //gui.Controls.Add(button2); var pictureBox = new Miyagi.UI.Controls.PictureBox { Name = "testingPictureBox", Location = new Point(380, 140), Size = new Size(400, 100), }; pictureBox.Bitmap = new System.Drawing.Bitmap(new System.Drawing.Bitmap(400, 100)); // add the Buttons to the GUI gui.Controls.Add(pictureBox); // add the GUI to the GUIManager _miyagiSystem.GUIManager.GUIs.Add(gui); gui.SpriteRenderer.CacheToTexture = true; System.Windows.Forms.Timer dummyTimer = new System.Windows.Forms.Timer(); dummyTimer.Interval = 2000; dummyTimer.Tick += dummyTimer_Tick; dummyTimer.Start(); }
public void UpdateFields() { boneNameLabel.Text = selectedBone; if (skeleton.ContainsBone(boneNameLabel.Text)) { Bone bone = skeleton.GetBone(boneNameLabel.Text); Quaternion q = ModelViewer.GetRotation(bone.FullTransform); boneNameLabel.Text = bone.Name; bonePosition.Text = bone.FullTransform.Translation.ToString(); boneRotation.Text = q.ToString(); boneRotation2.Text = string.Format("X:{0} Y:{1} Z:{2}", q.PitchInDegrees, q.YawInDegrees, q.RollInDegrees); q = bone.Orientation; relPosition.Text = bone.Position.ToString(); relRotation.Text = q.ToString(); relRotation2.Text = string.Format("X:{0} Y:{1} Z:{2}", q.PitchInDegrees, q.YawInDegrees, q.RollInDegrees); Bone bindBone = skeleton.GetBone(boneNameLabel.Text); Matrix4 bindBoneFullTransform = bindBone.BindDerivedInverseTransform.Inverse(); q = ModelViewer.GetRotation(bindBoneFullTransform); bindPosition.Text = bindBoneFullTransform.Translation.ToString(); bindRotation.Text = q.ToString(); bindRotation2.Text = string.Format("X:{0} Y:{1} Z:{2}", q.PitchInDegrees, q.YawInDegrees, q.RollInDegrees); AnimationState currentAnimation = modelViewer.CurrentAnimation; if (currentAnimation != null) { animationName.Text = "Animation: " + currentAnimation.Name; float currentTime = currentAnimation.Time; animationTime.Text = "Time: " + currentTime.ToString(); Animation anim = skeleton.GetAnimation(currentAnimation.Name); NodeAnimationTrack animTrack = anim.NodeTracks[bone.Handle]; KeyFrame keyFrame1, keyFrame2; ushort dummy; animTrack.GetKeyFramesAtTime(currentTime, out keyFrame1, out keyFrame2, out dummy); AnimationStateSet helperAnimSet = new AnimationStateSet(); helperSkeleton.InitAnimationState(helperAnimSet); AnimationState helperAnimation = helperAnimSet.GetAnimationState(currentAnimation.Name); helperAnimation.IsEnabled = true; helperAnimation.Time = keyFrame1.Time; helperSkeleton.SetAnimationState(helperAnimSet); Bone helperBone = helperSkeleton.GetBone(bone.Handle); // currentAnimation.Time; keyFrame1Time.Text = helperAnimation.Time.ToString(); q = ModelViewer.GetRotation(helperBone.FullTransform); keyFrame1Position.Text = helperBone.FullTransform.Translation.ToString(); keyFrame1Rotation.Text = q.ToString(); keyFrame1Rotation2.Text = string.Format("X:{0} Y:{1} Z:{2}", q.PitchInDegrees, q.YawInDegrees, q.RollInDegrees); helperAnimation.Time = keyFrame2.Time; helperSkeleton.SetAnimationState(helperAnimSet); keyFrame2Time.Text = helperAnimation.Time.ToString(); q = ModelViewer.GetRotation(helperBone.FullTransform); keyFrame2Position.Text = helperBone.FullTransform.Translation.ToString(); keyFrame2Rotation.Text = q.ToString(); keyFrame2Rotation2.Text = string.Format("X:{0} Y:{1} Z:{2}", q.PitchInDegrees, q.YawInDegrees, q.RollInDegrees); #if NOT keyFrame1Time.Text = keyFrame1.Time.ToString(); q = keyFrame1.Rotation; keyFrame1Position.Text = helperBone.Translate.ToString(); keyFrame1Rotation.Text = q.ToString(); keyFrame1Rotation2.Text = string.Format("X:{0} Y:{1} Z:{2}", q.PitchInDegrees, q.YawInDegrees, q.RollInDegrees); keyFrame2Time.Text = keyFrame2.Time.ToString(); q = keyFrame2.Rotation; keyFrame2Position.Text = keyFrame2.Translate.ToString(); keyFrame2Rotation.Text = q.ToString(); keyFrame2Rotation2.Text = string.Format("X:{0} Y:{1} Z:{2}", q.PitchInDegrees, q.YawInDegrees, q.RollInDegrees); #endif } else { animationName.Text = "No animation selected"; } bonePosition.Show(); boneRotation.Show(); boneRotation2.Show(); relPosition.Show(); relRotation.Show(); relRotation2.Show(); bindPosition.Show(); bindRotation.Show(); bindRotation2.Show(); if (currentAnimation != null) { prevKeyframeLabel.Show(); keyFrame1TimeLabel.Show(); keyFrame1PositionLabel.Show(); keyFrame1RotationLabel.Show(); keyFrame1Time.Show(); keyFrame1Position.Show(); keyFrame1Rotation.Show(); keyFrame1Rotation2.Show(); nextKeyframeLabel.Show(); keyFrame2TimeLabel.Show(); keyFrame2PositionLabel.Show(); keyFrame2RotationLabel.Show(); keyFrame2Time.Show(); keyFrame2Position.Show(); keyFrame2Rotation.Show(); keyFrame2Rotation2.Show(); } else { prevKeyframeLabel.Hide(); keyFrame1TimeLabel.Hide(); keyFrame1PositionLabel.Hide(); keyFrame1RotationLabel.Hide(); keyFrame1Time.Hide(); keyFrame1Position.Hide(); keyFrame1Rotation.Hide(); keyFrame1Rotation2.Hide(); nextKeyframeLabel.Hide(); keyFrame2TimeLabel.Hide(); keyFrame2PositionLabel.Hide(); keyFrame2RotationLabel.Hide(); keyFrame2Time.Hide(); keyFrame2Position.Hide(); keyFrame2Rotation.Hide(); keyFrame2Rotation2.Hide(); } } else { boneNameLabel.Text = "Invalid Bone Selected"; bonePosition.Hide(); boneRotation.Hide(); boneRotation2.Hide(); relPosition.Hide(); relRotation.Hide(); relRotation2.Hide(); bindPosition.Hide(); bindRotation.Hide(); bindRotation2.Hide(); prevKeyframeLabel.Hide(); keyFrame1TimeLabel.Hide(); keyFrame1PositionLabel.Hide(); keyFrame1RotationLabel.Hide(); keyFrame1Time.Hide(); keyFrame1Position.Hide(); keyFrame1Rotation.Hide(); keyFrame1Rotation2.Hide(); nextKeyframeLabel.Hide(); keyFrame2TimeLabel.Hide(); keyFrame2PositionLabel.Hide(); keyFrame2RotationLabel.Hide(); keyFrame2Time.Hide(); keyFrame2Position.Hide(); keyFrame2Rotation.Hide(); keyFrame2Rotation2.Hide(); } }
private void SetupLighting() { scene.AmbientLight = new ColorEx(0.2f, 0.2f, 0.2f); Light = scene.CreateLight("Light2"); Light.DiffuseColour = MinLightColour; Light.SetAttenuation(8000, 1, 0.0005f, 0); Light.SpecularColour = new ColorEx(1, 1, 1); LightNode = scene.RootSceneNode.CreateChildSceneNode("MovingLightNode"); LightNode.AttachObject(Light); //create billboard set BillboardSet bbs = scene.CreateBillboardSet("lightbbs", 1); bbs.SetMaterialName("Examples/Flare"); Billboard bb = bbs.CreateBillboard(new Vector3(0, 0, 0), MinLightColour); LightNode.AttachObject(bbs); mLightController = new LightGrassWibbler(Light, bb, MinLightColour, this.MaxLightColour, MinFlareSize, MaxFlareSize); // create controller, after this is will get updated on its own //WaveformControllerFunction func = new WaveformControllerFunction(WaveformType.Sine, 0.0f, 0.5f); //ControllerManager.Instance.CreateController(val, func); LightNode.Position = new Vector3(300, 250, -300); Animation anim = scene.CreateAnimation("LightTrack", 20); //Spline it for nce curves anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE);// = Mogre.Animation.InterpolationMode.IM_SPLINE; //create a srtack to animte the camera's node NodeAnimationTrack track = anim.CreateNodeTrack(0, LightNode); //setup keyframes TransformKeyFrame key = track.CreateNodeKeyFrame(0); key.Translate = new Vector3(300, 550, -300); key = track.CreateNodeKeyFrame(2); //B key.Translate = new Vector3(150, 600, -250); key = track.CreateNodeKeyFrame(4); //C key.Translate = new Vector3(-150, 650, -100); key = track.CreateNodeKeyFrame(6); //D key.Translate = new Vector3(-400, 500, -200); key = track.CreateNodeKeyFrame(8); //E key.Translate = new Vector3(-200, 500, -400); key = track.CreateNodeKeyFrame(10); //F key.Translate = new Vector3(-100, 450, -200); key = track.CreateNodeKeyFrame(12); //G key.Translate = new Vector3(-100, 400, 180); key = track.CreateNodeKeyFrame(14); //H key.Translate = new Vector3(0, 250, 600); key = track.CreateNodeKeyFrame(16); //I key.Translate = new Vector3(100, 650, 100); key = track.CreateNodeKeyFrame(18); //J key.Translate = new Vector3(250, 600, 0); key = track.CreateNodeKeyFrame(20); //K == A key.Translate = new Vector3(300, 550, -300); // Create a new animation state to track this AnimState = scene.CreateAnimationState("LightTrack"); AnimState.Enabled = true; }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(NodeAnimationTrack obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
protected void CreateRibbons() { viewport.BackgroundColor = ColorEx.Black; float scale = 100f; scene.AmbientLight = new ColorEx(0.5f, 0.5f, 0.5f); //scene.SetSkyBox(true, "Examples/SpaceSkyBox", 20f * oneMeter); Vector3 dir = new Vector3(-1f, -1f, 0.5f); dir.Normalize(); Light light1 = scene.CreateLight("light1"); light1.Type = LightType.Directional; light1.Direction = dir; // Create a barrel for the ribbons to fly through Entity barrel = scene.CreateEntity("barrel", "barrel.mesh"); SceneNode barrelNode = scene.RootSceneNode.CreateChildSceneNode(); barrelNode.ScaleFactor = 5f * Vector3.UnitScale; barrelNode.AttachObject(barrel); RibbonTrail trail = new RibbonTrail("DemoTrail", "numberOfChains", 2, "maxElementsPerChain", 80); trail.MaterialName = "Examples/LightRibbonTrail"; trail.TrailLength = scale * 400f; scene.RootSceneNode.CreateChildSceneNode().AttachObject(trail); // Create 3 nodes for trail to follow SceneNode animNode = scene.RootSceneNode.CreateChildSceneNode(); animNode.Position = scale * new Vector3(50f, 30f, 0); Animation anim = scene.CreateAnimation("an1", 14); anim.InterpolationMode = InterpolationMode.Spline; NodeAnimationTrack track = anim.CreateNodeTrack(1, animNode); TransformKeyFrame kf = track.CreateNodeKeyFrame(0); kf.Translate = scale * new Vector3(50f, 30f, 0f); kf = track.CreateNodeKeyFrame(2); kf.Translate = scale * new Vector3(100f, -30f, 0f); kf = track.CreateNodeKeyFrame(4); kf.Translate = scale * new Vector3(120f, -100f, 150f); kf = track.CreateNodeKeyFrame(6); kf.Translate = scale * new Vector3(30f, -100f, 50f); kf = track.CreateNodeKeyFrame(8); kf.Translate = scale * new Vector3(-50f, 30f, -50f); kf = track.CreateNodeKeyFrame(10); kf.Translate = scale * new Vector3(-150f, -20f, -100f); kf = track.CreateNodeKeyFrame(12); kf.Translate = scale * new Vector3(-50f, -30f, 0f); kf = track.CreateNodeKeyFrame(14); kf.Translate = scale * new Vector3(50f, 30f, 0f); AnimationState animState = scene.CreateAnimationState("an1"); //animState.Enabled = true; animStateList = new List <AnimationState>(); animStateList.Add(animState); trail.SetInitialColor(0, 1.0f, 0.8f, 0f, 1.0f); trail.SetColorChange(0, 0.5f, 0.5f, 0.5f, 0.5f); trail.SetInitialWidth(0, scale * 5f); trail.AddNode(animNode); // Add light Light light2 = scene.CreateLight("light2"); light2.Diffuse = trail.GetInitialColor(0); animNode.AttachObject(light2); // Add billboard BillboardSet bbs = scene.CreateBillboardSet("bb", 1); bbs.CreateBillboard(Vector3.Zero, trail.GetInitialColor(0)); bbs.MaterialName = "flare"; animNode.AttachObject(bbs); animNode = scene.RootSceneNode.CreateChildSceneNode(); animNode.Position = scale * new Vector3(-50f, 100f, 0f); anim = scene.CreateAnimation("an2", 10); anim.InterpolationMode = InterpolationMode.Spline; track = anim.CreateNodeTrack(1, animNode); kf = track.CreateNodeKeyFrame(0); kf.Translate = scale * new Vector3(-50f, 100f, 0f); kf = track.CreateNodeKeyFrame(2); kf.Translate = scale * new Vector3(-100f, 150f, -30f); kf = track.CreateNodeKeyFrame(4); kf.Translate = scale * new Vector3(-200f, 0f, 40f); kf = track.CreateNodeKeyFrame(6); kf.Translate = scale * new Vector3(0f, -150f, 70f); kf = track.CreateNodeKeyFrame(8); kf.Translate = scale * new Vector3(50f, 0f, 30f); kf = track.CreateNodeKeyFrame(10); kf.Translate = scale * new Vector3(-50f, 100f, 0f); animState = scene.CreateAnimationState("an2"); //animState.setEnabled(true); animStateList.Add(animState); trail.SetInitialColor(1, 0.0f, 1.0f, 0.4f, 1.0f); trail.SetColorChange(1, 0.5f, 0.5f, 0.5f, 0.5f); trail.SetInitialWidth(1, scale * 5f); trail.AddNode(animNode); // Add light Light light3 = scene.CreateLight("l3"); light3.Diffuse = trail.GetInitialColor(1); animNode.AttachObject(light3); // Add billboard bbs = scene.CreateBillboardSet("bb2", 1); bbs.CreateBillboard(Vector3.Zero, trail.GetInitialColor(1)); bbs.MaterialName = "flare"; animNode.AttachObject(bbs); }
protected override void CreateScene() { // set some ambient light scene.AmbientLight = new ColorEx(1.0f, 0.2f, 0.2f, 0.2f); // create a skydome scene.SetSkyDome(true, "Examples/CloudySky", 5, 8); // create a simple default point light Light light = scene.CreateLight("MainLight"); light.Position = new Vector3(20, 80, 50); // create a plane for the plane mesh Plane plane = new Plane(); plane.Normal = Vector3.UnitY; plane.D = 200; // create a plane mesh MeshManager.Instance.CreatePlane("FloorPlane", plane, 200000, 200000, 20, 20, true, 1, 50, 50, Vector3.UnitZ); // create an entity to reference this mesh Entity planeEntity = scene.CreateEntity("Floor", "FloorPlane"); planeEntity.MaterialName = "Examples/RustySteel"; scene.RootSceneNode.CreateChildSceneNode().AttachObject(planeEntity); // create an entity to have follow the path Entity ogreHead = scene.CreateEntity("OgreHead", "ogrehead.mesh"); // create a scene node for the entity and attach the entity headNode = scene.RootSceneNode.CreateChildSceneNode("OgreHeadNode", Vector3.Zero, Quaternion.Identity); headNode.AttachObject(ogreHead); // make sure the camera tracks this node camera.SetAutoTracking(true, headNode, Vector3.Zero); // create a scene node to attach the camera to SceneNode cameraNode = scene.RootSceneNode.CreateChildSceneNode("CameraNode"); cameraNode.AttachObject(camera); // create new animation Animation animation = scene.CreateAnimation("OgreHeadAnimation", 10.0f); // nice smooth animation animation.InterpolationMode = InterpolationMode.Spline; // create the main animation track NodeAnimationTrack track = animation.CreateNodeTrack(0, cameraNode); // create a few keyframes to move the camera around AddKey(track, 0.0f, Vector3.Zero); AddKey(track, 2.5f, new Vector3(500, 500, -1000)); AddKey(track, 5.0f, new Vector3(-1500, 1000, -600)); AddKey(track, 7.5f, new Vector3(0, -100, 0)); AddKey(track, 10.0f, Vector3.Zero); // create a new animation state to control the animation animationState = scene.CreateAnimationState("OgreHeadAnimation"); // enable the animation animationState.IsEnabled = true; // turn on some fog scene.SetFog(FogMode.Exp, ColorEx.White, 0.0002f); }
public static void CleanupAnimation(Skeleton skel, Animation anim) { Animation newAnim = skel.CreateAnimation("_replacement", anim.Length); Animation tmpAnim = skel.CreateAnimation("_temporary", anim.Length); foreach (NodeAnimationTrack track in anim.NodeTracks.Values) { Bone bone = skel.GetBone((ushort)track.Handle); NodeAnimationTrack newTrack = newAnim.CreateNodeTrack(track.Handle, bone); NodeAnimationTrack tmpTrack = tmpAnim.CreateNodeTrack(track.Handle, bone); int maxFrame = track.KeyFrames.Count; int lastKeyFrame = -1; for (int keyFrameIndex = 0; keyFrameIndex < track.KeyFrames.Count; ++keyFrameIndex) { if (anim.InterpolationMode == InterpolationMode.Linear) { // Linear is based on one point before and one after. TransformKeyFrame cur = track.GetTransformKeyFrame(keyFrameIndex); if (keyFrameIndex == 0 || keyFrameIndex == (track.KeyFrames.Count - 1)) { // Add the key frame if it is the first or last keyframe. lastKeyFrame = keyFrameIndex; DuplicateKeyFrame(newTrack, cur); } else { // Make sure tmpTrack is clean.. we just use it for interpolation tmpTrack.RemoveAllKeyFrames(); TransformKeyFrame prior = track.GetTransformKeyFrame(lastKeyFrame); TransformKeyFrame next = track.GetTransformKeyFrame(keyFrameIndex + 1); DuplicateKeyFrame(tmpTrack, prior); DuplicateKeyFrame(tmpTrack, next); // Check to see if removing this last keyframe will throw off // any of the other keyframes that were considered redundant. bool needKeyFrame = false; for (int i = lastKeyFrame + 1; i <= keyFrameIndex; ++i) { TransformKeyFrame orig = track.GetTransformKeyFrame(i); TransformKeyFrame interp = new TransformKeyFrame(tmpTrack, orig.Time); tmpTrack.GetInterpolatedKeyFrame(orig.Time, interp); // Is this interpolated frame useful or redundant? if (!CompareKeyFrames(interp, cur)) { needKeyFrame = true; break; } } if (needKeyFrame) { lastKeyFrame = keyFrameIndex; DuplicateKeyFrame(newTrack, cur); } } } else if (anim.InterpolationMode == InterpolationMode.Spline) { // Spline is based on two points before and two after. TransformKeyFrame cur = track.GetTransformKeyFrame(keyFrameIndex); #if DISABLED_CODE if (keyFrameIndex == 0 || keyFrameIndex == 1 || keyFrameIndex == (track.KeyFrames.Count - 1) || keyFrameIndex == (track.KeyFrames.Count - 2)) { // Add the key frame if it is the first, second, last or second to last keyframe. DuplicateKeyFrame(newTrack, cur); } else { // Make sure tmpTrack is clean.. we just use it for interpolation tmpTrack.RemoveAllKeyFrames(); TransformKeyFrame prior1 = track.GetTransformKeyFrame(keyFrameIndex - 2); TransformKeyFrame prior2 = track.GetTransformKeyFrame(keyFrameIndex - 1); TransformKeyFrame next1 = track.GetTransformKeyFrame(keyFrameIndex + 1); TransformKeyFrame next2 = track.GetTransformKeyFrame(keyFrameIndex + 2); DuplicateKeyFrame(tmpTrack, prior1); DuplicateKeyFrame(tmpTrack, prior2); DuplicateKeyFrame(tmpTrack, next1); DuplicateKeyFrame(tmpTrack, next2); TransformKeyFrame interp = new TransformKeyFrame(tmpTrack, cur.Time); tmpTrack.GetInterpolatedKeyFrame(cur.Time, interp); // Is this interpolated frame useful or redundant? if (!CompareKeyFrames(interp, cur)) { DuplicateKeyFrame(newTrack, cur); } } #else DuplicateKeyFrame(newTrack, cur); #endif } else { System.Diagnostics.Debug.Assert(false, "Invalid InterpolationMode: " + anim.InterpolationMode); } } } skel.RemoveAnimation(tmpAnim.Name); skel.RemoveAnimation(newAnim.Name); skel.RemoveAnimation(anim.Name); // Recreate the animation with the proper name (awkward) anim = skel.CreateAnimation(anim.Name, anim.Length); foreach (NodeAnimationTrack track in newAnim.NodeTracks.Values) { Bone bone = skel.GetBone((ushort)track.Handle); NodeAnimationTrack newTrack = anim.CreateNodeTrack(track.Handle, bone); foreach (KeyFrame keyFrame in track.KeyFrames) { DuplicateKeyFrame(newTrack, (TransformKeyFrame)keyFrame); } } }
// Just override the mandatory create scene method protected override void CreateScene() { RAND = new Random(0); // najak: use a time-based seed GuiMgr = OverlayElementManager.Instance; scene.AmbientLight = new ColorEx(0.75f, 0.75f, 0.75f); // default Ambient Light // Customize Controls - speed up camera and slow down the input update rate this.camSpeed = 5.0f; inputInterval = inputTimer = 0.02f; // Create water mesh and entity, and attach to sceneNode waterMesh = new WaterMesh("WaterMesh", PLANE_SIZE, CMPLX); waterEntity = scene.CreateEntity("WaterEntity", "WaterMesh"); SceneNode waterNode = scene.RootSceneNode.CreateChildSceneNode(); waterNode.AttachObject(waterEntity); // Add Ogre head, give it it's own node headNode = waterNode.CreateChildSceneNode(); Entity ent = scene.CreateEntity("head", "ogrehead.mesh"); headNode.AttachObject(ent); // Create the camera node, set its position & attach camera camera.Yaw(-45f); camera.Move(new Vector3(1500f, 700f, PLANE_SIZE + 700f)); camera.LookAt(new Vector3(PLANE_SIZE / 2f, 300f, PLANE_SIZE / 2f)); camera.SetAutoTracking(false, headNode); // Autotrack the head, but it isn't working right //scene.SetFog(FogMode.Exp, ColorEx.White, 0.000020f); // add Fog for fun, cuz we can // show overlay waterOverlay = (Overlay)OverlayManager.Instance.GetByName("Example/WaterOverlay"); waterOverlay.Show(); // Create Rain Emitter, but default Rain to OFF particleSystem = ParticleSystemManager.Instance.CreateSystem("rain", "Examples/Water/Rain"); particleEmitter = particleSystem.GetEmitter(0); particleEmitter.EmissionRate = 0f; // Attach Rain Emitter to SceneNode, and place it 3000f above the water surface SceneNode rNode = scene.RootSceneNode.CreateChildSceneNode(); rNode.Translate(new Vector3(PLANE_SIZE / 2.0f, 3000, PLANE_SIZE / 2.0f)); rNode.AttachObject(particleSystem); particleSystem.FastForward(20); // Fastforward rain to make it look natural // It can't be set in .particle file, and we need it ;) particleSystem.BillboardOrigin = BillboardOrigin.BottomCenter; // Set Lighting lightNode = scene.RootSceneNode.CreateChildSceneNode(); lightSet = scene.CreateBillboardSet("Lights", 20); lightSet.MaterialName = "Particles/Flare"; lightNode.AttachObject(lightSet); SetLighting("Ambient"); // Add Lights - added by Najak to show lighted Water conditions - cool! #region STUBBED LIGHT ANIMATION // Create a new animation state to track this // TODO: Light Animation not working. //this.animState = scene.CreateAnimationState("WaterLight"); //this.animState.Time = 0f; //this.animState.IsEnabled = false; // set up spline animation of light node. Create random Spline Animation anim = scene.CreateAnimation("WaterLight", 20); NodeAnimationTrack track = anim.CreateNodeTrack(0, this.lightNode); TransformKeyFrame key = (TransformKeyFrame)track.CreateKeyFrame(0); for (int ff = 1; ff <= 19; ff++) { key = (TransformKeyFrame)track.CreateKeyFrame(ff); Random rand = new Random(0); Vector3 lpos = new Vector3( (float)rand.NextDouble() % (int)PLANE_SIZE, //- PLANE_SIZE/2, (float)rand.NextDouble() % 300 + 100, (float)rand.NextDouble() % (int)PLANE_SIZE); //- PLANE_SIZE/2 key.Translate = lpos; } key = (TransformKeyFrame)track.CreateKeyFrame(20); #endregion STUBBED LIGHT ANIMATION // Initialize the Materials/Demo UpdateMaterial(); UpdateInfoParamC(); UpdateInfoParamD(); UpdateInfoParamU(); UpdateInfoParamT(); UpdateInfoNormals(); UpdateInfoHeadDepth(); UpdateInfoSkyBox(); UpdateInfoHeadSpeed(); UpdateInfoLights(); UpdateInfoTracking(); // Init Head Animation: Load adds[] elements - Ogre head animation adds[0] = 0.3f; adds[1] = -1.6f; adds[2] = 1.1f; adds[3] = 0.5f; sines[0] = 0; sines[1] = 100; sines[2] = 200; sines[3] = 300; } // end CreateScene()
void setupLighting() { /****/ // Set ambient light mSceneManager.SetAmbientLight(Converter.GetColor(0.2f, 0.2f, 0.2f)); // Point light, movable, reddish mLight = mSceneManager.CreateLight("Light2"); mLight.SetDiffuseColour(mMinLightColour); mLight.SetSpecularColour(1.0f, 1.0f, 1.0f); mLight.SetAttenuation(8000.0f, 1.0f, 0.0005f, 0.0f); // Create light node mLightNode = mSceneManager.GetRootSceneNode().CreateChildSceneNode("MovingLightNode"); mLightNode.AttachObject(mLight); // create billboard set BillboardSet bbs = mSceneManager.CreateBillboardSet("lightbbs", 1); bbs.SetMaterialName("Examples/Flare"); Billboard bb = bbs.CreateBillboard(0, 0, 0, mMinLightColour); // attach mLightNode.AttachObject(bbs); // create controller, after this is will get updated on its own mWFCF = new WaveformControllerFunction(WaveformType.Sine, 0.0f, 0.5f); mCFFPtr = new ControllerFunctionFloatPtr(mWFCF); mLightWibbler = new LightWibbler(mLight, bb, mMinLightColour, mMaxLightColour, mMinFlareSize, mMaxFlareSize); mCVFPtr = new ControllerValueFloatPtr(mLightWibbler.mCVFH); ControllerManager contMgr = ControllerManager.GetSingleton(); mLightCtlFlt = contMgr.CreateController(contMgr.GetFrameTimeSource(), mCVFPtr, mCFFPtr); mLightNode.SetPosition(new Vector3(300, 250, -300)); // Create a track for the light Animation anim = mSceneManager.CreateAnimation("LightTrack", 20.0f); // Spline it for nice curves anim.SetInterpolationMode(Animation.InterpolationMode.Spline); // Create a track to animate the camera's node NodeAnimationTrack track = anim.CreateNodeTrack(0, mLightNode); // Setup keyframes TransformKeyFrame key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(0.0f)).Handle, false); // A startposition key.SetTranslate(new Vector3(300.0f, 550.0f, -300.0f)); key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(2.0f)).Handle, false); //B key.SetTranslate(new Vector3(150.0f, 600.0f, -250.0f)); key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(4.0f)).Handle, false); //C key.SetTranslate(new Vector3(-150.0f, 650.0f, -100.0f)); key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(6.0f)).Handle, false); //D key.SetTranslate(new Vector3(-400.0f, 500.0f, -200.0f)); key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(8.0f)).Handle, false); //E key.SetTranslate(new Vector3(-200.0f, 500.0f, -400.0f)); key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(10.0f)).Handle, false); //F key.SetTranslate(new Vector3(-100.0f, 450.0f, -200.0f)); key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(12.0f)).Handle, false); //G key.SetTranslate(new Vector3(-100.0f, 400.0f, 180.0f)); key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(14.0f)).Handle, false); //H key.SetTranslate(new Vector3(0.0f, 250.0f, 600.0f)); key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(16.0f)).Handle, false); //I key.SetTranslate(new Vector3(100.0f, 650.0f, 100.0f)); key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(18.0f)).Handle, false); //J key.SetTranslate(new Vector3(250.0f, 600.0f, 0.0f)); key = new TransformKeyFrame(KeyFrame.getCPtr(track.CreateKeyFrame(20.0f)).Handle, false); //K == A key.SetTranslate(new Vector3(300.0f, 550.0f, -300.0f)); // Create a new animation state to track this mAnimState = mSceneManager.CreateAnimationState("LightTrack"); mAnimState.SetEnabled(true); /****/ }
protected override void CreateScene() { // Set ambient light sceneMgr.AmbientLight = new ColourValue(0.75f, 0.75f, 0.75f); // Create a light Light l = sceneMgr.CreateLight("MainLight"); // Accept default settings: point light, white diffuse, just set position // NB I could attach the light to a SceneNode if I wanted it to move automatically with // other objects, but I don't l.Position = new Vector3(200, 700, 100); sceneMgr.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE; // Create a skydome sceneMgr.SetSkyDome(true, "Examples/CloudySky", 30, 5); // Put in a bit of fog for the hell of it sceneMgr.SetFog(FogMode.FOG_EXP, ColourValue.White, 0.0001f, 0.5f); // Define a floor plane mesh Plane p = new Plane(); p.normal = Vector3.UNIT_Y; p.d = 180; MeshManager.Singleton.CreatePlane("FloorPlane", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, p, PLANE_SIZE * 1000, PLANE_SIZE * 1000, 20, 20, true, 1, 50, 50, Vector3.UNIT_Z); Entity ent = sceneMgr.CreateEntity("floorEntity", "FloorPlane"); ent.SetMaterialName("Examples/RustySteel"); ent.CastShadows = false; SceneNode floorNode = sceneMgr.RootSceneNode.CreateChildSceneNode("floorSceneNode"); floorNode.AttachObject(ent); // Add a head, give it it's own node // The Ogre head faces to Z headNode = sceneMgr.RootSceneNode.CreateChildSceneNode("headSceneNode"); ent = sceneMgr.CreateEntity("head", "ogrehead.mesh"); ent.CastShadows = true; headNode.AttachObject(ent); atheneNode = sceneMgr.RootSceneNode.CreateChildSceneNode("atheneSceneNode"); //Entity *Athene = mSceneMgr->createEntity( "Razor", "razor.mesh" ); Entity Athene = sceneMgr.CreateEntity("Athene", "athene.mesh"); Athene.SetMaterialName("Examples/Athene/NormalMapped"); Athene.CastShadows = true; atheneNode.AttachObject(Athene); atheneNode.SetPosition(500, -100, 500); // Obstacle for collisions detection SceneNode barrelNode = sceneMgr.RootSceneNode.CreateChildSceneNode("barrelSceneNode"); Entity barrel = sceneMgr.CreateEntity("barrel", "barrel.mesh"); barrel.CastShadows = true; barrelNode.AttachObject(barrel); barrelNode.SetPosition(1300, -100, 500); barrelNode.SetScale(40, 40, 40); // Create light node SceneNode lightNode = sceneMgr.RootSceneNode.CreateChildSceneNode("lightSceneNode"); lightNode.AttachObject(l); goto cameraControl; // set up spline animation of node Animation anim = sceneMgr.CreateAnimation("HeadTrack", 20); // Spline it for nice curves anim.SetInterpolationMode(Mogre.Animation.InterpolationMode.IM_SPLINE); // Create a track to animate the camera's node NodeAnimationTrack track = anim.CreateNodeTrack(0, headNode); // Setup keyframes TransformKeyFrame key = track.CreateNodeKeyFrame(0); // startposition key.Translate = new Vector3(0, 0, 0); key.Rotation = Quaternion.IDENTITY; key = track.CreateNodeKeyFrame(2.5f); key.Translate = new Vector3(0, 0, 1000); key.Rotation = Vector3.UNIT_Z.GetRotationTo(new Vector3(1000, 0, 1000)); key = track.CreateNodeKeyFrame(5); key.Translate = new Vector3(1000, 0, 1000); key.Rotation = Vector3.UNIT_Z.GetRotationTo(new Vector3(1000, 0, 0)); key = track.CreateNodeKeyFrame(7.5f); key.Translate = new Vector3(1000, 0, 0); key.Rotation = Vector3.UNIT_Z.GetRotationTo(Vector3.NEGATIVE_UNIT_X); key = track.CreateNodeKeyFrame(10); key.Translate = new Vector3(0, 0, 0); // Second round key = track.CreateNodeKeyFrame(11); key.Translate = new Vector3(0, 0, 400); key.Rotation = new Quaternion(new Radian(3.14f / 4.0f), Vector3.UNIT_Z); key = track.CreateNodeKeyFrame(11.5f); key.Translate = new Vector3(0, 0, 600); key.Rotation = new Quaternion(new Radian(-3.14f / 4.0f), Vector3.UNIT_Z); key = track.CreateNodeKeyFrame(12.5f); key.Translate = new Vector3(0, 0, 1000); key.Rotation = Vector3.UNIT_Z.GetRotationTo(new Vector3(500, 500, 1000)); key = track.CreateNodeKeyFrame(13.25f); key.Translate = new Vector3(500, 500, 1000); key.Rotation = Vector3.UNIT_Z.GetRotationTo(new Vector3(1000, -500, 1000)); key = track.CreateNodeKeyFrame(15); key.Translate = new Vector3(1000, 0, 1000); key.Rotation = Vector3.UNIT_Z.GetRotationTo(new Vector3(1000, 0, -500)); key = track.CreateNodeKeyFrame(16); key.Translate = new Vector3(1000, 0, 500); key = track.CreateNodeKeyFrame(16.5f); key.Translate = new Vector3(1000, 0, 600); key = track.CreateNodeKeyFrame(17.5f); key.Translate = new Vector3(1000, 0, 0); key.Rotation = Vector3.UNIT_Z.GetRotationTo(new Vector3(-500, 500, 0)); key = track.CreateNodeKeyFrame(118.25f); key.Translate = new Vector3(500, 500, 0); key.Rotation = new Quaternion(new Radian(3.14f), Vector3.UNIT_X) * Vector3.UNIT_Z.GetRotationTo(new Vector3(-500, -500, 0)); key = track.CreateNodeKeyFrame(20); key.Translate = new Vector3(0, 0, 0); key = track.CreateNodeKeyFrame(2000); key.Translate = new Vector3(-20000000, 0, 0); // Create a new animation state to track this mAnimState = sceneMgr.CreateAnimationState("HeadTrack"); mAnimState.Enabled = true; cameraControl :; setupCameraControlSystem(); }
// Scene creation public override void CreateScene() { // Set ambient light sceneMgr.AmbientLight = new ColourValue(0.2F, 0.2F, 0.2F); // Create a skydome sceneMgr.SetSkyDome(true, "Examples/CloudySky", 5, 8); // Create a light Light l = sceneMgr.CreateLight("MainLight"); // Accept default settings: point light, white diffuse, just set position // NB I could attach the light to a SceneNode if I wanted it to move automatically with // other objects, but I don't l.Position = new Vector3(20F, 80F, 50F); // Define a floor plane mesh Plane p; p.normal = Vector3.UNIT_Y; p.d = 200; MeshManager.Singleton.CreatePlane("FloorPlane", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, p, 200000F, 20000F, 20, 20, true, 1, 50F, 50F, Vector3.UNIT_Z); Entity ent; // Create an entity (the floor) ent = sceneMgr.CreateEntity("floor", "FloorPlane"); ent.SetMaterialName("Examples/RustySteel"); // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2) sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent); // Add a head, give it it's own node SceneNode headNode = sceneMgr.RootSceneNode.CreateChildSceneNode(); ent = sceneMgr.CreateEntity("head", "ogrehead.mesh"); headNode.AttachObject(ent); // Make sure the camera track this node camera.SetAutoTracking(true, headNode); // Create the camera node & attach camera SceneNode camNode = sceneMgr.RootSceneNode.CreateChildSceneNode(); camNode.AttachObject(camera); // set up spline animation of node Animation anim = sceneMgr.CreateAnimation("CameraTrack", 10F); // Spline it for nice curves anim.SetInterpolationMode(Animation.InterpolationMode.IM_SPLINE); // Create a track to animate the camera's node NodeAnimationTrack track = anim.CreateNodeTrack(0, camNode); // Setup keyframes TransformKeyFrame key = track.CreateNodeKeyFrame(0F); // startposition key = track.CreateNodeKeyFrame(2.5F); key.Translate = new Vector3(500F, 500F, -1000F); key = track.CreateNodeKeyFrame(5F); key.Translate = new Vector3(-1500F, 1000F, -600F); key = track.CreateNodeKeyFrame(7.5F); key.Translate = new Vector3(0F, 100F, 0F); key = track.CreateNodeKeyFrame(10F); key.Translate = new Vector3(0F, 0F, 0F); // Create a new animation state to track this animState = sceneMgr.CreateAnimationState("CameraTrack"); animState.Enabled = true; // Put in a bit of fog for the hell of it sceneMgr.SetFog(FogMode.FOG_EXP, ColourValue.White, 0.0002F); }