コード例 #1
0
        public void Unload()
        {
            Speed    = Vector2.Zero;
            MaxSpeed = Vector2.Zero;

            _model = null;
        }
コード例 #2
0
        /// <summary>
        /// Onde eu crio o maluco que fica andando pelo mapa, animado por uma aniamação esqueletal
        /// </summary>
        /// <param name="scene"></param>
        private Node CreateDude(Scene scene)
        {
            var cache     = this.ResourceCache;
            var modelNode = scene.CreateChild("Jack");

            modelNode.Position = new Vector3(0, 0, 0);
            modelNode.Rotation = new Quaternion(0, 0, 0);
            //var modelObject = modelNode.CreateComponent<AnimatedModel>();
            var modelObject = new AnimatedModel();

            modelNode.AddComponent(modelObject);
            modelObject.Model = cache.GetModel("Models/Jack.mdl");
            //modelObject.Material = cache.GetMaterial("Materials/Jack.xml");
            modelObject.CastShadows = true;

            // Create an AnimationState for a walk animation. Its time position will need to be manually updated to advance the
            // animation, The alternative would be to use an AnimationController component which updates the animation automatically,
            // but we need to update the model's position manually in any case
            var walkAnimation = cache.GetAnimation("Models/Jack_Walk.ani");
            var state         = modelObject.AddAnimationState(walkAnimation);

            // The state would fail to create (return null) if the animation was not found
            if (state != null)
            {
                // Enable full blending weight and looping
                state.Weight = 1;
                state.Looped = true;
            }

            // Create our custom Mover component that will move & animate the model during each frame's update
            var mover = new Mover(ModelMoveSpeed, ModelRotationSpeed, Bounds);

            modelNode.AddComponent(mover);
            return(modelNode);
        }
コード例 #3
0
        internal static void BuildRagdoll(AnimatedModel actor, RebuildOptions options = null, Ragdoll ragdoll = null, string boneNameToBuild = null)
        {
            if (options == null)
            {
                options = new RebuildOptions();
            }
            var model = actor.SkinnedModel;

            if (!model || model.WaitForLoaded())
            {
                Editor.LogError("Missing or not loaded model.");
                return;
            }
            var bones = model.Bones;
            var nodes = model.Nodes;

            actor.GetCurrentPose(out var localNodesPose);
            if (bones.Length == 0 || localNodesPose.Length == 0)
            {
                Editor.LogError("Empty skeleton.");
                return;
            }
            var skinningMatrices = new Matrix[bones.Length];

            for (int boneIndex = 0; boneIndex < bones.Length; boneIndex++)
            {
                ref var bone = ref bones[boneIndex];
                skinningMatrices[boneIndex] = bone.OffsetMatrix * localNodesPose[bone.NodeIndex];
            }
コード例 #4
0
        public override void DepthExtractor(GameTime gt, IObject obj, ref Matrix View, ref Matrix projection, RenderHelper render)
        {
            AnimatedModel modelo = obj.Modelo as AnimatedModel;

            foreach (ModelMesh modelMesh in modelo.GetAnimatedModel().Meshes)
            {
                foreach (ModelMeshPart meshPart in modelMesh.MeshParts)
                {
                    SkinnedModelBasicEffect basicEffect = (SkinnedModelBasicEffect)meshPart.Effect;
                    basicEffect.CurrentTechnique = basicEffect.Techniques["DEPTH"];
                    if (followBone)
                    {
                        basicEffect.World = Followed.GetBoneAbsoluteTransform(boneName) * Followobj.WorldMatrix;
                        basicEffect.Bones = modelo.getBonesTransformation();
                    }
                    else
                    {
                        basicEffect.World = WorldMatrix;
                        basicEffect.Bones = ac.GetBoneTransformations();
                    }
                    basicEffect.View       = View;
                    basicEffect.Projection = projection;
                }

                modelMesh.Draw();
            }
            render.SetSamplerStates(ginfo.SamplerState);
        }
コード例 #5
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            {
                ///carrega o Modelo
                AnimatedModel am = new AnimatedModel(factory, "..\\Content\\Model\\PlayerMarine", "..\\Content\\Textures\\PlayerMarineDiffuse");
                ///Inicializa o Controlador (Idle eh o nome da animacao inicial)
                AnimatedController arobo = new AnimatedController(am, "Idle");

                ///Cria o shader e o material animados
                DeferredSimpleAnimationShader sas  = new DeferredSimpleAnimationShader(arobo);
                DeferredAnimatedMaterial      amat = new DeferredAnimatedMaterial(arobo, sas);

                CharacterControllerInput gp = new CharacterControllerInput(this, new Vector3(100, 50, 1), 25, 10, 10, Vector3.One);

                IObject marine = new IObject(amat, am, gp.Characterobj);
                ///Adiciona no mundo
                this.World.AddObject(marine);

                LightThrowBepu lt = new LightThrowBepu(this.World, factory);
            }

            {
                SimpleModel          simpleModel = new SimpleModel(factory, "Model//cenario");
                TriangleMeshObject   tmesh       = new TriangleMeshObject(simpleModel, Vector3.Zero, Matrix.Identity, Vector3.One, MaterialDescription.DefaultBepuMaterial());
                DeferredNormalShader shader      = new DeferredNormalShader();
                DeferredMaterial     fmaterial   = new DeferredMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
            }



            #region NormalLight
            DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White);
            DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White);
            DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White);
            DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White);
            DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White);
            float li = 0.5f;
            ld1.LightIntensity = li;
            ld2.LightIntensity = li;
            ld3.LightIntensity = li;
            ld4.LightIntensity = li;
            ld5.LightIntensity = li;
            this.World.AddLight(ld1);
            this.World.AddLight(ld2);
            this.World.AddLight(ld3);
            this.World.AddLight(ld4);
            this.World.AddLight(ld5);
            #endregion

            CameraFirstPerson cam = new CameraFirstPerson(GraphicInfo);
            cam.MoveSpeed *= 5;
            this.World.CameraManager.AddCamera(cam);

            SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//grasscube");
            CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc);
        }
