Ejemplo n.º 1
0
                private static List <MaterialRef> FindOriginalMaterials(Object obj, string materialStr)
                {
                    List <MaterialRef> materialRefs = new List <MaterialRef>();

                    SerializedObject serializedObject = new SerializedObject(obj);

                    string[] materials = materialStr.Split(kItemSplitChar);

                    foreach (string material in materials)
                    {
                        SerializedProperty materialProp = serializedObject.FindProperty(material);

                        if (materialProp != null)
                        {
                            MaterialRef materialRef = new MaterialRef
                            {
                                _material     = materialProp.objectReferenceValue as Material,
                                _propertyPath = material
                            };
                            materialRefs.Add(materialRef);
                        }
                    }

                    return(materialRefs);
                }
 public static void MaterialCreate(
     MaterialRef materialRef)
 {
     ThrowOut(
         SUMaterialCreate(
             out materialRef.intPtr),
         "Could not create material.");
 }
 public static void MaterialRelease(
     MaterialRef materialRef)
 {
     ThrowOut(
         SUMaterialRelease(
             ref materialRef.intPtr),
         "Could not release material");
 }
Ejemplo n.º 4
0
 public static void MaterialSetColor(
     MaterialRef materialRef,
     Color color)
 {
     ThrowOut(
         SUMaterialSetColor(
             materialRef.intPtr,
             ref color),
         "Could not set color.");
 }
Ejemplo n.º 5
0
 public static void DrawingElementSetMaterial(
     DrawingElementRef drawingElementRef,
     MaterialRef materialRef)
 {
     ThrowOut(
         SUDrawingElementSetMaterial(
             drawingElementRef.intPtr,
             materialRef.intPtr),
         "Could not set drawing element material");
 }
Ejemplo n.º 6
0
            out int type); // really an enum, not an int

        public static void MaterialGetColorizeType(
            MaterialRef materialRef,
            out int type)
        {
            ThrowOut(
                SUMaterialGetColorizeType(
                    materialRef.intPtr,
                    out type),
                "Could not get material colorize type.");
        }
 public static void MaterialGetNameLegacyBehavior(
     MaterialRef materialRef,
     StringRef stringRef)
 {
     ThrowOut(
         SUMaterialGetNameLegacyBehavior(
             materialRef.intPtr,
             out stringRef.intPtr),
         "Could not get material legacy name.");
 }
 public static void MaterialSetColorizeType(
     MaterialRef materialRef,
     int colorizeType)
 {
     ThrowOut(
         SUMaterialSetColorizeType(
             materialRef.intPtr,
             colorizeType),
         "Could not set colorize type.");
 }
 public static void MaterialSetName(
     MaterialRef materialRef,
     string name)
 {
     ThrowOut(
         SUMaterialSetName(
             materialRef.intPtr,
             name),
         "Could not set name.");
 }
 public static void MaterialGetColor(
     MaterialRef materialRef,
     out Color color)
 {
     ThrowOut(
         SUMaterialGetColor(
             materialRef.intPtr,
             out color),
         "Could not get color.");
 }
Ejemplo n.º 11
0
 public static void MaterialSetTexture(
     MaterialRef materialRef,
     TextureRef textureRef)
 {
     ThrowOut(
         SUMaterialSetTexture(
             materialRef.intPtr,
             textureRef.intPtr),
         "Could not set texture.");
 }
Ejemplo n.º 12
0
 public static void FaceGetFrontMaterial(
     FaceRef faceRef,
     MaterialRef materialRef)
 {
     ThrowOut(
         SUFaceGetFrontMaterial(
             faceRef.intPtr,
             out materialRef.intPtr),
         "Could not get face front material");
 }
