Esempio n. 1
0
        //TODO: this is a temporary hack until we have proper meta
        //This is just to get the path to the manifest file for LOD0 so we can figure out which morphs are available to the figure, nothing more
        protected string GetMeshKeyFromFigure(GameObject obj)
        {
            CoreMeshMetaData cmmd = obj.GetComponentInChildren <CoreMeshMetaData> ();

            if (cmmd != null)
            {
                string key = cmmd.geometryId;
                return(key);
            }

            /*
             * //we need to find a gameobject that includes the figure and use that runtime path
             * CoreMesh[] cms = obj.GetComponentsInChildren<CoreMesh>();
             * foreach (CoreMesh cm in cms) {
             *      if (cm.meshType == MESH_TYPE.BODY && cm.runtimeMorphPath.Length > 0) {
             *              return cm.runtimeMorphPath;
             *      }
             * }
             *
             * //if that fails, try to get it from the core mesh meta data, note the names may not always match....
             *
             * CoreMeshMetaData cmmd = obj.GetComponentInChildren<CoreMeshMetaData> ();
             * if (cmmd != null) {
             *      string key = cmmd.geometryId + "/" + cmmd.geometryId + "/" + cmmd.geometryId + "_LOD0";
             *      return key;
             * }
             */

            /*
             *
             * //coremesh isn't attached to the root figure, it is to children though...
             * CSBoneService boneService = obj.GetComponent<CSBoneService>();
             * if (boneService != null) {
             *      CoreMesh[] coreMeshes =boneService.gameObject.GetComponentsInChildren<CoreMesh> ();
             *      if(coreMeshes.Count > 0){
             *
             *
             * }
             *
             * CoreMesh cm = obj.GetComponent<CoreMesh> ();
             *
             * if(cm == null || cm.runtimeMorphPath.Length <= 0){
             *      //can we attempt to infer it?
             *      throw new Exception("Unknown figure data");
             * }
             *
             * return cm.runtimeMorphPath;
             *
             */

            throw new Exception("Unknown Figure");
        }