コード例 #6
0
        protected override void OnShow(Node node, Asset asset)
        {
            node.CreateComponent <WirePlane>();
            //Here we should find a model to apply ANI
            //TODO: ask user if not sure
            var modelName = Directory.GetFiles(Path.GetDirectoryName(asset.FullPathToAsset), "*.mdl")
                            .Select(Path.GetFileNameWithoutExtension)
                            .FirstOrDefault(f => asset.AssetFileName.StartsWith(f));

            if (string.IsNullOrEmpty(modelName))
            {
                throw new Exception("Can't find a model to apply selected animation.");
            }

            model       = node.CreateComponent <AnimatedModel>();
            model.Model = ResourceCache.GetModel(Path.Combine(Path.GetDirectoryName(asset.RelativePathToAsset), modelName + ".mdl"));
            model.SetMaterial(CreateDefaultMaterial());

            var walkAnimation = ResourceCache.GetAnimation(asset.RelativePathToAsset);
            var state         = model.AddAnimationState(walkAnimation);

            if (state != null)
            {
                state.Weight = 1;
                state.Looped = true;
            }
            node.SetScaleBasedOnBoundingBox(60);
        }
コード例 #7
0
        protected override void  Draw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <Light.ILight> lights)
        {
            AnimatedModel modelo = obj.Modelo as AnimatedModel;

            for (int i = 0; i < modelo.GetAnimatedModel().Meshes.Count; i++)
            {
                ModelMesh modelMesh = modelo.GetAnimatedModel().Meshes[i];
                for (int j = 0; j < modelMesh.MeshParts.Count; j++)
                {
                    SkinnedEffect basicEffect = (SkinnedEffect)modelMesh.MeshParts[j].Effect;

                    if (EnableTexture)
                    {
                        basicEffect.Texture = modelo.getTexture(TextureType.DIFFUSE, i, j);
                    }

                    if (followBone)
                    {
                        basicEffect.World = Followed.GetBoneAbsoluteTransform(boneName) * Followobj.WorldMatrix;
                        basicEffect.SetBoneTransforms(modelo.getBonesTransformation());
                    }
                    else
                    {
                        basicEffect.World = WorldMatrix;
                        basicEffect.SetBoneTransforms(ac.GetBoneTransformations());
                    }
                    basicEffect.View       = cam.View;
                    basicEffect.Projection = cam.Projection;
                }
                modelMesh.Draw();
            }
        }
コード例 #8
0
ファイル: Gear.cs プロジェクト: adavattedeve/Portfolio
 void Awake()
 {
     stats                     = GetComponent <CharacterStats> ();
     mainHand                  = stats.mainHand;
     sticher                   = GetComponentInChildren <ModelSticher> ();
     inventory                 = GetComponent <Inventory> ();
     gear                      = new ItemSlot[10];
     gear [0]                  = new ItemSlot(0, ItemType.HELMET);
     gear [1]                  = new ItemSlot(1, ItemType.AMULET);
     gear [2]                  = new ItemSlot(2, ItemType.RING);
     gear [3]                  = new ItemSlot(3, ItemType.RING);
     gear [4]                  = new ItemSlot(4, ItemType.CHEST);
     gear [5]                  = new ItemSlot(5, ItemType.GLOVES);
     gear [6]                  = new ItemSlot(6, ItemType.WEAPON);
     gear [7]                  = new ItemSlot(7, ItemType.OFFHAND);
     gear [8]                  = new ItemSlot(8, ItemType.LEGS);
     gear [9]                  = new ItemSlot(9, ItemType.BOOTS);
     defaultAnimatedModels     = new AnimatedModel[5];
     defaultAnimatedModels [0] = new AnimatedModel(defaultAnimatedHead, ItemType.HELMET);
     defaultAnimatedModels [1] = new AnimatedModel(defaultAnimatedChest, ItemType.CHEST);
     defaultAnimatedModels [2] = new AnimatedModel(defaultAnimatedLegs, ItemType.LEGS);
     defaultAnimatedModels [3] = new AnimatedModel(defaultAnimatedFeet, ItemType.BOOTS);
     defaultAnimatedModels [4] = new AnimatedModel(defaultAnimatedHands, ItemType.GLOVES);
     animatedModels            = new AnimatedModel[5];
     animatedModels [0]        = new AnimatedModel(new GameObject[defaultAnimatedModels [0].models.Length], ItemType.HELMET);
     animatedModels [1]        = new AnimatedModel(new GameObject[defaultAnimatedModels [1].models.Length], ItemType.CHEST);
     animatedModels [2]        = new AnimatedModel(new GameObject[defaultAnimatedModels [2].models.Length], ItemType.LEGS);
     animatedModels [3]        = new AnimatedModel(new GameObject[defaultAnimatedModels [3].models.Length], ItemType.BOOTS);
     animatedModels [4]        = new AnimatedModel(new GameObject[defaultAnimatedModels [4].models.Length], ItemType.GLOVES);
 }
