Beispiel #1
0
        public void AttachingCIItemToNode(GameObject currentNode, AssetSchematic schematic)
        {
            switch (schematic.type_and_function.item_function)
            {
            case ItemFunction.soft_wearable:
                CIclothing ciclothing = currentNode.AddComponent <CIclothing>();
                ciclothing.meshType = CONSTANTS.MESH_TYPE.CLOTH;
                ciclothing.dazName  = schematic.origin_and_description.name;
                ciclothing.ID       = schematic.origin_and_description.mcs_id;


                if (schematic.structure_and_physics.item_structure.alpha_masks_key != null)
                {
                    for (int i = 0; i < schematic.structure_and_physics.item_structure.alpha_masks_key.Count(); i++)
                    {
                        string slot = schematic.structure_and_physics.item_structure.alpha_masks_key[i];
                        string path = schematic.structure_and_physics.item_structure.alpha_masks[i];


                        switch (slot)
                        {
                        case "BODY":
                            ciclothing.alphaMasks[CONSTANTS.MATERIAL_SLOT.BODY] = GetTextureFromPath(path, basePath);
                            break;

                        case "HEAD":
                            ciclothing.alphaMasks[CONSTANTS.MATERIAL_SLOT.HEAD] = GetTextureFromPath(path, basePath);
                            break;

                        case "EYE":
                            //do nothing, we don't support this slot yet
                            break;
                        }
                    }
                }


                break;

            case ItemFunction.hair:
                CIhair cihair = currentNode.AddComponent <CIhair>();
                if (schematic.structure_and_physics.item_structure.overlay != null)
                {
                    cihair.overlay      = GetTextureFromPath(schematic.structure_and_physics.item_structure.overlay, basePath);
                    cihair.overlayColor = AssetSchematicUtility.ConvertColorStringToColor(schematic.structure_and_physics.item_structure.overlay_color);
                }
                cihair.meshType = CONSTANTS.MESH_TYPE.HAIR;
                cihair.dazName  = schematic.origin_and_description.name;
                cihair.ID       = schematic.origin_and_description.mcs_id;
                break;

            case ItemFunction.prop:
                CIprop ciprop = currentNode.AddComponent <CIprop>();
                ciprop.meshType = CONSTANTS.MESH_TYPE.PROP;
                ciprop.dazName  = schematic.origin_and_description.name;
                ciprop.ID       = schematic.origin_and_description.mcs_id;
                break;
            }
        }
Beispiel #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);
        }
Beispiel #3
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);
        }