Esempio n. 2
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. 3
0
        protected void ProcessNode(GameObject rootNode, AssetSchematic rootSchematic, GameObject currentNode, Dictionary <string, AssetSchematic> schematicLookup)
        {
            //what am i?
            AssetSchematic schematic = GetSchematicFromGameObject(currentNode, schematicLookup);

            //strip any components we don't understand
            Component[] components = currentNode.GetComponents <Component>();
            for (int i = 0; i < components.Length; i++)
            {
                Type   type     = components[i].GetType();
                string typeName = type.ToString();

                if (componentWhiteList.Contains(typeName))
                {
                    continue;
                }

                //only strip these if we're in play mode, it's possible we could actually mess stuff up permanently if not
                if (Application.isPlaying)
                {
                    GameObject.Destroy(components[i]);
                }
            }

            //Debug.Log ("Current Node: " + currentNode + " Schematic: " + (schematic==null?"null":"not null"));

            bool skip = false;

            if (schematic != null)
            {
                //UnityEngine.Debug.Log("Found a node with a schematic: " + currentNode.name);

                string guid = schematic.origin_and_description.mcs_id;
                //UnityEngine.Debug.Log("node a: " + currentNode.name + " | " + guid + " | " + schematic.type_and_function.artisttools_function + " | " + schematic.type_and_function.item_function + " | " + rootSchematic.type_and_function.item_function);
                //found the schematic, do something with it

                /*
                 *              if (currentNode.transform.parent == null && currentNode.GetInstanceID()==rootNode.GetInstanceID())
                 *              {
                 *
                 *                      GameObject tgo = new GameObject ();
                 *                      tgo.name = currentNode.name + " Root";
                 *                      currentNode.transform.SetParent (tgo.transform);
                 *              }
                 */

                GameObject parentNode;

                if (currentNode.transform.parent != null)
                {
                    parentNode = currentNode.transform.parent.gameObject;
                }
                else
                {
                    parentNode = currentNode;
                }

                //UnityEngine.Debug.Log("Processing node: " + currentNode.name + " type: " + schematic.type_and_function.hierarchy_rank);

                switch (schematic.type_and_function.artisttools_function)
                {
                case ArtistToolsFunction.material:
                    break;

                case ArtistToolsFunction.item:

                    //does my parent have a CostumeItem and CoreMeshMetaData, if yes bail on processing
                    // You can see an example item in the Lawless Survivor outfit "LSPants", the nodes will
                    // look like LSPants -> LSPants -> LSPants_LOD0, the double name on the top is causing problems
                    // which this check fixes
                    if (currentNode.transform.parent != null)
                    {
                        CoreMeshMetaData cmmdParent = parentNode.GetComponent <CoreMeshMetaData>();
                        CostumeItem      ciParent   = parentNode.GetComponent <CostumeItem>();

                        if (cmmdParent != null && ciParent != null)
                        {
                            //UnityEngine.Debug.LogWarning("Parent node has CoreMeshMetaData and CostumeItem, skipping node: " + currentNode.name);
                            skip = true;
                            break;
                        }
                    }

                    CoreMeshMetaData coreMeshMetaData = null;
                    if (schematic.type_and_function.hierarchy_rank == HierarchyRank.item)
                    {
                        //AssetPrepper -> PrepForMCS does it this way
                        coreMeshMetaData = currentNode.AddComponent <CoreMeshMetaData>();
                        AttachingCIItemToNode(currentNode, schematic);
                    }
                    else
                    {
                        //Artist tools does it this way
                        coreMeshMetaData = parentNode.AddComponent <CoreMeshMetaData>();
                    }
                    coreMeshMetaData.vendorId   = schematic.origin_and_description.vendor_id;
                    coreMeshMetaData.versionId  = schematic.version_and_control.item_version.ToString();
                    coreMeshMetaData.geometryId = schematic.origin_and_description.name;
                    coreMeshMetaData.ID         = schematic.origin_and_description.mcs_id;

                    //commented out fields can be skipped safely
                    //coreMeshMetaData.compatabilityBase = schematic.compatibilities[0];
                    //coreMeshMetaData.compatibilities = schematic.compatibilities;
                    //coreMeshMetaData.declarativeUse = "";
                    //coreMeshMetaData.controllerScales = ...';
                    coreMeshMetaData.item_id       = schematic.origin_and_description.mcs_id;
                    coreMeshMetaData.collection_id = schematic.origin_and_description.collection_id;
                    coreMeshMetaData.rank          = schematic.type_and_function.hierarchy_rank;
                    coreMeshMetaData.function      = schematic.type_and_function.item_function;
                    //coreMeshMetaData.schematic = ...;
                    coreMeshMetaData.collection_version = schematic.version_and_control.collection_version;
                    coreMeshMetaData.item_version       = schematic.version_and_control.item_version;
                    coreMeshMetaData.mcs_version        = schematic.version_and_control.mcs_version;
                    coreMeshMetaData.item_name          = schematic.origin_and_description.name;
                    coreMeshMetaData.collection_name    = schematic.origin_and_description.collection_name;

                    switch (rootSchematic.type_and_function.item_function)
                    {
                    case ItemFunction.soft_wearable:
                        coreMeshMetaData.meshType = CONSTANTS.MESH_TYPE.CLOTH;
                        break;

                    case ItemFunction.hair:
                        coreMeshMetaData.meshType = CONSTANTS.MESH_TYPE.HAIR;
                        break;

                    case ItemFunction.prop:
                        coreMeshMetaData.meshType = CONSTANTS.MESH_TYPE.PROP;
                        break;
                    }
                    break;

                case ArtistToolsFunction.model:
                    //handles path for artist tools
                    //AttachingCIItemToNode(parentNode, schematic);

                    break;

                case ArtistToolsFunction.geometry:
                    //CoreMesh, but we'll handle it via hierarchy rank instead
                    AttachCoreMeshToNode(currentNode, schematic, rootSchematic);

                    break;
                }

                if (!skip)
                {
                    switch (schematic.type_and_function.hierarchy_rank)
                    {
                    case HierarchyRank.geometry:
                        AttachCoreMeshToNode(currentNode, schematic, rootSchematic);
                        break;
                    }
                }
            }

            //dive into each child
            for (int i = 0; i < currentNode.transform.childCount; i++)
            {
                GameObject child = currentNode.transform.GetChild(i).gameObject;
                ProcessNode(rootNode, rootSchematic, child, schematicLookup);
            }


            //return nothing, as we've modified the current game object
        }