Ejemplo n.º 13
0
        static void ResolveMaterial(MaterialRef material, string relativeSceneDir, string fullSceneDir)
        {
            var mtrlName = ContentUtils.CreateSafeName(material.Name);
            var texPath  = material.Texture ?? "";

            material.Name    = Path.Combine(relativeSceneDir, mtrlName);
            material.Texture = Path.Combine(relativeSceneDir, texPath);
            var mtrlFileName = Path.Combine(fullSceneDir, mtrlName + ".material");


            if (!File.Exists(mtrlFileName))
            {
                var newMtrl = new BaseIllum();

                newMtrl.ColorTexture.Path     = ResolveTexture(relativeSceneDir, fullSceneDir, texPath, "", newMtrl.ColorTexture.Path);
                newMtrl.SurfaceTexture.Path   = ResolveTexture(relativeSceneDir, fullSceneDir, texPath, "_surf", newMtrl.SurfaceTexture.Path);
                newMtrl.NormalMapTexture.Path = ResolveTexture(relativeSceneDir, fullSceneDir, texPath, "_local", "_bump", newMtrl.NormalMapTexture.Path);
                newMtrl.EmissionTexture.Path  = ResolveTexture(relativeSceneDir, fullSceneDir, texPath, "_glow", newMtrl.EmissionTexture.Path);

                File.WriteAllText(mtrlFileName, BaseIllum.ExportToXml(newMtrl));
            }
        }
Ejemplo n.º 14
0
        public static void ModelGetMaterials(
            ModelRef modelRef,
            long numRequested,
            MaterialRef[] materialRefs,
            out long numReturned)
        {
            IntPtr[] intPtrs = new IntPtr[numRequested];

            ThrowOut(
                SUModelGetMaterials(
                    modelRef.intPtr,
                    numRequested,
                    intPtrs,
                    out numReturned),
                "Could not get materials.");

            for (int i = 0; i < numReturned; ++i)
            {
                materialRefs[i]        = new MaterialRef();
                materialRefs[i].intPtr = intPtrs[i];
            }
        }
Ejemplo n.º 15
0
                public static object PropertyField(object obj, GUIContent label, ref bool dataChanged, GUIStyle style, params GUILayoutOption[] options)
                {
                    MaterialRef materialRef = (MaterialRef)obj;

                    if (label == null)
                    {
                        label = new GUIContent();
                    }

                    label.text += " (" + materialRef + ")";

                    bool editorCollapsed = !EditorGUILayout.Foldout(!materialRef._editorCollapsed, label);

                    if (editorCollapsed != materialRef._editorCollapsed)
                    {
                        materialRef._editorCollapsed = editorCollapsed;
                        dataChanged = true;
                    }

                    if (!editorCollapsed)
                    {
                        int origIndent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel++;

                        eEdtiorType editorType = materialRef.GetMaterialIndex() == -1 ? eEdtiorType.Shared : eEdtiorType.Instanced;


                        //Draw type dropdown
                        {
                            EditorGUI.BeginChangeCheck();
                            editorType = (eEdtiorType)EditorGUILayout.EnumPopup("Material Type", editorType);

                            if (EditorGUI.EndChangeCheck())
                            {
                                dataChanged = true;
                                materialRef = new MaterialRef(editorType == eEdtiorType.Shared ? -1 : 0);
                            }
                        }

                        //Draw renderer field
                        if (editorType == eEdtiorType.Instanced)
                        {
                            bool renderChanged = false;
                            ComponentRef <Renderer> rendererComponentRef = SerializationEditorGUILayout.ObjectField(materialRef.GetRenderer(), new GUIContent("Renderer"), ref renderChanged);

                            if (renderChanged)
                            {
                                dataChanged = true;
                                materialRef = new MaterialRef(rendererComponentRef, 0);
                            }

                            //Show drop down for materials
                            Renderer renderer = rendererComponentRef.GetComponent();

                            if (renderer != null)
                            {
                                string[] materialNames = new string[renderer.sharedMaterials.Length];

                                for (int i = 0; i < materialNames.Length; i++)
                                {
                                    materialNames[i] = renderer.sharedMaterials[i].name;
                                }

                                EditorGUI.BeginChangeCheck();
                                int materialIndex = EditorGUILayout.Popup("Material", materialRef.GetMaterialIndex(), materialNames);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    dataChanged = true;
                                    materialRef = new MaterialRef(rendererComponentRef, materialIndex);
                                }
                            }
                        }
                        else
                        {
                            bool assetChanged            = false;
                            AssetRef <Material> assetRef = SerializationEditorGUILayout.ObjectField(materialRef.GetAsset(), new GUIContent("Material"), ref assetChanged);

                            if (assetChanged)
                            {
                                dataChanged = true;
                                materialRef = new MaterialRef(assetRef);
                            }
                        }

                        EditorGUI.indentLevel = origIndent;
                    }


                    return(materialRef);
                }
