private static void CopyMaterialPropertiesOnLodZeroToOtherLODs(GameObject go)
    {
        CostumeItem[] all_items = go.GetComponentsInChildren <CostumeItem> (true);
        foreach (CostumeItem item in all_items)
        {
            SkinnedMeshRenderer[] skinned_meshes     = null;
            SkinnedMeshRenderer   lodZero            = null;
            Material[]            lod_zero_materials = null;

            if (item.GetType() == typeof(CIbody))
            {
                Debug.Log("BODY");
                CIbody body = item as CIbody;
                skinned_meshes = new SkinnedMeshRenderer[body.LODlist.Count];
                int i = 0;
                foreach (CoreMesh mesh in body.LODlist)
                {
                    skinned_meshes[i] = mesh.gameObject.GetComponent <SkinnedMeshRenderer>();
                    i++;
                }
            }
            else
            {
                skinned_meshes = item.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>(true);
            }

            foreach (SkinnedMeshRenderer renderer in skinned_meshes)
            {
                if (renderer.name.EndsWith("0"))
                {
                    lodZero            = renderer;
                    lod_zero_materials = lodZero.sharedMaterials;
                }
            }

            foreach (SkinnedMeshRenderer renderer in skinned_meshes)
            {
                if (renderer != lodZero)
                {
                    Material[] sub_materials = renderer.sharedMaterials;
                    int        i             = 0;
                    foreach (Material mat in sub_materials)
                    {
                        mat.CopyPropertiesFromMaterial(lod_zero_materials[i]);
                        i++;
                    }
                    renderer.sharedMaterials = sub_materials;
                }
            }
        }
    }
Esempio n. 2
0
        /// <summary>
        /// Attachs the costume_item to the given CIbody figure.
        /// </summary>
        /// <returns>The GameObject costume_item</returns>
        /// <param name="costume_item">Costume item.</param>
        /// <param name="figure_bone_map">Figure bone map.</param>
        /// <param name="figure">Figure.</param>
        /// <param name="root_bone">Root bone.</param>
        /// <remarks>Unneccesary return of parameter GameObject as both are the same GameObject</remarks>
        public static GameObject AttachCostumeItemToFigure(GameObject costume_item, BoneUtility.BoneMap figure_bone_map, CIbody figure, Transform root_bone)
        {
            // add to figure
            costume_item.transform.parent = figure.transform;

            // does not need "costume_item = " as BindGeometryToTransform alters the costume_item GameObject anyway
            costume_item = BindGeometryToTransform(costume_item, figure.transform);

            // need figure bones for targeting
            // BoneMap body_bones = new BoneMap(transform);

            // go through each coremesh and rebind bones n what not
            CoreMesh[] meshes = costume_item.GetComponentsInChildren <CoreMesh> (true);
            foreach (CoreMesh mesh in meshes)
            {
                if (mesh.meshType == MESH_TYPE.PROP)
                {
                    continue;
                }

                /*
                 * if(mesh.skinnedMeshRenderer.rootBone.name != "hip")
                 * {
                 *  Transform[] bones = mesh.skinnedMeshRenderer.bones;
                 *  foreach(Transform bone in bones)
                 *  {
                 *      if(bone.name == "hip")
                 *      {
                 *          UnityEngine.Debug.Log("Re-assigned hip bone as root");
                 *          mesh.skinnedMeshRenderer.rootBone = bone;
                 *          break;
                 *      }
                 *  }
                 * }
                 */

                mesh.skinnedMeshRenderer.bones = BoneUtility.RemapBones(mesh.skinnedMeshRenderer.bones, mesh.skinnedMeshRenderer.rootBone, figure_bone_map, root_bone);
                //UnityEngine.Debug.Log("Remapped: " + mesh.name + " bones: " + mesh.skinnedMeshRenderer.bones.Length + " root: " + mesh.skinnedMeshRenderer.rootBone.name);
                mesh.skinnedMeshRenderer.rootBone = root_bone;
            }

            return(costume_item);
        }
Esempio n. 3
0
        /// <summary>
        /// Attaches a clone of the costume item to given CIbody figure.
        /// Send the GameObject of a costumeItem here, and we'll clone it, bind it and return the result
        /// </summary>
        /// <returns>The cloned GameObject of the costume_item</returns>
        /// <param name="costume_item">Costume_item.</param>
        /// <param name="figure">Figure.</param>
        public static GameObject CloneAndAttachCostumeItemToFigure(GameObject costume_item, BoneUtility.BoneMap figure_bone_map, CIbody figure, Transform root_bone)
        {
            // instatiate copy
            GameObject clone = GameObject.Instantiate(costume_item);

            clone.name = costume_item.name;

            // use the basic Attachment method
            GeometryTransferUtility.AttachCostumeItemToFigure(clone, figure_bone_map, figure, root_bone);

            // return the cloned costume_item GameObject
            return(clone);
        }
