Exemple #1
0
 /// <summary>
 /// Apply a material profile to all parts in the body.
 /// </summary>
 public void ApplyMaterialProfile(MaterialProfile profile)
 {
     foreach (BodyPart part in AllParts)
     {
         part.ApplyMaterialProfile(profile);
     }
 }
Exemple #2
0
        /// <summary>
        /// Add an item by name with a count.
        /// </summary>
        public void AddItem(string name, int count = 1, MaterialProfile profile = null)
        {
            if (count == 0)
            {
                return;
            }

            Item item = new Item(name, count);

            Items.Add(item);

            if (profile != null)
            {
                item.ApplyMaterialProfile(profile);
            }
        }
Exemple #3
0
        /// <summary>
        /// Applies the material profile.
        /// </summary>
        /// <param name="targetMaterial">If target material is null, the properties will be applied globally.</param>
        public void Apply(Material targetMaterial = null)
        {
            if (currentProfile == null)
            {
                currentProfile = inWorld;
            }

            if (targetMaterial != null)
            {
                targetMaterial.SetVector(ShaderUtils.LightDir, currentProfile.lightDirection);
                targetMaterial.SetColor(ShaderUtils.LightColor, currentProfile.lightColor);
                targetMaterial.SetColor(ShaderUtils.TintColor, currentProfile.tintColor);
                return;
            }

            Shader.SetGlobalVector(ShaderUtils.LightDir, currentProfile.lightDirection);
            Shader.SetGlobalColor(ShaderUtils.LightColor, currentProfile.lightColor);
            Shader.SetGlobalColor(ShaderUtils.TintColor, currentProfile.tintColor);
        }