Ejemplo n.º 16
0
		static void ResolveMaterial ( MaterialRef material, string relativeSceneDir, string fullSceneDir )
		{
			var mtrlName		=	ContentUtils.CreateSafeName( material.Name );
			var texPath			=	material.Texture ?? "";

			material.Name		=	Path.Combine( relativeSceneDir, mtrlName );
			material.Texture	=	Path.Combine( relativeSceneDir, texPath );
			var mtrlFileName	=	Path.Combine( fullSceneDir, mtrlName + ".material" );


			if (!File.Exists(mtrlFileName)) {

				var newMtrl =	new BaseIllum();

				newMtrl.ColorTexture.Path		=	ResolveTexture( relativeSceneDir, fullSceneDir, texPath, ""			, newMtrl.ColorTexture.Path		);  
				newMtrl.SurfaceTexture.Path		=	ResolveTexture( relativeSceneDir, fullSceneDir, texPath, "_surf"	, newMtrl.SurfaceTexture.Path	);  
				newMtrl.NormalMapTexture.Path	=	ResolveTexture( relativeSceneDir, fullSceneDir, texPath, "_local"	, newMtrl.NormalMapTexture.Path	);  
				newMtrl.EmissionTexture.Path	=	ResolveTexture( relativeSceneDir, fullSceneDir, texPath, "_glow"	, newMtrl.EmissionTexture.Path	);  

				File.WriteAllText( mtrlFileName, BaseIllum.ExportToXml(newMtrl) );
			}

		}
 protected override void ClearStaticValue()
 {
     _value = new MaterialRef();
 }
Ejemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="flags"></param>
        /// <param name="blendMode"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public Material GetMaterial(int flags, BlendMode blendMode, uint group)
        {
            if (blendMode != BlendMode.Normal && BlendModeUtils.Factors[(int)blendMode].pma)
            {
                flags |= (int)MaterialFlags.ColorFilter;
            }

            List <MaterialRef> items;

            if (!_materials.TryGetValue(flags, out items))
            {
                items             = new List <MaterialRef>();
                _materials[flags] = items;
            }

            int         frameId = Time.frameCount;
            int         cnt     = items.Count;
            MaterialRef result  = null;

            for (int i = 0; i < cnt; i++)
            {
                MaterialRef item = items[i];

                if (item.group == group && item.blendMode == blendMode)
                {
                    if (item.frame != frameId)
                    {
                        firstMaterialInFrame = true;
                        item.frame           = frameId;
                    }
                    else
                    {
                        firstMaterialInFrame = false;
                    }

                    if (_combineTexture)
                    {
                        item.material.SetTexture(ShaderConfig.ID_AlphaTex, _texture.alphaTexture);
                    }

                    return(item.material);
                }
                else if (result == null && (item.frame > frameId || item.frame < frameId - 1)) //collect materials if it is unused in last frame
                {
                    result = item;
                }
            }

            if (result == null)
            {
                result = new MaterialRef()
                {
                    material = CreateMaterial(flags)
                };
                items.Add(result);
            }
            else if (_combineTexture)
            {
                result.material.SetTexture(ShaderConfig.ID_AlphaTex, _texture.alphaTexture);
            }

            if (result.blendMode != blendMode)
            {
                BlendModeUtils.Apply(result.material, blendMode);
                result.blendMode = blendMode;
            }

            result.group         = group;
            result.frame         = frameId;
            firstMaterialInFrame = true;
            return(result.material);
        }