Esempio n. 4
0
        //todo: expand this...

        /**
         * schematic.origin_and_description.gender = MCS.Utility.Schematic.Enumeration.Gender.male;
         * schematic.origin_and_description.vendor_name = "DAZ3D";
         * schematic.type_and_function.item_function = MCS.Utility.Schematic.Enumeration.ItemFunction.soft_wearable;
         * schematic.origin_and_description.collection_name = "UrbanMetro";
         * schematic.origin_and_description.id = "UMPants";
         * schematic.origin_and_description.name = "UMPants";
         * schematic.version_and_control.item_version = 0.01;
         * schematic.origin_and_description.description = "/Urban Metro Outfit for Genesis 2 Male(s)/Pants";
         * schematic.version_and_control.compatibilities = new string[1]{ "/Genesis 2/Male" };
         * schematic.version_and_control.mcs_version = 1.5;
         */
        public GameObject CreateMorphGameObjectFromFbx(GameObject go, AssetSchematic schematic, Dictionary <string, Texture2D> textures, bool InstantiateNewObjectUponCreation = true)
        {
            UnityEngine.Debug.Log("CreateMorphGameObjectFromFbx: " + go.name + " | " + schematic.stream_and_path.source_path);

            GameObject gameObject = null;

            if (InstantiateNewObjectUponCreation)
            {
                gameObject = GameObject.Instantiate(go) as GameObject;
            }
            else
            {
                gameObject = go;
            }
            GameObject child = gameObject.transform.GetChild(0).gameObject;

            child.AddComponent <MCSItemModel> ();
            child.GetComponent <MCSItemModel> ().schematic = schematic;
            GameObject child2 = child.transform.GetChild(0).gameObject;

            //Adding the coremesh component to the root...ish gameobject of the item. Then we set the various values from the asset schematic (.mon file)
            child2.AddComponent <CoreMeshMetaData>();
            CoreMeshMetaData cmmd = child2.GetComponent <CoreMeshMetaData>();

            cmmd.vendorId  = schematic.origin_and_description.vendor_name;
            cmmd.versionId = schematic.version_and_control.item_version.ToString();

            switch (schematic.type_and_function.item_function)
            {
            case MCS.Utility.Schematic.Enumeration.ItemFunction.soft_wearable:
                cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.CLOTH;
                break;

            case MCS.Utility.Schematic.Enumeration.ItemFunction.rigid_wearable:
                cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.CLOTH;
                break;

            case MCS.Utility.Schematic.Enumeration.ItemFunction.figure:
                cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.BODY;
                break;

            case MCS.Utility.Schematic.Enumeration.ItemFunction.hair:
                cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.HAIR;
                break;

            case MCS.Utility.Schematic.Enumeration.ItemFunction.prop:
                cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.PROP;
                break;

            case MCS.Utility.Schematic.Enumeration.ItemFunction.unknown:
                cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.UNKNOWN;
                break;

            default:
                cmmd.meshType = MCS.CONSTANTS.MESH_TYPE.UNKNOWN;
                break;
            }
            cmmd.geometryId      = schematic.origin_and_description.mcs_id;
            cmmd.ID              = schematic.origin_and_description.mcs_id;
            cmmd.declarativeUse  = schematic.origin_and_description.description;
            cmmd.mcs_version     = schematic.version_and_control.mcs_version;
            cmmd.collection_name = schematic.origin_and_description.collection_name;

            //Adding all the coremesh components to anything that has a skinned mesh renderer. We also add the paths to the runtime morphs here
            foreach (SkinnedMeshRenderer rend in gameObject.GetComponentsInChildren <SkinnedMeshRenderer>())
            {
                rend.gameObject.AddComponent <CoreMesh>();

                CoreMesh cm = rend.gameObject.GetComponent <CoreMesh> ();
                cm.dazName  = schematic.origin_and_description.name;
                cm.ID       = schematic.origin_and_description.mcs_id;
                cm.meshType = cmmd.meshType;
                int index = -1;

                for (int i = 0; i < schematic.structure_and_physics.morph_structure.lodMorphObjectNames.Length; i++)
                {
                    if (schematic.structure_and_physics.morph_structure.lodMorphObjectNames [i] == cm.gameObject.name)
                    {
                        index = i;
                    }
                }

                if (index > -1)
                {
                    cm.runtimeMorphPath = schematic.structure_and_physics.morph_structure.lodMorphLocations[index];
                }
            }

            //Adding the different CICostumeItem classes, ie. CIClothing, CIBody, CIHair, CIProp.
            switch (cmmd.meshType)
            {
            case MCS.CONSTANTS.MESH_TYPE.CLOTH:
                child2.AddComponent <CIclothing>();
                CIclothing cicl = child2.GetComponent <CIclothing>();
                cicl.dazName  = schematic.origin_and_description.name;
                cicl.ID       = schematic.origin_and_description.mcs_id;
                cicl.meshType = cmmd.meshType;
                cicl.DetectCoreMeshes();
                //TODO: textures is a list of textures, not a dictionary, right?

                /*
                 *              if (textures.ContainsKey ("alphaMask")) {
                 *                      cicl.alphaMask = textures ["alphaMask"];
                 *              }
                 */
                cicl.isAttached = false;
                break;

            case MCS.CONSTANTS.MESH_TYPE.BODY:
                //todo: all the figure stuff needs to be added here, ie. CharacterManager, Core Morphs, JCT stuff, etc

                child2.AddComponent <CIbody>();
                CIbody body = child2.GetComponent <CIbody>();

                break;

            case MCS.CONSTANTS.MESH_TYPE.HAIR:
                child2.AddComponent <CIhair>();
                CIhair hair = child2.GetComponent <CIhair>();
                hair.dazName  = schematic.origin_and_description.name;
                hair.ID       = schematic.origin_and_description.mcs_id;
                hair.meshType = cmmd.meshType;
                hair.DetectCoreMeshes();
                break;

            case MCS.CONSTANTS.MESH_TYPE.PROP:
                child2.AddComponent <CIprop>();
                CIprop prop = child2.GetComponent <CIprop>();
                prop.dazName  = schematic.origin_and_description.name;
                prop.ID       = schematic.origin_and_description.mcs_id;
                prop.meshType = cmmd.meshType;
                prop.DetectCoreMeshes();
                prop.basePosition = prop.transform.localPosition;
                prop.baseRotation = prop.transform.localEulerAngles;

                //todo: add bone and attachment point stuff to the prop object
                break;

            case MCS.CONSTANTS.MESH_TYPE.UNKNOWN:
                //Unknown
                break;
            }

            return(gameObject);
        }