Exemple #4
0
        /// <summary>
        /// Make a humanoid body.
        /// </summary>
        /// <param name="fingers">number of fingers</param>
        /// <param name="toes">number of toes</param>
        /// <param name="teeth">number of teeth</param>
        /// <param name="ribs">number of ribs</param>
        /// <param name="meatTorso">meat in the torso</param>
        /// <param name="meatArms">meat in each arm</param>
        /// <param name="meatLegs">meat in each leg</param>
        /// <param name="meatFactor">value which all meat values are multiplied by</param>
        /// <param name="fatTorso">fat in torso</param>
        /// <param name="fatArms">fat in arms</param>
        /// <param name="fatLegs">fat in legs</param>
        /// <param name="fatFactor">value which all fat values are multiplied by</param>
        /// <param name="partProfile"><see cref="MaterialProfile"/> of the body overall, defaults to <see cref="MaterialProfile.FleshWithBones"/></param>
        /// <param name="boneProfile"><see cref="MaterialProfile"/> of the bones, defaults to <see cref="MaterialProfile.Bone"/></param>
        /// <param name="fleshProfile"><see cref="MaterialProfile"/> of the flesh, defaults to <see cref="MaterialProfile.Flesh"/></param>
        /// <param name="fatProfile"><see cref="MaterialProfile"/> of the fat, defaults to <see cref="MaterialProfile.Fat"/></param>
        /// <returns></returns>
        public static Body MakeHumanoid(
            int fingers   = 5, int toes     = 5,
            int teeth     = 32, int ribs    = 24,
            int meatTorso = 6, int meatArms = 2, int meatLegs = 3, float meatFactor = 1f,
            int fatTorso  = 2, int fatArms  = 0, int fatLegs  = 1, float fatFactor  = 1f,
            MaterialProfile partProfile = null, MaterialProfile boneProfile = null, MaterialProfile fleshProfile = null, MaterialProfile fatProfile = null
            )
        {
            // Create body.
            Body body = new Body();

            // Create and add all body parts.
            BodyPart head     = body.Base = BodyPart.MakeHead();
            BodyPart neck     = head.AddChild(BodyPart.MakeNeck());
            BodyPart torso    = neck.AddChild(BodyPart.MakeTorso());
            BodyPart armLeft  = torso.AddChild(BodyPart.MakeArm("Left"));
            BodyPart armRight = torso.AddChild(BodyPart.MakeArm("Right"));
            BodyPart legLeft  = torso.AddChild(BodyPart.MakeLeg("Left"));
            BodyPart legRight = torso.AddChild(BodyPart.MakeLeg("Right"));

            BodyPart handLeft  = armLeft.AddChild(BodyPart.MakeAppendage("Left", "Hand", fingers));
            BodyPart handRight = armRight.AddChild(BodyPart.MakeAppendage("Right", "Hand", fingers));
            BodyPart footLeft  = legLeft.AddChild(BodyPart.MakeAppendage("Left", "Foot", toes));
            BodyPart footRight = legRight.AddChild(BodyPart.MakeAppendage("Right", "Foot", toes));

            body.AllParts.AddRange(new[] {
                head,
                neck,
                torso,
                armLeft, handLeft,
                armRight, handRight,
                legLeft, footLeft,
                legRight, footRight,
            });

            // Apply default human item profiles if none are specified.
            partProfile ??= MaterialProfile.FleshWithBones;
            boneProfile ??= MaterialProfile.Bone;
            fleshProfile ??= MaterialProfile.Flesh;
            fatProfile ??= MaterialProfile.Fat;

            if (partProfile != null)
            {
                body.ApplyMaterialProfile(partProfile);
            }

            // Apply meat and fat factors.
            meatTorso = (int)(meatTorso * meatFactor);
            meatArms  = (int)(meatArms * meatFactor);
            meatLegs  = (int)(meatLegs * meatFactor);

            fatTorso = (int)(fatTorso * fatFactor);
            fatArms  = (int)(fatArms * fatFactor);
            fatLegs  = (int)(fatLegs * fatFactor);

            // Add inventories and items.
            Inventory headInventory = head.AddComponent <Inventory>();

            headInventory.AddItem("Skull", 1, boneProfile);
            headInventory.AddItem("Jawbone", 1, boneProfile);
            headInventory.AddItem("Tooth", teeth, boneProfile);

            Inventory torsoInventory = torso.AddComponent <Inventory>();

            torsoInventory.AddItem("Rib", ribs, boneProfile);
            torsoInventory.AddItem("Meat", meatTorso, fleshProfile);
            torsoInventory.AddItem("Fat", fatTorso, fatProfile);

            Inventory armLeftInventory = armLeft.AddComponent <Inventory>();

            armLeftInventory.AddItem("Humerus", 1, boneProfile);
            armLeftInventory.AddItem("Ulna", 1, boneProfile);
            armLeftInventory.AddItem("Radius", 1, boneProfile);
            armLeftInventory.AddItem("Meat", meatArms, fleshProfile);
            armLeftInventory.AddItem("Fat", fatArms, fatProfile);

            Inventory armRightInventory = armRight.AddComponent <Inventory>();

            armRightInventory.AddItem("Humerus", 1, boneProfile);
            armRightInventory.AddItem("Ulna", 1, boneProfile);
            armRightInventory.AddItem("Radius", 1, boneProfile);
            armRightInventory.AddItem("Meat", meatArms, fleshProfile);
            armRightInventory.AddItem("Fat", fatArms, fatProfile);

            Inventory legLeftInventory = legLeft.AddComponent <Inventory>();

            legLeftInventory.AddItem("Femur", 1, boneProfile);
            legLeftInventory.AddItem("Fibula", 1, boneProfile);
            legLeftInventory.AddItem("Tibula", 1, boneProfile);
            legLeftInventory.AddItem("Meat", meatLegs, fleshProfile);
            legLeftInventory.AddItem("Fat", fatLegs, fatProfile);

            Inventory legRightInventory = legRight.AddComponent <Inventory>();

            legRightInventory.AddItem("Femur", 1, boneProfile);
            legRightInventory.AddItem("Fibula", 1, boneProfile);
            legRightInventory.AddItem("Tibula", 1, boneProfile);
            legRightInventory.AddItem("Meat", meatLegs, fleshProfile);
            legRightInventory.AddItem("Fat", fatLegs, fatProfile);

            // Return the created body.
            return(body);
        }