コード例 #9
0
ファイル: Spawner.cs プロジェクト: scifiboi/ultraSandbox
        private void objectFromTemplate()
        {
            PhysModel curModel;

            switch (template.useType)
            {
            case Template.UseType.Animated:
                curModel = new AnimatedModel(Scene);
                break;

            default:
                curModel = new PhysModel(Scene);
                break;
            }


            curModel.Materials = template.materials;
            curModel.Meshes    = template.meshes;
            curModel.Position  = ghost.Position;
            curModel.PhysBoxes = template.pmeshes;

            curModel.IsStatic = template.isStatic;

            curModel.Name = Scene.getUniqueName();

            curModel.Orientation = ghost.Orientation;

            if (template.hasLight && Scene.lightCount < ShaderLoader.maxNoLights)
            {
                Light mLight = new LightSpot(curModel);
                mLight.Color = new Vector4(template.lightColor, 1);
            }
        }
コード例 #10
0
        protected override void Draw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <Light.ILight> lights)
        {
            AnimatedModel modelo = obj.Modelo as AnimatedModel;

            for (int i = 0; i < modelo.GetAnimatedModel().Meshes.Count; i++)
            {
                ModelMesh modelMesh = modelo.GetAnimatedModel().Meshes[i];
                for (int j = 0; j < modelMesh.MeshParts.Count; j++)
                {
                    SkinnedModelBasicEffect basicEffect = (SkinnedModelBasicEffect)modelMesh.MeshParts[j].Effect;
                    basicEffect.CurrentTechnique = basicEffect.Techniques["FORWARD"];
                    basicEffect.Parameters["diffuseMap0"].SetValue(modelo.getTexture(TextureType.DIFFUSE, i, j));
                    basicEffect.Parameters["diffuseMapEnabled"].SetValue(true);
                    if (followBone)
                    {
                        basicEffect.World = Followed.GetBoneAbsoluteTransform(boneName) * Followobj.WorldMatrix;
                        basicEffect.Bones = ac.GetBoneTransformations();
                    }
                    else
                    {
                        basicEffect.World = WorldMatrix;
                        basicEffect.Bones = ac.GetBoneTransformations();
                    }
                    basicEffect.View       = cam.View;
                    basicEffect.Projection = cam.Projection;
                }
                modelMesh.Draw();
            }
        }
コード例 #11
0
        private IComponent CreateModel(Engine engine, Skeleton skeleton, ModelDefinition model, ImcVariant variant, int m, int b)
        {
            const string PapPathFormat = "chara/monster/m{0:D4}/animation/a0001/bt_common/resident/monster.pap";


            var component = new AnimatedModel(engine, skeleton, variant, model, ModelQuality.High)
            {
            };


            var papPath = string.Format(PapPathFormat, m, b);

            SaintCoinach.IO.File papFileBase;
            if (Parent.Realm.Packs.TryGetFile(papPath, out papFileBase))
            {
                var anim = new AnimationContainer(skeleton, new PapFile(papFileBase));

                var hasAnim = false;
                for (var i = 0; i < DefaultAnimationNames.Length && !hasAnim; ++i)
                {
                    var n = DefaultAnimationNames[i];
                    if (anim.AnimationNames.Contains(n))
                    {
                        component.AnimationPlayer.Animation = anim.Get(n);
                        hasAnim = true;
                    }
                }

                if (!hasAnim)
                {
                    component.AnimationPlayer.Animation = anim.Get(0);
                }
            }
            return(component);
        }
