/// <summary>
        /// Adds all of the geometry used by a model component to the static geometry.
        /// This is used by the ModelComponent.
        /// </summary>
        public void Add(ModelComponent mc, ThingBlock template, ModelBlock block, ThingDefinition def)
        {
            // if the model detail option is low and this model wants imposters, don't even make any static geometry of it
            if (Options.ModelDetail == ModelDetailOption.Low) {
                if (def.GetBoolProperty("Imposters", false))
                    return;
            }

            var sceneMgr = LKernel.GetG<SceneManager>();

            string meshName = block.GetStringProperty("mesh", null);
            // map region goes first
            string sgeomName = template.GetStringProperty("MapRegion", "(Default)");
            // static group can override map region
            sgeomName = block.GetStringProperty("StaticGroup", sgeomName);
            Entity ent;

            // get our entity if it already exists
            if (!ents.TryGetValue(meshName, out ent)) {
                // getting the entity was not successful, so we have to create it
                ent = sceneMgr.CreateEntity(meshName + mc.ID, meshName);
                string material;
                if (block.StringTokens.TryGetValue("material", out material))
                    ent.SetMaterialName(material);

                ents.Add(meshName, ent);
            }

            Vector3 pos;
            // two ways to get the position
            // inherit it from the lthing, the default (if we were using nodes, this would be the default too)
            if (block.GetBoolProperty("InheritOrientation", true)) {
                pos = (mc.Owner.SpawnOrientation * block.GetVectorProperty("position", Vector3.ZERO)) + template.VectorTokens["position"];
            }
            // or we can choose not to inherit it for whatever reason
            else {
                pos = block.GetVectorProperty("position", Vector3.ZERO) + template.VectorTokens["position"];
            }
            Quaternion orient = block.GetQuatProperty("orientation", Quaternion.IDENTITY) * template.GetQuatProperty("orientation", Quaternion.IDENTITY);
            Vector3 sca = block.GetVectorProperty("scale", Vector3.UNIT_SCALE);

            StaticGeometry sg;
            if (!sgeoms.TryGetValue(sgeomName, out sg)) {
                sg = LKernel.GetG<SceneManager>().CreateStaticGeometry(sgeomName);

                sg.RegionDimensions = regionDimensions;
                sg.RenderingDistance = 300 / 5f;

                sgeoms.Add(sgeomName, sg);
            }

            sg.AddEntity(ent, pos, orient, sca);
        }
        public void Add(ModelComponent mc, ThingBlock template, ModelBlock block, ThingDefinition def)
        {
            // if the model detail option is low and this model wants imposters, don't even make any instanced geometry of it
            if (Options.ModelDetail == ModelDetailOption.Low) {
                if (def.GetBoolProperty("Imposters", false))
                    return;
            }

            var sceneMgr = LKernel.GetG<SceneManager>();

            string meshName = block.GetStringProperty("mesh", null);
            string mapRegion = template.GetStringProperty("MapRegion", string.Empty);
            string key = mapRegion + meshName;

            // create our entity if it doesn't exist
            if (!ents.ContainsKey(key)) {
                Entity ent = sceneMgr.CreateEntity(mc.Name + mc.ID, meshName);
                ent.SetMaterialName(block.GetStringProperty("Material", string.Empty));
                // then add it to our dictionary
                ents.Add(key, ent);
            }

            // get our transforms
            Vector3 pos;
            // two ways to get the position
            // inherit it from the lthing, the default (if we were using nodes, this would be the default too)
            if (block.GetBoolProperty("InheritOrientation", true)) {
                pos = (mc.Owner.SpawnOrientation * block.GetVectorProperty("position", Vector3.ZERO)) + template.VectorTokens["position"];
            }
            // or we can choose not to inherit it for whatever reason
            else {
                pos = block.GetVectorProperty("position", Vector3.ZERO) + template.VectorTokens["position"];
            }
            Quaternion orient = block.GetQuatProperty("orientation", Quaternion.IDENTITY) * template.GetQuatProperty("orientation", Quaternion.IDENTITY);
            Vector3 sca = block.GetVectorProperty("scale", Vector3.UNIT_SCALE);

            // put them in one class
            Transform trans = new Transform {
                Position = pos,
                Orientation = orient,
                Scale = sca,
            };

            // if the transforms dictionary doesn't contain the mesh yet, add a new one
            if (!transforms.ContainsKey(key)) {
                transforms.Add(key, new List<Transform>());
            }
            // then put our transform into the dictionary
            transforms[key].Add(trans);
        }