Esempio n. 5
0
    /// <summary>
    /// Attempts to find items that are on the figure that should not be and will remove them
    /// </summary>
    public void RemoveRogueContent(GameObject RootObject)
    {
        CoreMeshMetaData[] cmmds = RootObject.GetComponentsInChildren <CoreMeshMetaData>();

        HashSet <string> availableIds = new HashSet <string>();

        List <ContentPack> badCPs = new List <ContentPack>();

        //build a map
        foreach (ContentPack cp in availableContentPacks)
        {
            CoreMeshMetaData[] cpCMMDs = null;
            try
            {
                cpCMMDs = cp.RootGameObject.GetComponentsInChildren <CoreMeshMetaData>();
            }
            catch
            {
                badCPs.Add(cp);
                continue;
            }

            if (cpCMMDs != null)
            {
                foreach (CoreMeshMetaData cmmd in cpCMMDs)
                {
                    availableIds.Add(cmmd.ID);
                }
            }
        }

        foreach (ContentPack cp in badCPs)
        {
            availableContentPacks.Remove(cp);
        }

        foreach (CoreMeshMetaData cmmd in cmmds)
        {
            if (availableIds.Contains(cmmd.ID))
            {
                continue;
            }

            CIbody selfBody = cmmd.gameObject.GetComponent <CIbody>();
            if (selfBody != null)
            {
                //skip the body
                continue;
            }

            //we want to remove this node
            GameObject          nodeParent = cmmd.transform.parent.gameObject;
            CIbody              cibody     = nodeParent.GetComponent <CIbody>();
            MCSCharacterManager nCharMan   = nodeParent.GetComponent <MCSCharacterManager>();

            GameObject deleteObj = cmmd.gameObject;

            //make sure we're not removing the main figure or anything like that
            if (cibody == null && nCharMan == null)
            {
                deleteObj = nodeParent;
            }

            UnityEngine.Debug.Log("Found rogue item: " + deleteObj + " removing from " + RootObject.name);

            if (Application.isPlaying)
            {
                GameObject.Destroy(deleteObj);
            }
            else
            {
                GameObject.DestroyImmediate(deleteObj);
            }
        }
    }