コード例 #12
0
        public AnimTest(GameSession.GameSession RuningGameSession)
            : base(RuningGameSession)
        {
            this.model = new AnimatedModel("test2/Victoria-hat-tpose");
            this.model.LoadContent(this.RunningGameSession.Content);

            base.model = this.model.model;

            dance = new AnimatedModel("test2/Victoria-hat-dance");
            dance.LoadContent(this.RunningGameSession.Content);

            // Obtain the clip we want to play. I'm using an absolute index,
            // because XNA 4.0 won't allow you to have more than one animation
            // associated with a model, anyway. It would be easy to add code
            // to look up the clip by name and to index it by name in the model.
            AnimationClip clip = dance.Clips[0];


            // And play the clip
            AnimationPlayer player = model.PlayClip(clip);

            player.Looping = true;


            //    this.Rotation = new Vector3(0.0f, 0.0f, (float)(Math.PI/2));
        }
コード例 #13
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            {
                ///carrega o Modelo
                AnimatedModel am = new AnimatedModel(factory, "..\\Content\\Model\\PlayerMarine", "..\\Content\\Textures\\PlayerMarineDiffuse");
                ///Inicializa o Controlador (Idle eh o nome da animacao inicial)
                AnimatedController arobo = new AnimatedController(am, "Idle");

                ///Cria o shader e o material animados
                ForwardSimpleAnimationShader sas  = new ForwardSimpleAnimationShader(arobo);
                ForwardAnimatedMaterial      amat = new ForwardAnimatedMaterial(arobo, sas);
                IObject marine = new IObject(amat, am, new GhostObject(Vector3.Zero, Matrix.Identity, Vector3.One * 10));

                ///Adiciona no mundo
                this.World.AddObject(marine);

                //sas.EnableTexture = true;
            }

            var newCameraFirstPerson = new CameraFirstPerson(GraphicInfo);

            this.World.CameraManager.AddCamera(newCameraFirstPerson);
        }
コード例 #14
0
 public AnimatedModelAdapter(AasSystem aasSystem, AasHandle handle, AnimatedModel model, bool borrowed = false)
 {
     aasSystem_ = aasSystem;
     handle_    = handle;
     model_     = model;
     borrowed_  = borrowed;
 }
コード例 #15
0
        void RestartJacks()
        {
            var ll = new Vector <Node>();  //get rid of some old objects

            scene.GetChildrenWithName(ll, "Sphere", true);
            for (int ii = 0; ii < ll.Size; ii++)
            {
                ll[ii].Remove();
            }

            var nn = new Vector <Node>();

            scene.GetChildrenWithName(nn, "Stuffing", true);
            for (int ii = 0; ii < nn.Size; ii++)
            {
                nn[ii].Remove();
            }

            var mm = new Vector <Node>();

            scene.GetChildrenWithName(mm, "Jack", true);
            for (int ii = 0; ii < mm.Size; ii++)
            {
                mm[ii].Remove();
            }

            // Create animated models, you dont know ... jack
            var cache = GetSubsystem <ResourceCache>();

            for (int z = -1; z <= 1; ++z)
            {
                for (int x = -4; x <= 4; ++x)
                {
                    Node modelNode = scene.CreateChild("Jack");
                    modelNode.Position = new Vector3(x * 5.0f, 0.0f, z * 5.0f);
                    modelNode.Rotation = new Quaternion(0.0f, 180.0f, 0.0f);
                    AnimatedModel modelObject = modelNode.CreateComponent <AnimatedModel>();
                    modelObject.Model = cache.Get <Model>("Models/Jack.mdl");
                    modelObject.SetMaterial(cache.Get <Material>("Materials/Jack.xml"));
                    modelObject.CastShadows = true;
                    // Set the model to also update when invisible to avoid staying invisible when the model should come into
                    // view, but does not as the bounding box is not updated
                    modelObject.UpdateInvisible = true;

                    // Create a rigid body and a collision shape. These will act as a trigger for transforming the
                    // model into a ragdoll when hit by a moving object
                    RigidBody body = modelNode.CreateComponent <RigidBody>();
                    // The Trigger mode makes the rigid body only detect collisions, but impart no forces on the
                    // colliding objects
                    body.Trigger = true;
                    CollisionShape shape = modelNode.CreateComponent <CollisionShape>();
                    // Create the capsule shape with an offset so that it is correctly aligned with the model, which
                    // has its origin at the feet
                    shape.SetCapsule(0.7f, 2.0f, new Vector3(0.0f, 1.0f, 0.0f), Quaternion.Identity);

                    // Create a custom component that reacts to collisions and creates the ragdoll
                    modelNode.AddComponent(new Ragdoll());
                }
            }
        }
コード例 #16
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            model = Content.Load <AnimatedModel>("human");

            effect = new AnimatedModelEffect(GraphicsDevice);
            effect.DiffuseLightDirection = new Vector3(1, 1, -1);
            effect.DiffuseLightColor     = Color.White;
            effect.DiffuseLightIntensity = 0.2f;

            effect.AmbientLightColor = Color.White;
            effect.AmbientIntensity  = 0.8f;

            animation = new AnimationPlayer(model);
            clips     = model.clips.Values.ToArray();
            animation.StartClip(clips[currentClipIndex], 1, true);


            Vector3 cameraPosition = new Vector3(-30, -30, 20);
            float   aspectRatio    = GraphicsDevice.PresentationParameters.BackBufferWidth / (float)GraphicsDevice.PresentationParameters.BackBufferHeight;

            view       = Matrix.CreateLookAt(cameraPosition, new Vector3(0, 0, 20), Vector3.UnitZ);
            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, aspectRatio, 1, 500);
        }