Example #3
0
        public Derpy(ThingBlock block, ThingDefinition def)
            : base(block, def)
        {
            bodyComponent = ModelComponents[0];
            flagComponent = ModelComponents[1];
            startLightComponent = ModelComponents[2];

            bodyFacing = new Euler(0, 0, 0);
            neckFacing = new Euler(0, 0, 0);

            Skeleton skeleton = bodyComponent.Entity.Skeleton;
            skeleton.BlendMode = SkeletonAnimationBlendMode.ANIMBLEND_CUMULATIVE;

            blinkState = bodyComponent.Entity.GetAnimationState("Blink2");
            blinkState.Enabled = true;
            blinkState.Loop = true;
            blinkState.Weight = 1f;
            blinkState.AddTime(ID);

            neckBone = skeleton.GetBone("Neck");
            neckBone.SetManuallyControlled(true);
            foreach (var state in bodyComponent.Entity.AllAnimationStates.GetAnimationStateIterator())
            {
                // don't add a blend mask to the blink state because we'll make a different one for it
                if (state == blinkState)
                    continue;

                state.CreateBlendMask(skeleton.NumBones);
                state.SetBlendMaskEntry(neckBone.Handle, 0f);
            }
            neckBone.InheritOrientation = false;

            blinkState.CreateBlendMask(skeleton.NumBones, 0f);
            ushort handle = skeleton.GetBone("EyeBrowTop.R").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowBottom.R").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowTop.L").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowBottom.L").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);

            LKernel.GetG<AnimationManager>().Add(blinkState);

            interpNode = LKernel.GetG<SceneManager>().RootSceneNode.CreateChildSceneNode("DerpyInterpNode" + ID, Vector3.ZERO);

            anim = DerpyAnimation.Hover1;
        }
Example #4
0
        public Lyra(ThingBlock block, ThingDefinition def)
            : base(block, def)
        {
            foreach (ModelComponent mc in ModelComponents) {
                if (mc.Name.EndsWith("Body"))
                    bodyComponent = mc;
                else if (mc.Name.EndsWith("Mane"))
                    maneComponent = mc;
                else if (mc.Name.EndsWith("Tail"))
                    tailComponent = mc;
            }

            // make sure our animations add their weights and don't just average out. The AnimationBlender already handles averaging between two anims.
            Skeleton skeleton = bodyComponent.Entity.Skeleton;
            skeleton.BlendMode = SkeletonAnimationBlendMode.ANIMBLEND_CUMULATIVE;

            // set up the blink animation state with some stuff
            blinkState = bodyComponent.Entity.GetAnimationState("Blink2");
            blinkState.Enabled = true;
            blinkState.Loop = true;
            blinkState.Weight = 1;
            blinkState.AddTime(ID);

            // set up all of the animation states to not use the neck bone
            neckbone = skeleton.GetBone("Neck");
            neckbone.SetManuallyControlled(true);
            foreach (var state in bodyComponent.Entity.AllAnimationStates.GetAnimationStateIterator()) {
                // don't add a blend mask to the blink state because we'll make a different one for it
                if (state == blinkState)
                    continue;

                state.CreateBlendMask(skeleton.NumBones);
                state.SetBlendMaskEntry(neckbone.Handle, 0f);
            }
            neckbone.InheritOrientation = false;

            neckFacing = new Euler(0, 0, 0);

            // set up a blend mask so only the eyebrow bones have any effect on the blink animation
            blinkState.CreateBlendMask(skeleton.NumBones, 0f);
            ushort handle = skeleton.GetBone("EyeBrowTop.R").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowBottom.R").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowTop.L").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);
            handle = skeleton.GetBone("EyeBrowBottom.L").Handle;
            blinkState.SetBlendMaskEntry(handle, 1f);

            // add the blink state to the animation manager so it has time added to it
            LKernel.GetG<AnimationManager>().Add(blinkState);

            // set up some timers to handle animation changing
            random = new Random(IDs.Random);
            animTimer = new System.Threading.Timer(new TimerCallback(AnimTimerTick), null, random.Next(ANIMATION_TIMESPAN_MINIMUM, ANIMATION_TIMESPAN_MAXIMUM), Timeout.Infinite);

            // add a bit of time to things so the animations aren't all synced at the beginning
            float rand = (float) random.NextDouble();
            bodyComponent.AnimationBlender.AddTime(rand);
            tailComponent.AnimationState.AddTime(rand);

            followKart = LKernel.GetG<PlayerManager>().MainPlayer.Kart;
            LKernel.GetG<Root>().FrameStarted += FrameStarted;
        }