Esempio n. 4
0
        public override void OnInspectorGUI()
        {
            GUIStyle mcsDefaultButtonStyle = new GUIStyle(GUI.skin.button);

            mcsDefaultButtonStyle.margin  = new RectOffset(10, 10, 5, 5);
            mcsDefaultButtonStyle.padding = new RectOffset(5, 5, 5, 5);

            CIclothing       comp = (CIclothing)target;
            CoreMeshMetaData cmmd = comp.gameObject.GetComponent <CoreMeshMetaData> ();

            comp.dazName = EditorGUILayout.TextField("Daz Name", comp.dazName);
            comp.ID      = EditorGUILayout.TextField("ID", comp.ID);
            //comp.LODlist = EditorGUILayout.Field

            SerializedProperty lodList = serializedObject.FindProperty("LODlist");

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(lodList, true);
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }


            comp.currentLODlevel = EditorGUILayout.FloatField("Current LOD Level", comp.currentLODlevel);
            comp.meshType        = (MESH_TYPE)EditorGUILayout.EnumPopup("Mesh Type", comp.meshType);

            comp.isAttached = EditorGUILayout.Toggle("Is Attached", comp.isAttached);
            bool isVisible = EditorGUILayout.Toggle("Is Visible", comp.isVisible);

            comp.SetVisibility(isVisible);

            if (cmmd != null)
            {
                List <MaterialOption> mos = GetPotentialMaterialsFromAssetId(cmmd.collection_name, comp.dazName);
                if (mos != null)
                {
                    List <string> options = new List <string>();
                    foreach (MaterialOption mo in mos)
                    {
                        options.Add(mo.displayName);
                    }

                    if (mos.Count > 0)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("Preconfigured Materials");
                        _materialOptionIndex = EditorGUILayout.Popup(_materialOptionIndex, options.ToArray());
                        if (_materialOptionIndex >= 0)
                        {
                            Material m = AssetDatabase.LoadAssetAtPath <Material>(mos[_materialOptionIndex].assetPath);
                            if (m != null)
                            {
                                Renderer[] renderers = comp.gameObject.GetComponentsInChildren <Renderer>();
                                foreach (Renderer renderer in renderers)
                                {
                                    renderer.material = m;
                                }
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }

            //comp.alphaMask = (Texture2D) EditorGUILayout.ObjectField ("Alpha Mask (deprecated)", comp.alphaMask, typeof (Texture2D), false);

            foreach (MATERIAL_SLOT slot in Enum.GetValues(typeof(MATERIAL_SLOT)))
            {
                if (slot != MATERIAL_SLOT.HEAD && slot != MATERIAL_SLOT.BODY)
                {
                    continue;
                }

                Texture2D tex = comp.alphaMasks.ContainsKey(slot) ? comp.alphaMasks [slot] : null;



                //NOTE: let's NOT do this, this would be a legacy 1.0 -> 1.5, but I think we should have these explicitly separate
                // we'll only process the old texture slot

                /*
                 * if (slot == MATERIAL_SLOT.BODY && tex == null) {
                 *      tex = comp.alphaMask;
                 * }
                 */

                comp.alphaMasks [slot] = (Texture2D)EditorGUILayout.ObjectField("Alpha Mask: " + slot.ToString(), tex, typeof(Texture2D), false);
            }


            if (GUILayout.Button("Recalculate Bounds", mcsDefaultButtonStyle))
            {
                comp.RecalculateBounds();
            }



            //handle the dynamic list of elements

            //EditorGUILayout.LabelField("LOD Level", myTarget.Level.ToString());
        }
Esempio n. 5
0
        /// <summary>
        /// Create a NEW game object by cloning an existing game object and passing in schematics or reading them directly off the nodes
        /// NOTE: this works for BOTH runtime and editor and from loose schematics or embedded schematics
        /// NOTE: you will likely want to specificy several callbacks based on the delegates at the top of this file (textures/mats/guid/scehmatic/etc)
        /// </summary>
        /// <param name="gameObjectIn"></param>
        /// <param name="schematicsIn"></param>
        /// <returns></returns>
        public GameObject CreateGameObjectFromExistinGameObject(GameObject gameObjectIn, Dictionary <string, AssetSchematic> schematicLookup, List <AssetSchematic> schematicsIn = null)
        {
            string     targetName = gameObjectIn.name;
            GameObject targetGO   = GameObject.Instantiate(gameObjectIn);

            targetGO.name = gameObjectIn.name; //ditch things like "(Clone)"



            if (schematicsIn == null || schematicsIn.Count <= 0)
            {
                GetAllSchematicsFromNodes(targetGO, schematicLookup);
            }
            else
            {
                schematics = schematicsIn;
            }
            IndexSchematics(schematicLookup);

            //Debug.Log ("Number of schematics: " + schematics.Count + " | vs: " + (schematicsIn != null ?  schematicsIn.Count.ToString() : "null"));

            GameObject     rootNode      = targetGO;
            AssetSchematic rootSchematic = GetSchematicFromGameObject(rootNode, schematicLookup);


            if (rootSchematic == null)
            {
                //this is the wrong root node, let's check for a child that has the same name and or has a item_function defined
                for (int i = 0; i < targetGO.transform.childCount; i++)
                {
                    GameObject node = targetGO.transform.GetChild(i).gameObject;

                    if (node.name == targetName || MCS_Utilities.Paths.ScrubKey(node.name) == targetName)
                    {
                        rootNode      = node;
                        rootSchematic = GetSchematicFromGameObject(rootNode, schematicLookup);
                    }
                }
            }

            if (rootSchematic == null)
            {
                throw new Exception("Root schematic must not be null");
            }

            //Debug.Log ("Target: " + targetGO + " RootSchematic: " + rootSchematic.type_and_function.item_function);

            ProcessNode(rootNode, rootSchematic, targetGO, schematicLookup);

            if (rootSchematic.type_and_function.primary_function == PrimaryFunction.material)
            {
                Debug.Log("Found Material Asset Schematic.");
            }

            //do some final handling now that our stuff is assembled
            switch (rootSchematic.type_and_function.item_function)
            {
            case ItemFunction.soft_wearable:
            case ItemFunction.hair:
            case ItemFunction.prop:
                //CoreMeshMetaData coreMeshMetaData = targetGO.GetComponent<CoreMeshMetaData>();
                //if(rootSchematic.type_and_function.artisttools_function == ArtistToolsFunction.item)
                //{

                //}
                CoreMeshMetaData coreMeshMetaData = targetGO.GetComponentInChildren <CoreMeshMetaData>(true);

                /*
                 * if (coreMeshMetaData == null)
                 * {
                 *  coreMeshMetaData = targetGO.GetComponentInChildren<CoreMeshMetaData>(true);
                 * }
                 */

                CIclothing ciclothing = targetGO.GetComponentInChildren <CIclothing>(true);
                CIhair     cihair     = targetGO.GetComponentInChildren <CIhair>(true);
                CIprop     ciprop     = targetGO.GetComponentInChildren <CIprop>(true);

                CoreMesh[]      coreMeshes     = targetGO.GetComponentsInChildren <CoreMesh>(true);
                List <CoreMesh> listCoreMeshes = new List <CoreMesh>();

                foreach (CoreMesh coreMesh in coreMeshes)
                {
                    listCoreMeshes.Add(coreMesh);

                    //is the geometry id empty?
                    if (coreMeshMetaData.geometryId == null || coreMeshMetaData.geometryId.Length <= 0)
                    {
                        coreMeshMetaData.geometryId = coreMesh.gameObject.name;
                        //take the left half of the name if we find a "." , eg: "NMBoots_1462.Shape" -> "NMBoots_1462"
                        int pos = coreMeshMetaData.geometryId.LastIndexOf(".");
                        if (pos >= 0)
                        {
                            coreMeshMetaData.geometryId = coreMeshMetaData.geometryId.Substring(0, pos);
                        }
                    }
                }

                if (ciclothing != null)
                {
                    ciclothing.LODlist = listCoreMeshes;
                }
                if (cihair != null)
                {
                    cihair.LODlist = listCoreMeshes;
                }
                if (ciprop != null)
                {
                    ciprop.LODlist = listCoreMeshes;
                }
                break;
            }

            return(targetGO);
        }