コード例 #17
0
        public Player(Game game)
            : base(game)
        {
            position    = new Vector3(0, 0, 0);
            playerModel = new AnimatedModel(game);

            Ap = 0;

            manaPotions   = 5;
            healthPotions = 5;

            strength     = 10;
            constitution = 10;
            intelligence = 10;
            wisdom       = 10;
            agility      = 10;

            mana          = 100;
            health        = 100;
            gold          = 0;
            xpToNextLevel = 0;
            level         = 0;

            LevelUp();
        }
コード例 #18
0
        protected override void Start()
        {
            base.Start();

            // Create Scene and stuff
            Scene  scene  = new Scene();
            Octree octree = scene.CreateComponent <Octree>();
            Zone   zone   = scene.CreateComponent <Zone>();

            zone.AmbientColor = new Color(0.75f, 0.75f, 0.75f);

            // Create the root note
            Node rootNode = scene.CreateChild();

            rootNode.Position = new Vector3(0, 0, 0);

            // Create a light node
            Node  lightNode = rootNode.CreateChild();
            Light light     = lightNode.CreateComponent <Light>();

            light.Color     = new Color(0.75f, 0.75f, 0.75f);
            light.LightType = LightType.Directional;
            lightNode.SetDirection(new Vector3(2, -3, -1));

            // Create the camera
            cameraNode = scene.CreateChild();
            Camera camera = cameraNode.CreateComponent <Camera>();

            // Set camera Position and Direction above the monkey pointing down
            cameraNode.Position = new Vector3(0, 12, 0);
            cameraNode.SetDirection(new Vector3(0, 0, 0) - cameraNode.Position);

            // Save the camera transform resulting from that configuration
            cameraTransform = From3x4(cameraNode.Transform);

            monkeyNode = rootNode.CreateChild("monkeyNode");
            AnimatedModel monkey = monkeyNode.CreateComponent <AnimatedModel>();

            // Xamarin monkey model created by Vic Wang at http://vidavic.weebly.com
            monkey.Model = ResourceCache.GetModel("monkey1.mdl");
            monkey.SetMaterial(ResourceCache.GetMaterial("Materials/phong1.xml"));

            // Move the monkey down a bit so it's centered on the origin
            monkeyNode.Translate(new Vector3(0, -3, 0));

            // Get the initial rotations of the arm bones
            rightArmRotationBase = monkeyNode.GetChild("arm2", true).Rotation;
            leftArmRotationBase  = monkeyNode.GetChild("arm6", true).Rotation;

            // And the leg bones
            rightLegRotationBase = monkeyNode.GetChild("leg1", true).Rotation;
            leftLegRotationBase  = monkeyNode.GetChild("leg5", true).Rotation;

            // Set up the Viewport
            Viewport viewport = new Viewport(Context, scene, camera, null);

            Renderer.SetViewport(0, viewport);
            viewport.SetClearColor(new Color(0.88f, 0.88f, 0.88f));
        }
コード例 #19
0
        //public Quaternion Rotation;

        #endregion

        #region constructor, initialize

        /// <summary>
        /// Constructor, needs model
        /// </summary>
        /// <param name="m">model of the player</param>
        public Player(AnimatedModel m)
        {
            AniModel = m;
            Position = new Vector3(GameConstants.fLaneCenter, 0, -3f);
            //Console.WriteLine("Startposition: (" + this.Position.X + "/ " + this.Position.Y + "/" + this.Position.Z + ")");
            Initialize();
            this.name = "Player";
        }
コード例 #20
0
        public override MapItem Deserialize(BinaryReader r)
        {
            var am = new AnimatedModel(false);

            ReadKdopItem(r, am);
            am.Tags  = ReadObjectList <Token>(r);
            am.Model = r.ReadToken();
            am.Node  = new UnresolvedNode(r.ReadUInt64());
            return(am);
        }
