public PlayerModel(Game1 game, SkinnedModel skinnedModel) : base(game, skinnedModel) { game.mediator.register(this, MyEvent.P_RUN, MyEvent.C_ATTACK_BULLET_BEGIN); animationController.Speed = 1.2f; activeAnimation = PlayerAnimations.Idle; playAnimation(); }
private Player initializePlayer() { SkinnedModel pmodel = Content.Load <SkinnedModel>(@"model/PlayerMarine"); //SkinningData skinnedData = pmodel.Tag as SkinningData; PlayerUnit playerUnit = new PlayerUnit(this, new Vector3(-5, GetHeightAtPosition(5, -5) + 5, 5), new Vector3(0, 0, 0), Constants.PLAYER_SCALE); Player player = new Player(this, pmodel, playerUnit); return(player); }
/// <summary> /// Loads the model. /// </summary> /// <param name="factory">The factory.</param> /// <param name="BatchInformations">The batch informations.</param> /// <param name="TextureInformations">The texture informations.</param> protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations) { skinnedModel = factory.GetAnimatedModel(Name); ModelBuilderHelper.Extract(factory, out BatchInformations, out TextureInformations, skinnedModel.Model, _diffuseName, _bumpName, _specularName, _glowName, isInternal); BoundingSphere sphere = new BoundingSphere(); foreach (var item in skinnedModel.Model.Meshes) { sphere = BoundingSphere.CreateMerged(sphere, item.BoundingSphere); } modelRadius = sphere.Radius; }
/// <summary> /// Reads a .fbx file and creates the triangle mesh out of it. /// </summary> /// <param name="fileName">Path to the .fbx file.</param> /// <param name="content">ContentManager used to load .fbx files.</param> private void createFromFBX(string fileName, ContentManager content) { _model = content.Load<SkinnedModel>(fileName); _vertices = new FBXVertexFormat[_model.Meshes[0].Vertices.VertexCount]; _indices = new int[_model.Meshes[0].Indices.IndexCount]; _model.Meshes[0].Vertices.GetData<FBXVertexFormat>(_vertices); _model.Meshes[0].Indices.GetData<int>(_indices); for (int i = 0; i < _vertices.Length; ++i) { _vertices[i].normal.Normalize(); } }
public Monster(Game1 game, SkinnedModel skinnedModel, Unit unit) : base(game, unit, new MonsterModel(game, skinnedModel)) { monsterModel = ((MonsterModel)cModel); monsterUnit = ((MonsterUnit)unit); foreach (ModelMesh mesh in skinnedModel.Model.Meshes) { foreach (SkinnedEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); } } }
public MonstersManager(Game1 game) : base(game) { monsters = new List <Monster>(); myGame = game; rnd = new Random(); hpBillBoardSystem = new HPBillboardSystem(game.GraphicsDevice, game.Content, Constants.HP_SIZE, monsters); //skinnedModel = Game.Content.Load<SkinnedModel>(@"Textures\EnemyBeast"); skinnedModel = Game.Content.Load <SkinnedModel>(@"model\EnemyBeast"); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); spriteFont = Content.Load <SpriteFont>("Fonts\\Arial"); // Load the skinned model skinnedModel = Content.Load <SkinnedModel>("Models\\test_stickmanM"); foreach (ModelMesh mesh in skinnedModel.Model.Meshes) { foreach (SkinnedEffect effect in mesh.Effects) { /* * // texture can be changed: * Texture2D axe = Content.Load<Texture2D>("Textures\\axe"); * Texture2D dwarf = Content.Load<Texture2D>("Textures\\dwarf"); * effect.Texture = dwarf; * if (mesh.Name == "axe") * { * effect.Texture = axe; * } */ effect.EnableDefaultLighting(); effect.SpecularColor = new Vector3(0.25f); effect.SpecularPower = 16; } } // Create an animation controller and start a clip animationController = new AnimationController(skinnedModel.SkeletonBones); animationController.Speed = 0.5f; animationController.TranslationInterpolation = InterpolationMode.Linear; animationController.OrientationInterpolation = InterpolationMode.Linear; animationController.ScaleInterpolation = InterpolationMode.Linear; //animationController.StartClip(skinnedModel.AnimationClips["Take 001"]); activeAnimationClip = 2; // "UkkoArmature|Idle" animationController.StartClip(skinnedModel.AnimationClips.Values[activeAnimationClip]); // Set up the camera. view = Matrix.CreateLookAt(new Vector3(100, 100, 500), new Vector3(0, 30, 0), Vector3.Up); projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 1280 / 720, 1, 1000); }
private void reinitialize2(SkinnedModel skinnedModel) { this.skinnedModel = skinnedModel; //setNewEffect(); // Create an animation controller and start a clip animationController = new AnimationController(skinnedModel.SkeletonBones); animationController.Speed = 0.5f; animationController.TranslationInterpolation = InterpolationMode.Linear; animationController.OrientationInterpolation = InterpolationMode.Linear; animationController.ScaleInterpolation = InterpolationMode.Linear; //animationController.StartClip(skinnedModel.AnimationClips[animation]); }
public void SetModel(SkinnedModel model) { PreviewActor.SkinnedModel = model; PreviewActor.AnimationGraph = null; Object.Destroy(ref _animGraph); if (!model) { return; } // Use virtual animation graph to playback the animation _animGraph = FlaxEngine.Content.CreateVirtualAsset <AnimationGraph>(); _animGraph.InitAsAnimation(model, _window.Asset); PreviewActor.AnimationGraph = _animGraph; }
private int ComputeLODIndex(SkinnedModel model) { if (PreviewActor.ForcedLOD != -1) { return(PreviewActor.ForcedLOD); } // Based on RenderTools::ComputeModelLOD CreateProjectionMatrix(out var projectionMatrix); float screenMultiple = 0.5f * Mathf.Max(projectionMatrix.M11, projectionMatrix.M22); var sphere = PreviewActor.Sphere; var viewOrigin = ViewPosition; float distSqr = Vector3.DistanceSquared(ref sphere.Center, ref viewOrigin); var screenRadiusSquared = Mathf.Square(screenMultiple * sphere.Radius) / Mathf.Max(1.0f, distSqr); // Check if model is being culled if (Mathf.Square(model.MinScreenSize * 0.5f) > screenRadiusSquared) { return(-1); } // Skip if no need to calculate LOD if (model.LoadedLODs == 0) { return(-1); } var lods = model.LODs; if (lods.Length == 0) { return(-1); } if (lods.Length == 1) { return(0); } // Iterate backwards and return the first matching LOD for (int lodIndex = lods.Length - 1; lodIndex >= 0; lodIndex--) { if (Mathf.Square(lods[lodIndex].ScreenSize * 0.5f) >= screenRadiusSquared) { return(lodIndex + PreviewActor.LODBias); } } return(0); }
public void LoadSkinnedModel(String path, String modelName) { try { SkinnedModel mdl = new SkinnedModel(); mdl.GraphicsDevice = graphicsDevice; mdl.FilePath = path + "/" + modelName + ".fbx"; mdl.Initialize(); CRender.Instance.dSkinnedModelDict.Add(modelName, mdl); } catch (ContentLoadException e) { CRender.Instance.dSkinnedModelDict.Add(modelName, null); CConsole.Instance.Print("Tried to load skinned model " + modelName + " but failed, error " + e.ToString()); } }
public AnimatedModel(Game1 game, SkinnedModel skinnedModel) : base(game, skinnedModel.Model) { this.skinnedModel = skinnedModel; //setNewEffect(); // Create an animation controller and start a clip animationController = new AnimationController(skinnedModel.SkeletonBones); animationController.Speed = 0.5f; animationController.TranslationInterpolation = InterpolationMode.Linear; animationController.OrientationInterpolation = InterpolationMode.Linear; animationController.ScaleInterpolation = InterpolationMode.Linear; //animationController.StartClip(skinnedModel.AnimationClips[animation]); }
private SkinnedModel CreateVirtualModel(SkinnedModel skinnedModel) { if (!skinnedModel || skinnedModel.Skeleton == null) { return(null); } SkinnedModel virtualModel = Content.CreateVirtualAsset <SkinnedModel>(); virtualModel.Skeleton = skinnedModel.Skeleton; virtualModel.SetupMaterialSlots(skinnedModel.MaterialSlotsCount); for (int i = 0; i < virtualModel.MaterialSlotsCount; i++) { virtualModel.MaterialSlots[i].Material = skinnedModel.MaterialSlots[i].Material; virtualModel.MaterialSlots[i].Name = skinnedModel.MaterialSlots[i].Name; virtualModel.MaterialSlots[i].ShadowsMode = skinnedModel.MaterialSlots[i].ShadowsMode; } virtualModel.SetupMeshes(skinnedModel.MeshesCount); for (int i = 0; i < virtualModel.MeshesCount; i++) { virtualModel.Meshes[i].MaterialSlotIndex = skinnedModel.Meshes[i].MaterialSlotIndex; int[] indices = skinnedModel.Meshes[i].DownloadIndexBuffer(); var vertices = skinnedModel.Meshes[i].DownloadVertexBuffer(); Vector3[] positions = new Vector3[vertices.Length]; Int4[] blendIndices = new Int4[vertices.Length]; Vector4[] blendWeights = new Vector4[vertices.Length]; Vector3[] normals = new Vector3[vertices.Length]; Vector3[] tangents = new Vector3[vertices.Length]; Vector2[] uv = new Vector2[vertices.Length]; for (int j = 0; j < vertices.Length; j++) { positions[j] = vertices[j].Position; blendIndices[j] = vertices[j].BlendIndices; blendWeights[j] = vertices[j].BlendWeights; normals[j] = vertices[j].Normal; tangents[j] = vertices[j].Tangent; uv[j] = vertices[j].TexCoord; } virtualModel.Meshes[i].UpdateMesh(positions, indices, blendIndices, blendWeights, normals, tangents, uv); } return(virtualModel); }
public Player(Game1 game, SkinnedModel skinnedModel, Unit unit) : base(game, unit, new PlayerModel(game, skinnedModel)) { foreach (ModelMesh mesh in skinnedModel.Model.Meshes) { foreach (SkinnedEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); } } spriteBatch = new SpriteBatch(game.GraphicsDevice); crossHairTex = game.Content.Load <Texture2D>("crosshair"); delayedAction = new DelayedAction(800); //run at first to show to the character otherwise the character dont show playerRun(); }
public void LoadContent(ContentManager content) { if (_modelName.Contains(".xnb") || _modelName.Contains(".fbx")) { _modelName.Replace(".xnb", ""); _modelName.Replace(".fbx", ""); } if (_modelName.Contains("Models")) { skinnedModel = content.Load <SkinnedModel>(_modelName.Replace(".xnb", "")); } else { skinnedModel = content.Load <SkinnedModel>("Models\\" + _modelName.Replace(".xnb", "")); } animationController = new AnimationController(skinnedModel.SkeletonBones); foreach (ModelMesh mesh in skinnedModel.Model.Meshes) { foreach (SkinnedEffect effect in mesh.Effects) { if (_textures != null) { effect.Texture = _textures[0]; } effect.EnableDefaultLighting(); effect.SpecularColor = new Vector3(_specColor); effect.SpecularPower = _specPower; } } // Create an animation controller and start a clip animationController.Speed = _animationSpeed; animationController.TranslationInterpolation = InterpolationMode.Linear; animationController.OrientationInterpolation = InterpolationMode.Linear; animationController.ScaleInterpolation = InterpolationMode.Linear; animationController.LoopEnabled = _isLooped; _modelTransforms = new Matrix[skinnedModel.Model.Bones.Count]; skinnedModel.Model.CopyAbsoluteBoneTransformsTo(_modelTransforms); }
private void Start() { if (SavedModel) { Actor.SkinnedModel = SavedModel; } else { if (Actor.SkinnedModel) { Actor.SkinnedModel.WaitForLoaded(); var temp = Actor.SkinnedModel; //Actor.SkinnedModel = null; VirtualModel = CreateVirtualModel(temp); //Actor.SkinnedModel = temp; SetBones(); } } }
public SkinnedModel CreateSkinnedModel(IXNAGame game, ColladaModel _colladaModel) { SkinnedModel ret; colladaModel = _colladaModel; skinnedModel = new SkinnedModel(game); ret = skinnedModel; skinnedModel.FrameRate = colladaModel.frameRate; skinnedModel.numOfAnimations = colladaModel.numOfAnimations; LoadMeshes(); LoadBones(); // Clean up for possible next creation colladaModel = null; skinnedModel = null; return(ret); }
public void SetAnimationController(AnimationController ac, SkinnedModel model) { this.animationController = ac; this.animationController.StartClip(model.AnimationClips["Take 001"]); }
public MonsterModel(Game1 game, SkinnedModel skinnedModel) : base(game, skinnedModel) { animationController.StartClip(skinnedModel.AnimationClips[animations[(int)MonsterAnimations.Idle]]); //animationController.CrossFade(skinnedModel.AnimationClips.Values[0], TimeSpan.FromSeconds(0.05f)); }
public virtual void reinitialize(SkinnedModel skinnedModel) { base.reinitialize(skinnedModel.Model); reinitialize2(skinnedModel); }
public override bool Init() { if (!base.Init()) { return(false); } Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _texMgr = new TextureManager(); _texMgr.Init(Device); _drone = new SkinnedModel(Device, _texMgr, "Models/drone.x", "Textures", true); _droneInstance = new SkinnedModelInstance( "Attack", Matrix.RotationY(MathF.PI), _drone ); foreach (var clip in _droneInstance.Clips) { _droneInstance.AddClip(clip); } _droneInstance.LoopClips = true; _mage = new SkinnedModel(Device, _texMgr, "Models/magician.x", "textures", true); _mageInstance = new SkinnedModelInstance( "Attack", Matrix.RotationY(MathF.PI) * Matrix.Translation(4.0f, 0, 0), _mage ); foreach (var clip in _mageInstance.Clips) { _mageInstance.AddClip(clip); } _mageInstance.LoopClips = true; _soldier = new SkinnedModel(Device, _texMgr, "Models/soldier.x", "Textures", true); _soldierInstance = new SkinnedModelInstance( "Attack", Matrix.RotationY(MathF.PI) * Matrix.Translation(10, 0, 0), _soldier ); foreach (var clip in _soldierInstance.Clips) { _soldierInstance.AddClip(clip); } _soldierInstance.LoopClips = true; _grid = new BasicModel(); _grid.CreateGrid(Device, 30, 30, 60, 60); _grid.DiffuseMapSRV[0] = (_texMgr.CreateTexture("Textures/floor.dds")); _grid.NormalMapSRV[0] = (_texMgr.CreateTexture("Textures/floor_nmap.dds")); _gridInstance = new BasicModelInstance(_grid) { World = Matrix.Translation(0, -1.5f, 0) }; return(true); }
public AnimatedModel(MyGame game, SkinnedModel skinnedModel) : base(game, skinnedModel.Model) { reinitialize2(skinnedModel); }
public override void reinitialize(SkinnedModel skinnedModel) { base.reinitialize(skinnedModel); animationController.StartClip(skinnedModel.AnimationClips[animations[(int)MonsterAnimations.Idle]]); }
/// <summary> /// Converts this trianlge mesh into a BFSOctree. /// </summary> /// <param name="maxLevel">The maximum node level/depth of any node in /// the created DynamicOctree.</param> /// <returns>A BFSOctree representing this triangle mesh.</returns> public BFSOctree toBFSOctree(byte maxLevel) { System.Collections.Generic.IEnumerator<AnimationClip> enum1; System.Collections.Generic.IEnumerator<AnimationChannel> enum2; enum1 = _model.AnimationClips.Values.GetEnumerator(); enum1.MoveNext(); enum2 = enum1.Current.Channels.Values.GetEnumerator(); enum2.MoveNext(); Matrix[,] animation = new Matrix[enum2.Current.Count, enum1.Current.Channels.Count]; AnimationClip clip; _model.AnimationClips.TryGetValue("Take 001", out clip); AnimationController c = new AnimationController(_model.SkeletonBones); c.StartClip(clip); for (long i = 0; i < enum2.Current.Count; ++i) { c.Update(new TimeSpan(clip.Duration.Ticks / enum2.Current.Count), Matrix.Identity); for (int j = 0; j < enum1.Current.Channels.Count; ++j) animation[i, j] = c.SkinnedBoneTransforms[j]; } _model = null; BFSOctree result = new BFSOctree(toDynamicOctree(maxLevel)); result._animation = animation; result.frameCount = (uint)enum2.Current.Count; result.boneCount = (uint)enum1.Current.Channels.Count; return result; }