コード例 #21
0
        public void InitializeRendering(AnimationEditor editor, DeviceManager deviceManager, WadMoveable skin)
        {
            if (LicenseManager.UsageMode != LicenseUsageMode.Runtime)
            {
                return;
            }

            base.InitializeRendering(deviceManager.Device, Configuration.RenderingItem_Antialias);
            ResetCamera();

            _editor      = editor;
            _wadRenderer = new WadRenderer(deviceManager.___LegacyDevice);
            _model       = _wadRenderer.GetMoveable(editor.Moveable);

            Configuration = _editor.Tool.Configuration;

            if (skin != null)
            {
                _skinModel = _wadRenderer.GetMoveable(skin);
            }

            // Actual "InitializeRendering"
            _fontTexture = Device.CreateTextureAllocator(new RenderingTextureAllocator.Description {
                Size = new VectorInt3(512, 512, 2)
            });
            _fontDefault = Device.CreateFont(new RenderingFont.Description {
                FontName = "Segoe UI", FontSize = 24, FontIsBold = true, TextureAllocator = _fontTexture
            });

            // Legacy rendering
            {
                _device        = deviceManager.___LegacyDevice;
                _deviceManager = deviceManager;
                new BasicEffect(_device); // This effect is used for editor special meshes like sinks, cameras, light meshes, etc
                SharpDX.Direct3D11.RasterizerStateDescription renderStateDesc =
                    new SharpDX.Direct3D11.RasterizerStateDescription
                {
                    CullMode                 = SharpDX.Direct3D11.CullMode.None,
                    DepthBias                = 0,
                    DepthBiasClamp           = 0,
                    FillMode                 = SharpDX.Direct3D11.FillMode.Wireframe,
                    IsAntialiasedLineEnabled = true,
                    IsDepthClipEnabled       = true,
                    IsFrontCounterClockwise  = false,
                    IsMultisampleEnabled     = true,
                    IsScissorEnabled         = false,
                    SlopeScaledDepthBias     = 0
                };

                _rasterizerWireframe = RasterizerState.New(deviceManager.___LegacyDevice, renderStateDesc);

                _gizmo = new GizmoAnimationEditor(editor, _device, _deviceManager.___LegacyEffects["Solid"], this);
                _plane = GeometricPrimitive.GridPlane.New(_device, 8, 4);
            }
        }
コード例 #22
0
        public GameUnit(string modelName, Vector3 position, Vector3 rotation, Vector3 scale,
                        int life, int maxLife, Vector2 speed)
        {
            _life    = life;
            _maxLife = maxLife;

            Speed = speed;

            //_model = new AnimatedModel(new DrawableModel((GameModel)ModelManager.GetModel(modelName), position, rotation, scale, 0));
            _model = new AnimatedModel((GameModel)ModelManager.GetModel(modelName), position, rotation, scale, 0);

            _boundingSphere = _model.BSphere;
        }
コード例 #23
0
        protected override void Draw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <Light.ILight> lights)
        {
            AnimatedModel modelo = obj.Modelo as AnimatedModel;

            for (int i = 0; i < modelo.GetAnimatedModel().Meshes.Count; i++)
            {
                ModelMesh modelMesh = modelo.GetAnimatedModel().Meshes[i];
                for (int j = 0; j < modelMesh.MeshParts.Count; j++)
                {
                    SkinnedModelBasicEffect basicEffect = (SkinnedModelBasicEffect)modelMesh.MeshParts[j].Effect;
                    basicEffect.CurrentTechnique = basicEffect.Techniques["DEFERREDCUSTOM"];

                    basicEffect.Parameters["diffuseMap0"].SetValue(modelo.getTexture(TextureType.DIFFUSE, i, j));
                    basicEffect.Parameters["diffuseMapEnabled"].SetValue(true);
                    basicEffect.Parameters["normalMapEnabled"].SetValue(useBump);
                    basicEffect.Parameters["glowMapEnabled"].SetValue(useGlow);
                    basicEffect.Parameters["specularMapEnabled"].SetValue(useSpecular);

                    if (useGlow)
                    {
                        basicEffect.Parameters["glowMap0"].SetValue(modelo.getTexture(TextureType.GLOW, i, j));
                    }
                    if (useBump)
                    {
                        basicEffect.Parameters["normalMap0"].SetValue(modelo.getTexture(TextureType.BUMP, i, j));
                    }
                    if (useSpecular)
                    {
                        basicEffect.Parameters["specularMap0"].SetValue(modelo.getTexture(TextureType.SPECULAR, i, j));
                    }

                    if (followBone)
                    {
                        basicEffect.World = Followed.GetBoneAbsoluteTransform(boneName) * Followobj.WorldMatrix;
                        basicEffect.Bones = modelo.getBonesTransformation();
                    }
                    else
                    {
                        basicEffect.World = WorldMatrix;
                        basicEffect.Bones = ac.GetBoneTransformations();
                    }

                    basicEffect.View       = cam.View;
                    basicEffect.Projection = cam.Projection;
                }

                modelMesh.Draw();
            }

            render.SetSamplerStates(ginfo.SamplerState);
        }
コード例 #24
0
        public Enemy(string modelName, Vector3 position, Vector3 rotation, Vector3 scale,
                     int life, int maxLife, Vector2 speed)
        {
            _life    = life;
            _maxLife = maxLife;

            Speed = speed;

            //_model = new AnimatedModel(new DrawableModel((GameModel)ModelManager.GetModel(modelName), position, rotation, scale, 0));
            _model = new AnimatedModel((GameModel)ModelManager.GetModel(modelName), position, rotation, scale, 0);

            _model.TimeSpeed = 0.25f;
            _model.Animation.StartClip("Waiting", true);
        }
コード例 #25
0
        void CreateCharacter()
        {
            var cache = ResourceCache;

            Node objectNode = scene.CreateChild("Jack");

            objectNode.Position = (new Vector3(0.0f, 1.0f, 0.0f));

            // spin node
            Node adjustNode = objectNode.CreateChild("AdjNode");

            adjustNode.Rotation = (new  Quaternion(0, 180, 0));

            // Create the rendering component + animation controller
            AnimatedModel obj = adjustNode.CreateComponent <AnimatedModel>();

            obj.Model = cache.GetModel("Models/Mutant/Mutant.mdl");
            obj.SetMaterial(cache.GetMaterial("Models/Mutant/Materials/mutant_M.xml"));
            obj.CastShadows = true;
            adjustNode.CreateComponent <AnimationController>();

            // Set the head bone for manual control
            obj.Skeleton.GetBoneSafe("Mutant:Head").Animated = false;

            // Create rigidbody, and set non-zero mass so that the body becomes dynamic
            RigidBody body = objectNode.CreateComponent <RigidBody>();

            body.CollisionLayer = 1;
            body.Mass           = 1.0f;

            // Set zero angular factor so that physics doesn't turn the character on its own.
            // Instead we will control the character yaw manually
            body.SetAngularFactor(Vector3.Zero);

            // Set the rigidbody to signal collision also when in rest, so that we get ground collisions properly
            body.CollisionEventMode = CollisionEventMode.Always;

            // Set a capsule shape for collision
            CollisionShape shape = objectNode.CreateComponent <CollisionShape>();

            shape.SetCapsule(0.7f, 1.8f, new Vector3(0.0f, 0.9f, 0.0f), Quaternion.Identity);

            // Create the character logic component, which takes care of steering the rigidbody
            // Remember it so that we can set the controls. Use a WeakPtr because the scene hierarchy already owns it
            // and keeps it alive as long as it's not removed from the hierarchy
            character = new Character();
            objectNode.AddComponent(character);
        }
コード例 #26
0
    public static AnimatedModel Deserialize(GamePlatform p, string data)
    {
        AnimatedModel model = new AnimatedModel();

        model.nodes      = new Node[256];
        model.keyframes  = new Keyframe[1024];
        model.animations = new Animation[128];
        AnimatedModelBinding b = new AnimatedModelBinding();

        b.p = p;
        b.m = model;
        TableSerializer s = new TableSerializer();

        s.Deserialize(p, data, b);
        return(model);
    }
コード例 #27
0
        public override void PreUpdate(IObject ent, IList <Light.ILight> lights)
        {
            this.ent = ent;
            base.PreUpdate(ent, lights);

            AnimatedModel modelo = ent.Modelo as AnimatedModel;

            for (int i = 0; i < modelo.GetAnimatedModel().Meshes.Count; i++)
            {
                ModelMesh modelMesh = modelo.GetAnimatedModel().Meshes[i];
                for (int j = 0; j < modelMesh.MeshParts.Count; j++)
                {
                    modelMesh.MeshParts[j].Effect = SkinnedEffect;
                }
            }
        }
コード例 #28
0
        /// <summary>
        /// Create asteroid manager
        /// </summary>
        public GameAsteroidManager(Level setLevel)
            : base(setLevel)
        {
            // Load all items
            for (int num = 0; num < Level.NumOfItemTypes; num++)
            {
                // All items are animated, load with help of AnimatedModel.
                itemModels[num] = new AnimatedModel(ItemModelFilenames[num]);
            }             // for (num)

            // Load hit direction texture
            hitDirectionTexture = new Texture("HitDirection.dds");

            // Load goal model
            goalModel = new Model("Goal");
        }         // AsteroidManager()
コード例 #29
0
        public static Model AddModel(string modelPath, float loopBlend, string key = "")
        {
            modelPath = modelPath.Replace(G.I, '/');
            if (key == "")
            {
                key = modelPath.Substring(modelPath.LastIndexOf('/') + 1);
            }
            Model model = content.Load <Model>(modelPath);

            models.Add(key, model);

            AnimatedModel anim = new AnimatedModel(key);

            anim.LoadContent(RenderMethod.Diffuse);
            anim.MakeLoopBlend(loopBlend);
            return(model);
        }
コード例 #30
0
            public static ModelBase Create(RS5DirectoryEntry dirent)
            {
                RS5Chunk chunk = dirent.Data;

                if (dirent.Type == "IMDL")
                {
                    return(ImmobileModel.Create(chunk));
                }
                else if (dirent.Type == "AMDL")
                {
                    return(AnimatedModel.Create(chunk));
                }
                else
                {
                    throw new ArgumentException("Entry does not represent a model");
                }
            }
コード例 #31
0
 public static string Serialize(GamePlatform p, AnimatedModel m)
 {
     return null;
 }
コード例 #32
0
ファイル: Form1.cs プロジェクト: Matthewism/manicdigger
        void LoadModel()
        {
            game = new Game();
            game.SetPlatform(new GamePlatformNative());
            d = new AnimatedModelRenderer();
            AnimatedModel model = new AnimatedModel();
            try
            {
                model = AnimatedModelSerializer.Deserialize(game.GetPlatform(), richTextBox1.Text);
            }
            catch
            {

            }
            if (model != null)
            {
                d.Start(game, model);
            }
        }
コード例 #33
0
 public static AnimatedModel Deserialize(GamePlatform p, string data)
 {
     AnimatedModel model = new AnimatedModel();
     model.nodes = new Node[256];
     model.keyframes = new Keyframe[1024];
     model.animations = new Animation[128];
     AnimatedModelBinding b = new AnimatedModelBinding();
     b.p = p;
     b.m = model;
     TableSerializer s = new TableSerializer();
     s.Deserialize(p, data, b);
     return model;
 }
コード例 #34
0
		void CreateScene ()
		{
			var cache = ResourceCache;
			scene = new Scene ();

			// Create the Octree component to the scene so that drawable objects can be rendered. Use default volume
			// (-1000, -1000, -1000) to (1000, 1000, 1000)
			scene.CreateComponent<Octree> ();
			scene.CreateComponent<DebugRenderer>();

			// Create scene node & StaticModel component for showing a static plane
			var planeNode = scene.CreateChild("Plane");
			planeNode.Scale = new Vector3 (100, 1, 100);
			var planeObject = planeNode.CreateComponent<StaticModel> ();
			planeObject.Model = cache.GetModel ("Models/Plane.mdl");
			planeObject.SetMaterial (cache.GetMaterial ("Materials/StoneTiled.xml"));

			// Create a Zone component for ambient lighting & fog control
			var zoneNode = scene.CreateChild("Zone");
			var zone = zoneNode.CreateComponent<Zone>();
		
			// Set same volume as the Octree, set a close bluish fog and some ambient light
			zone.SetBoundingBox (new BoundingBox(-1000.0f, 1000.0f));
			zone.AmbientColor = new Color (0.15f, 0.15f, 0.15f);
			zone.FogColor = new Color (0.5f, 0.5f, 0.7f);
			zone.FogStart = 100;
			zone.FogEnd = 300;

			// Create a directional light to the world. Enable cascaded shadows on it
			var lightNode = scene.CreateChild("DirectionalLight");
			lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f));
			var light = lightNode.CreateComponent<Light>();
			light.LightType = LightType.Directional;
			light.CastShadows = true;
			light.ShadowBias = new BiasParameters(0.00025f, 0.5f);
		
			// Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance
			light.ShadowCascade = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f);

			// Create animated models
			const int numModels = 100;
			const float modelMoveSpeed = 2.0f;
			const float modelRotateSpeed = 100.0f;
			var bounds = new BoundingBox (new Vector3(-47.0f, 0.0f, -47.0f), new Vector3(47.0f, 0.0f, 47.0f));

			for (var i = 0; i < numModels; ++i)
			{
				var modelNode = scene.CreateChild("Jack");
				modelNode.Position = new Vector3(NextRandom(-45,45), 0.0f, NextRandom (-45, 45));
				modelNode.Rotation = new Quaternion (0, NextRandom(0, 360), 0);
				//var modelObject = modelNode.CreateComponent<AnimatedModel>();
				var modelObject = new AnimatedModel ();
				modelNode.AddComponent (modelObject);
				modelObject.Model = cache.GetModel("Models/Jack.mdl");
				//modelObject.Material = cache.GetMaterial("Materials/Jack.xml");
				modelObject.CastShadows = true;

				// Create an AnimationState for a walk animation. Its time position will need to be manually updated to advance the
				// animation, The alternative would be to use an AnimationController component which updates the animation automatically,
				// but we need to update the model's position manually in any case
				var walkAnimation = cache.GetAnimation("Models/Jack_Walk.ani");
				var state = modelObject.AddAnimationState(walkAnimation);
				// The state would fail to create (return null) if the animation was not found
				if (state != null)
				{
					// Enable full blending weight and looping
					state.Weight = 1;
					state.Looped = true;
				}
			
				// Create our custom Mover component that will move & animate the model during each frame's update
				var mover = new Mover (modelMoveSpeed, modelRotateSpeed, bounds);
				modelNode.AddComponent (mover);
			}
		
			// Create the camera. Limit far clip distance to match the fog
			CameraNode = scene.CreateChild("Camera");
			camera = CameraNode.CreateComponent<Camera>();
			camera.FarClip = 300;
		
			// Set an initial position for the camera scene node above the plane
			CameraNode.Position = new Vector3(0.0f, 5.0f, 0.0f);
		}
コード例 #35
0
 public void Start(Game game_, AnimatedModel model_)
 {
     game = game_;
     m = model_;
 }