コード例 #1
0
ファイル: ModelMaterials.cs プロジェクト: datphL/libwarcraft
        public ModelMaterial(byte[] inData)
        {
            using (MemoryStream ms = new MemoryStream(inData))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    this.Flags     = (MaterialFlags)br.ReadUInt32();
                    this.Shader    = (ShaderTypes)br.ReadUInt32();
                    this.BlendMode = (BlendingMode)br.ReadUInt32();

                    this.FirstTextureOffset = br.ReadUInt32();
                    this.FirstColour        = br.ReadRGBA();
                    this.FirstFlags         = (MaterialFlags)br.ReadUInt32();

                    this.SecondTextureOffset = br.ReadUInt32();
                    this.SecondColour        = br.ReadRGBA();

                    this.GroundType         = new UInt32ForeignKey("TerrainType", "ID", br.ReadUInt32());
                    this.ThirdTextureOffset = br.ReadUInt32();
                    this.BaseDiffuseColour  = br.ReadRGBA();
                    this.ThirdFlags         = (MaterialFlags)br.ReadUInt32();

                    this.RuntimeData1 = br.ReadUInt32();
                    this.RuntimeData2 = br.ReadUInt32();
                    this.RuntimeData3 = br.ReadUInt32();
                    this.RuntimeData4 = br.ReadUInt32();
                }
            }
        }
コード例 #2
0
 public void FromStreamEx_TexTable(Stream s, PmxTextureTable tx, PmxElementFormat f = null)
 {
     Name       = PmxStreamHelper.ReadString(s, f);
     NameE      = PmxStreamHelper.ReadString(s, f);
     Diffuse    = V4_BytesConvert.FromStream(s);
     Specular   = V3_BytesConvert.FromStream(s);
     Power      = PmxStreamHelper.ReadElement_Float(s);
     Ambient    = V3_BytesConvert.FromStream(s);
     Flags      = (MaterialFlags)s.ReadByte();
     EdgeColor  = V4_BytesConvert.FromStream(s);
     EdgeSize   = PmxStreamHelper.ReadElement_Float(s);
     Tex        = tx.GetName(PmxStreamHelper.ReadElement_Int32(s, f.TexSize));
     Sphere     = tx.GetName(PmxStreamHelper.ReadElement_Int32(s, f.TexSize));
     SphereMode = (SphereModeType)s.ReadByte();
     if (s.ReadByte() == 0)
     {
         Toon = tx.GetName(PmxStreamHelper.ReadElement_Int32(s, f.TexSize));
     }
     else
     {
         int n = s.ReadByte();
         Toon = SystemToon.GetToonName(n);
     }
     Memo = PmxStreamHelper.ReadString(s, f);
     UpdateAttributeFromMemo();
     FaceCount = PmxStreamHelper.ReadElement_Int32(s);
     if (f.WithID)
     {
         base.UID = PmxStreamHelper.ReadElement_UInt(s);
         base.CID = PmxStreamHelper.ReadElement_UInt(s);
     }
 }
コード例 #3
0
        private static Shader GetShaderNoCache(MaterialFlags flags)
        {
            var noBackCull = (flags & MaterialFlags.NoBackCull) == MaterialFlags.NoBackCull;
            var alpha      = (flags & MaterialFlags.Alpha) == MaterialFlags.Alpha;
            var vehicle    = (flags & MaterialFlags.Vehicle) == MaterialFlags.Vehicle;

            if (vehicle && alpha)
            {
                return(Shader.Find("SanAndreasUnity/VehicleTransparent"));
            }

            if (vehicle)
            {
                return(Shader.Find("SanAndreasUnity/Vehicle"));
            }

            if (noBackCull && alpha)
            {
                return(Shader.Find("SanAndreasUnity/TransparentNoBackCull"));
            }

            if (noBackCull)
            {
                return(Shader.Find("SanAndreasUnity/NoBackCull"));
            }

            if (alpha)
            {
                return(Shader.Find("SanAndreasUnity/Transparent"));
            }

            return(Shader.Find("SanAndreasUnity/Default"));
        }
コード例 #4
0
        public ModelMaterial(byte[] inData)
        {
            using (MemoryStream ms = new MemoryStream(inData))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    this.Flags     = (MaterialFlags)br.ReadUInt32();
                    this.Shader    = (WMOFragmentShaderType)br.ReadUInt32();
                    this.BlendMode = (BlendingMode)br.ReadUInt32();

                    this.FirstTextureOffset = br.ReadUInt32();
                    this.FirstColour        = br.ReadRGBA();
                    this.FirstFlags         = (MaterialFlags)br.ReadUInt32();

                    this.SecondTextureOffset = br.ReadUInt32();
                    this.SecondColour        = br.ReadRGBA();

                    this.GroundType         = new ForeignKey <uint>(DatabaseName.TerrainType, nameof(DBCRecord.ID), br.ReadUInt32());            // TODO: Implement TerrainTypeRecord
                    this.ThirdTextureOffset = br.ReadUInt32();
                    this.BaseDiffuseColour  = br.ReadRGBA();
                    this.ThirdFlags         = (MaterialFlags)br.ReadUInt32();

                    this.RuntimeData1 = br.ReadUInt32();
                    this.RuntimeData2 = br.ReadUInt32();
                    this.RuntimeData3 = br.ReadUInt32();
                    this.RuntimeData4 = br.ReadUInt32();
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Read material from library.
        /// </summary>
        /// <param name="reader"></param>
        public void ReadFromFile(BinaryReader reader)
        {
            materialHash = reader.ReadUInt64();
            materialName = StringHelpers.ReadString32(reader);

            ufo1  = reader.ReadByte();
            ufo2  = reader.ReadByte();
            flags = (MaterialFlags)reader.ReadInt32();
            ufo4  = reader.ReadByte();
            ufo5  = reader.ReadInt32();
            ufo6  = reader.ReadInt32();

            shaderID   = reader.ReadUInt64();
            shaderHash = reader.ReadUInt32();

            int spCount = reader.ReadInt32();

            parameters = new Dictionary <string, ShaderParameter>();
            for (int i = 0; i != spCount; i++)
            {
                var param = new ShaderParameter(reader);
                parameters.Add(param.ID, param);
            }

            int spsCount = reader.ReadInt32();

            samplers = new Dictionary <string, ShaderParameterSampler>();
            for (int i = 0; i != spsCount; i++)
            {
                var shader = new ShaderParameterSampler(reader);
                samplers.Add(shader.ID, shader);
            }
        }
コード例 #6
0
ファイル: Material.cs プロジェクト: LoOnyBiker/Mafia2Toolkit
        /// <summary>
        /// Read material from library.
        /// </summary>
        /// <param name="reader"></param>
        public void ReadFromFile(BinaryReader reader)
        {
            materialHash = reader.ReadUInt64();
            materialName = Functions.ReadString32(reader);

            ufo1  = reader.ReadByte();
            ufo2  = reader.ReadByte();
            flags = (MaterialFlags)reader.ReadInt32();
            ufo4  = reader.ReadByte();
            ufo5  = reader.ReadInt32();
            ufo6  = reader.ReadInt32();

            shaderID   = reader.ReadUInt64();
            shaderHash = reader.ReadUInt32();

            sp_count = reader.ReadInt32();
            sp       = new ShaderParameter[sp_count];
            for (int i = 0; i != sp_count; i++)
            {
                sp[i] = new ShaderParameter(reader);
            }

            sps_count = reader.ReadInt32();
            sps       = new ShaderParameterSampler[sps_count];
            for (int i = 0; i != sps_count; i++)
            {
                sps[i] = new ShaderParameterSampler(reader);
            }
        }
コード例 #7
0
 public bool Fits(MaterialFlags b)
 {
     return((!hasDiffuse || b.hasDiffuse) &&
            (!hasSpecular || b.hasSpecular) &&
            (!hasEmissive || b.hasEmissive) &&
            (!hasNormal || b.hasNormal) &&
            hasAlpha == b.hasAlpha);
 }
コード例 #8
0
 static void SetMixedValueMatrialFlags(MaterialEditor materialEditor, MaterialFlags allFlags, MaterialFlags mixedValueFlags)
 {
     foreach (Material material in materialEditor.targets)
     {
         MaterialFlags materialFlags = (MaterialFlags)material.GetInt(MaterialFlagsPropName);
         materialFlags = (materialFlags & mixedValueFlags) | (allFlags & ~mixedValueFlags);
         material.SetInt(MaterialFlagsPropName, (int)materialFlags);
     }
 }
コード例 #9
0
    private void InitizalizeTexture(MaterialType type, MaterialFlags flags)
    {
        if (!_cachedMaterials.ContainsKey(type))
        {
            _cachedMaterials[type] = new Dictionary <MaterialFlags, Material>();
        }
        if (!_cachedMaterials[type].ContainsKey(flags))
        {
            switch (type)
            {
            case MaterialType.Opaque:
                _cachedMaterials[type][flags] = new Material(baseStandardMaterial);
                break;

            case MaterialType.Stencil:
                _cachedMaterials[type][flags] = new Material(baseStandardMaterialCutout);
                break;

            case MaterialType.Transparent:
                _cachedMaterials[type][flags] = new Material(baseStandardMaterialTransparent);
                break;

            case MaterialType.SplatMap:
                _cachedMaterials[type][flags] = new Material(baseSplatMaterial);
                break;

            default:
                break;
            }
            if ((flags & MaterialFlags.Contaminants) == MaterialFlags.Contaminants)
            {
                _cachedMaterials[type][flags].EnableKeyword("CONTAMINANTS");
            }
            else
            {
                _cachedMaterials[type][flags].DisableKeyword("CONTAMINANTS");
            }

            if ((flags & MaterialFlags.Grass) == MaterialFlags.Grass)
            {
                _cachedMaterials[type][flags].EnableKeyword("GRASS");
            }
            else
            {
                _cachedMaterials[type][flags].DisableKeyword("GRASS");
            }

            foreach (var item in vectorProperties)
            {
                _cachedMaterials[type][flags].SetVector(item.Key, item.Value);
            }
            foreach (var item in textureProperties)
            {
                _cachedMaterials[type][flags].SetTexture(item.Key, item.Value);
            }
        }
    }
コード例 #10
0
ファイル: MainForm.cs プロジェクト: yuri410/lrvbsvnicg
 private void MainForm_Load(object sender, EventArgs e)
 {
     for (RenderPriority i = RenderPriority.First; i <= RenderPriority.Last; i++)
     {
         comboBox4.Items.Add(i.ToString());
     }
     for (MaterialFlags f = MaterialFlags.None; f <= MaterialFlags.BlendBright_Color; f++)
     {
         comboBox5.Items.Add(f.ToString());
     }
 }
コード例 #11
0
 public void SetFlag(MaterialFlags f, bool val)
 {
     if (val)
     {
         Flags |= f;
     }
     else
     {
         Flags &= ~f;
     }
 }
コード例 #12
0
 static MaterialFlags SetMaterialFlag(MaterialFlags allFlags, MaterialFlags flag, bool enable)
 {
     if (enable)
     {
         return(allFlags | flag);
     }
     else
     {
         return(allFlags & ~flag);
     }
 }
コード例 #13
0
        private static Shader GetShader(MaterialFlags flags)
        {
            if (_sShaders.ContainsKey(flags))
            {
                return(_sShaders[flags]);
            }

            var shader = GetShaderNoCache(flags);

            _sShaders.Add(flags, shader);
            return(shader);
        }
コード例 #14
0
 public MaterialLibraryMaterial(string name, MaterialFlags flags, Color emissiveColor, float[] uvScroll, bool isBackfaceCullingDisabled,
                                string shaderName, bool isSimpleShader, byte opacity, Color color)
 {
     this.Name                      = name;
     this.Flags                     = flags;
     this.EmissiveColor             = emissiveColor;
     this.UVScroll                  = uvScroll;
     this.IsBackfaceCullingDisabled = isBackfaceCullingDisabled;
     this.ShaderName                = shaderName;
     this.IsSimpleShader            = isSimpleShader;
     this.Opacity                   = opacity;
     this.Color                     = color;
 }
コード例 #15
0
    static MaterialFlags GetMixedValueMaterialFlags(MaterialEditor materialEditor)
    {
        MaterialFlags onFlags  = MaterialFlags.None;
        MaterialFlags offFlags = ~MaterialFlags.None;

        foreach (Material material in materialEditor.targets)
        {
            MaterialFlags materialFlags = (MaterialFlags)material.GetInt(MaterialFlagsPropName);
            onFlags  |= materialFlags;
            offFlags &= materialFlags;
        }

        return(onFlags ^ offFlags);
    }
コード例 #16
0
    static void DrawFlagToggleProperty(GUIContent label, MaterialFlags flag, ref MaterialFlags allFlags, ref MaterialFlags mixedValueFlags)
    {
        bool value      = GetMaterialFlag(allFlags, flag);
        bool mixedValue = GetMaterialFlag(mixedValueFlags, flag);

        EditorGUI.BeginChangeCheck();
        EditorGUI.showMixedValue = mixedValue;
        value = EditorGUILayout.Toggle(label, value);
        EditorGUI.showMixedValue = false;
        if (EditorGUI.EndChangeCheck())
        {
            mixedValueFlags = SetMaterialFlag(mixedValueFlags, flag, false);
        }

        allFlags = SetMaterialFlag(allFlags, flag, value);
    }
コード例 #17
0
    static bool DrawFlagFoldoutProperty(GUIContent label, MaterialFlags flag, ref MaterialFlags allFlags, ref MaterialFlags mixedValueFlags)
    {
        bool value      = GetMaterialFlag(allFlags, flag);
        bool mixedValue = GetMaterialFlag(mixedValueFlags, flag);

        EditorGUI.BeginChangeCheck();
        value = EditorGUILayout.Foldout(value || mixedValue, label);
        if (EditorGUI.EndChangeCheck())
        {
            mixedValueFlags = SetMaterialFlag(mixedValueFlags, flag, false);
        }

        allFlags = SetMaterialFlag(allFlags, flag, value);

        return(value);
    }
コード例 #18
0
ファイル: Material.cs プロジェクト: zbx1425/OpenBVE
 /// <summary>Clones an existing material</summary>
 public Material(Material Prototype)
 {
     this.Color               = Prototype.Color;
     this.EmissiveColor       = Prototype.EmissiveColor;
     this.TransparentColor    = Prototype.TransparentColor;
     this.Flags               = Prototype.Flags;
     this.DaytimeTexture      = Prototype.DaytimeTexture;
     this.NighttimeTexture    = Prototype.NighttimeTexture;
     this.BlendMode           = Prototype.BlendMode;
     this.GlowAttenuationData = Prototype.GlowAttenuationData;
     this.TextColor           = Prototype.TextColor;
     this.BackgroundColor     = Prototype.BackgroundColor;
     this.TextPadding         = Prototype.TextPadding;
     this.Font     = Prototype.Font;
     this.WrapMode = Prototype.WrapMode;
 }
コード例 #19
0
ファイル: Material.cs プロジェクト: zbx1425/OpenBVE
 /// <summary>Creates a new Material with default properties</summary>
 public Material()
 {
     this.Color               = Color32.White;
     this.EmissiveColor       = Color24.Black;
     this.TransparentColor    = Color24.Black;
     this.Flags               = MaterialFlags.None;
     this.DaytimeTexture      = null;
     this.NighttimeTexture    = null;
     this.BlendMode           = MeshMaterialBlendMode.Normal;
     this.GlowAttenuationData = 0;
     this.TextColor           = System.Drawing.Color.Black;
     this.BackgroundColor     = System.Drawing.Color.White;
     this.TextPadding         = new Vector2(0, 0);
     this.Font     = "Arial";
     this.WrapMode = null;
 }
コード例 #20
0
        public SceneObject BuildSquareMesh(Func<int, int, bool> shouldNotRenderTile, MaterialFlags materialProperties, RectangleF bounds, string description = null)
        {
            var trianglesPerRow = MaxTileRows;
            var trianglesPerCol = MaxTileColumns;
            var triangles = new List<IndexedTriangleWithNormal>(trianglesPerRow * trianglesPerCol * 2);

            for (var row = 0; row < trianglesPerRow; row++)
            {
                for (var col = 0; col < trianglesPerCol; col++)
                {
                    if (shouldNotRenderTile(col, row)) continue;

                    var topLeft = GetIndexAt(row, col);
                    var topRight = GetIndexAt(row, col + 1);
                    var bottomLeft = GetIndexAt(row + 1, col);
                    var bottomRight = GetIndexAt(row + 1, col + 1);

                    if (IsOutOfBounds(topLeft, bounds)
                        && IsOutOfBounds(topRight, bounds)
                        && IsOutOfBounds(bottomLeft, bounds)
                        && IsOutOfBounds(bottomRight, bounds))
                        continue;

                    triangles.Add(MakeTriangle(bottomLeft, topRight, topLeft));
                    triangles.Add(MakeTriangle(topRight, bottomLeft, bottomRight));
                }
            }

            if (triangles.Count == 0)
            {
                return null;
            }

            var vertices = _vertices.ToArray();
            return new SceneObject
            {
                Bounds = BoundingBox.FromPoints(vertices),
                MaterialProperties = materialProperties,
                Geometry = new TriangleMesh
                {
                    Vertices = vertices,
                    Triangles = triangles.ToArray()
                },
                Description = description
            };
        }
コード例 #21
0
ファイル: Material.cs プロジェクト: LoOnyBiker/Mafia2Toolkit
 /// <summary>
 /// Construct material based on basic material.
 /// </summary>
 public Material()
 {
     materialName = "NEW_MATERIAL";
     materialHash = 1;
     shaderHash   = 3388704532;
     shaderID     = 4894707398632176459;
     ufo1         = 128;
     ufo2         = 0;
     flags        = (MaterialFlags)31461376;
     ufo4         = 0;
     ufo5         = 0;
     ufo6         = 0;
     sp_count     = 0;
     sp           = new ShaderParameter[0];
     sps_count    = 1;
     sps          = new ShaderParameterSampler[1];
     sps[0]       = new ShaderParameterSampler();
 }
コード例 #22
0
        /// <summary>
        /// Construct material based on basic material.
        /// </summary>
        public Material()
        {
            materialName = "NEW_MATERIAL";
            materialHash = 1;
            shaderHash   = 3388704532;
            shaderID     = 4894707398632176459;
            ufo1         = 128;
            ufo2         = 0;
            flags        = (MaterialFlags)31461376;
            ufo4         = 0;
            ufo5         = 0;
            ufo6         = 0;
            parameters   = new Dictionary <string, ShaderParameter>();
            samplers     = new Dictionary <string, ShaderParameterSampler>();
            var spp = new ShaderParameterSampler();

            samplers.Add(spp.ID, spp);
        }
コード例 #23
0
 public void FromStreamEx(Stream s, PmxElementFormat f = null)
 {
     Name       = PmxStreamHelper.ReadString(s, f);
     NameE      = PmxStreamHelper.ReadString(s, f);
     Diffuse    = V4_BytesConvert.FromStream(s);
     Specular   = V3_BytesConvert.FromStream(s);
     Power      = PmxStreamHelper.ReadElement_Float(s);
     Ambient    = V3_BytesConvert.FromStream(s);
     Flags      = (MaterialFlags)s.ReadByte();
     EdgeColor  = V4_BytesConvert.FromStream(s);
     EdgeSize   = PmxStreamHelper.ReadElement_Float(s);
     Tex        = PmxStreamHelper.ReadString(s, f);
     Sphere     = PmxStreamHelper.ReadString(s, f);
     SphereMode = (SphereModeType)s.ReadByte();
     Toon       = PmxStreamHelper.ReadString(s, f);
     Memo       = PmxStreamHelper.ReadString(s, f);
     FaceCount  = PmxStreamHelper.ReadElement_Int32(s);
 }
コード例 #24
0
    private static MaterialFlags ReadMaterialFlags(Stream stream)
    {
        byte[] arrayOfBytes = new byte[4];
        stream.Read(arrayOfBytes, 0, 4);
        BitArray      flags         = new BitArray(arrayOfBytes);
        MaterialFlags materialFlags = new MaterialFlags();

        materialFlags.F_UNLIT    = flags[0];   // disable lighting logic in shader (but can still use vertex colors)
        materialFlags.F_UNFOGGED = flags[1];   // disable fog shading (rarely used)
        materialFlags.F_UNCULLED = flags[2];   // two-sided
        materialFlags.F_EXTLIGHT = flags[3];   // darkened, the intern face of windows are flagged 0x08
        materialFlags.F_SIDN     = flags[4];   // (bright at night, unshaded) (used on windows and lamps in Stormwind, for example) (see emissive color)
        materialFlags.F_WINDOW   = flags[5];   // lighting related (flag checked in CMapObj::UpdateSceneMaterials)
        materialFlags.F_CLAMP_S  = flags[6];   // tex clamp S (force this material's textures to use clamp s addressing) //TextureWrappingClamp
        materialFlags.F_CLAMP_T  = flags[7];   // tex clamp T (force this material's textures to use clamp t addressing) //TextureWrappingRepeat
        materialFlags.flag_0x100 = flags[8];

        return(materialFlags);
    }
コード例 #25
0
        public UnityEngine.Material[] GetMaterials(MaterialFlags flags,
                                                   Action <UnityEngine.Material> setupMaterial)
        {
            if (_materials.ContainsKey(flags))
            {
                return(_materials[flags]);
            }

            var mats = _geom.Materials.Select(x => {
                var mat = Convert(x, _textureDictionaries, flags);
                setupMaterial(mat);
                return(mat);
            }).ToArray();

            mats = _geom.MaterialSplits.Select(x => mats[x.MaterialIndex]).ToArray();

            _materials.Add(flags, mats);

            return(mats);
        }
コード例 #26
0
        public static MaterialFlags ReadMaterialFlags(this BinaryReader reader)
        {
            byte[] ArrayOfBytes = new byte[4];
            reader.Read(ArrayOfBytes, 0, 4);

            BitArray      Flags         = new BitArray(ArrayOfBytes);
            MaterialFlags materialFlags = new MaterialFlags()
            {
                F_UNLIT    = Flags[0],
                F_UNFOGGED = Flags[1],
                F_UNCULLED = Flags[2],
                F_EXTLIGHT = Flags[3],
                F_SIDN     = Flags[4],
                F_WINDOW   = Flags[5],
                F_CLAMP_S  = Flags[6],
                F_CLAMP_T  = Flags[7],
                flag_0x100 = Flags[8],
            };

            return(materialFlags);
        }
コード例 #27
0
 public void FromPmxMaterial(PmxMaterial m, bool nonStr = false)
 {
     Diffuse    = m.Diffuse;
     Specular   = m.Specular;
     Power      = m.Power;
     Ambient    = m.Ambient;
     Flags      = m.Flags;
     EdgeColor  = m.EdgeColor;
     EdgeSize   = m.EdgeSize;
     SphereMode = m.SphereMode;
     FaceCount  = m.FaceCount;
     ExDraw     = m.ExDraw;
     if (!nonStr)
     {
         Name   = m.Name;
         NameE  = m.NameE;
         Tex    = m.Tex;
         Sphere = m.Sphere;
         Toon   = m.Toon;
         Memo   = m.Memo;
     }
     Attribute = m.Attribute;
     FromID(m);
 }
コード例 #28
0
        private static Material CreateMaterial(MaterialFlags flags)
        {
            var shaderName = ((flags & MaterialFlags.Lightmapped) == MaterialFlags.Lightmapped)
                ? "Custom/WorldGeometry"
                : "Custom/PropGeometry";

            if ((flags & MaterialFlags.NoCull) == MaterialFlags.NoCull)
            {
                shaderName += ".NoCull";
            }

            if ((flags & MaterialFlags.Translucent) == MaterialFlags.Translucent)
            {
                shaderName += ".Translucent";
            }
            else if ((flags & MaterialFlags.AlphaTest) == MaterialFlags.AlphaTest)
            {
                shaderName += ".AlphaTest";
            }

            var shader = Shader.Find(shaderName);

            if (shader == null)
            {
                throw new FileNotFoundException(string.Format("Unable to find shader '{0}'", shaderName));
            }

            var mat = new Material(shader);

            if ((flags & MaterialFlags.TreeSway) == MaterialFlags.TreeSway)
            {
                mat.EnableKeyword("TREE_SWAY");
            }

            return(mat);
        }
コード例 #29
0
ファイル: CMDL.cs プロジェクト: Ermelber/EveryFileExplorer
            public MTOB(EndianBinaryReader er)
            {
                Type = er.ReadUInt32();
                Signature = er.ReadString(Encoding.ASCII, 4);
                if (Signature != "MTOB") throw new SignatureNotCorrectException(Signature, "MTOB", er.BaseStream.Position);
                Revision = er.ReadUInt32();
                NameOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
                Unknown2 = er.ReadUInt32();
                Unknown3 = er.ReadUInt32();
                Flags = (MaterialFlags)er.ReadUInt32();
                TexCoordConfig = er.ReadUInt32();
                TranslucencyKind = er.ReadUInt32();
                MaterialColor = new MaterialColorCtr(er);
                Rasterization = new RasterizationCtr(er);
                FragmentOperation = new FragmentOperationCtr(er);
                NrActiveTextureCoordiators = er.ReadUInt32();
                TextureCoordiators = new TextureCoordinatorCtr[3];
                TextureCoordiators[0] = new TextureCoordinatorCtr(er);
                TextureCoordiators[1] = new TextureCoordinatorCtr(er);
                TextureCoordiators[2] = new TextureCoordinatorCtr(er);
                TexMapper0Offset = er.ReadUInt32();
                if (TexMapper0Offset != 0) TexMapper0Offset += (UInt32)er.BaseStream.Position - 4;
                TexMapper1Offset = er.ReadUInt32();
                if (TexMapper1Offset != 0) TexMapper1Offset += (UInt32)er.BaseStream.Position - 4;
                TexMapper2Offset = er.ReadUInt32();
                if (TexMapper2Offset != 0) TexMapper2Offset += (UInt32)er.BaseStream.Position - 4;
                ProcTexMapperOffset = er.ReadUInt32();
                if (ProcTexMapperOffset != 0) ProcTexMapperOffset += (UInt32)er.BaseStream.Position - 4;
                ShaderOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
                FragmentShaderOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
                ShaderProgramDescriptionIndex = er.ReadUInt32();
                NrShaderParameters = er.ReadUInt32();
                ShaderParametersOffsetArrayOffset = er.ReadUInt32();
                LightSetIndex = er.ReadUInt32();
                FogIndex = er.ReadUInt32();
                ShadingParameterHash = er.ReadUInt32();
                ShaderParametersHash = er.ReadUInt32();
                TextureCoordinatorsHash = er.ReadUInt32();
                TextureSamplersHash = er.ReadUInt32();
                TextureMappersHash = er.ReadUInt32();
                MaterialColorHash = er.ReadUInt32();
                RasterizationHash = er.ReadUInt32();
                FragmentLightingHash = er.ReadUInt32();
                FragmentLightingTableHash = er.ReadUInt32();
                FragmentLightingTableParametersHash = er.ReadUInt32();
                TextureCombinersHash = er.ReadUInt32();
                AlphaTestHash = er.ReadUInt32();
                FragmentOperationHash = er.ReadUInt32();
                MaterialId = er.ReadUInt32();

                long curpos = er.BaseStream.Position;
                er.BaseStream.Position = NameOffset;
                Name = er.ReadStringNT(Encoding.ASCII);
                if (TexMapper0Offset != 0)
                {
                    er.BaseStream.Position = TexMapper0Offset;
                    Tex0 = new TexInfo(er);
                }
                if (TexMapper1Offset != 0)
                {
                    er.BaseStream.Position = TexMapper1Offset;
                    Tex1 = new TexInfo(er);
                }
                if (TexMapper2Offset != 0)
                {
                    er.BaseStream.Position = TexMapper2Offset;
                    Tex2 = new TexInfo(er);
                }
                /*if (TexMapper3Offset != 0)
                {
                    er.BaseStream.Position = Tex3Offset;
                    Tex3 = new TexInfo(er);
                }*/
                //TODO: Procedural Texture Mapper
                er.BaseStream.Position = ShaderOffset;
                Shader = new SHDR(er);
                er.BaseStream.Position = FragmentShaderOffset;
                FragShader = new FragmentShader(er);
                er.BaseStream.Position = curpos;
            }
コード例 #30
0
ファイル: ModelMaterials.cs プロジェクト: Nihlus/libwarcraft
        public ModelMaterial(byte[] inData)
        {
            using (MemoryStream ms = new MemoryStream(inData))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    this.Flags = (MaterialFlags) br.ReadUInt32();
                    this.Shader = (ShaderTypes) br.ReadUInt32();
                    this.BlendMode = (BlendingMode) br.ReadUInt32();

                    this.FirstTextureOffset = br.ReadUInt32();
                    this.FirstColour = br.ReadRGBA();
                    this.FirstFlags  = (MaterialFlags)br.ReadUInt32();

                    this.SecondTextureOffset = br.ReadUInt32();
                    this.SecondColour = br.ReadRGBA();

                    this.GroundType = new UInt32ForeignKey("TerrainType", "ID", br.ReadUInt32());
                    this.ThirdTextureOffset = br.ReadUInt32();
                    this.BaseDiffuseColour = br.ReadRGBA();
                    this.ThirdFlags = (MaterialFlags)br.ReadUInt32();

                    this.RuntimeData1 = br.ReadUInt32();
                    this.RuntimeData2 = br.ReadUInt32();
                    this.RuntimeData3 = br.ReadUInt32();
                    this.RuntimeData4 = br.ReadUInt32();
                }
            }
        }
コード例 #31
0
 internal static extern void SetFlags(IntPtr ptr, MaterialFlags flags);
コード例 #32
0
ファイル: idMaterial.cs プロジェクト: iainmckay/idtech4.net
		/// <summary>
		/// Test for existance of specific material flag(s).
		/// </summary>
		/// <param name="flag"></param>
		/// <returns></returns>
		public bool TestMaterialFlag(MaterialFlags flag)
		{
			return ((_materialFlags & flag) != 0);
		}
コード例 #33
0
ファイル: idMaterial.cs プロジェクト: iainmckay/idtech4.net
		private void Clear()
		{
			_description = "<none>";
			_renderBump = string.Empty;

			_contentFlags = ContentFlags.Solid;
			_surfaceFlags = SurfaceFlags.None;
			_materialFlags = 0;

			_sort = (float) MaterialSort.Bad;
			_coverage = MaterialCoverage.Bad;
			_cullType = CullType.Front;

			_deformType = DeformType.None;
			_deformRegisters = new int[4];

			_ops = null;
			_expressionRegisters = null;
			_constantRegisters = null;
			_stages = new MaterialStage[] { };

			_stageCount = 0;
			_ambientStageCount = 0;
			_registerCount = 0;
			
			_lightFalloffImage = null;
			_entityGui = 0;
			_shouldCreateBackSides = false;
			_editorImageName = null;

			_fogLight = false;
			_blendLight = false;
			_ambientLight = false;
			_noFog = false;
			_hasSubview = false;
			_allowOverlays = true;
			_unsmoothedTangents = false;

			_userInterface = null;
			_referenceCount = 0;
			
			/*editorAlpha = 1.0;*/
			_spectrum = 0;

			_polygonOffset = 0;
			_suppressInSubview = false;
			_portalSky = false;

			_decalInfo.StayTime = 10000;
			_decalInfo.FadeTime = 4000;
			_decalInfo.Start = new float[] { 1, 1, 1, 1 };
			_decalInfo.End = new float[] { 0, 0, 0, 0 };
		}
コード例 #34
0
        private static Shader GetShaderNoCache(MaterialFlags flags)
        {
            var noBackCull = (flags & MaterialFlags.NoBackCull) == MaterialFlags.NoBackCull;
            var alpha = (flags & MaterialFlags.Alpha) == MaterialFlags.Alpha;
            var vehicle = (flags & MaterialFlags.Vehicle) == MaterialFlags.Vehicle;

            if (vehicle && alpha) {
                return Shader.Find("SanAndreasUnity/VehicleTransparent");
            }

            if (vehicle) {
                return Shader.Find("SanAndreasUnity/Vehicle");
            }

            if (noBackCull && alpha) {
                return Shader.Find("SanAndreasUnity/TransparentNoBackCull");
            }

            if (noBackCull) {
                return Shader.Find("SanAndreasUnity/NoBackCull");
            }

            if (alpha) {
                return Shader.Find("SanAndreasUnity/Transparent");
            }

            return Shader.Find("SanAndreasUnity/Default");
        }
コード例 #35
0
    private void InitizalizeTexture(MaterialType type, MaterialFlags flags)
    {
        if (!_cachedMaterials.ContainsKey(type))
        {
            _cachedMaterials[type] = new Dictionary<MaterialFlags, Material>();
        }
        if (!_cachedMaterials[type].ContainsKey(flags))
        {
            switch (type)
            {
                case MaterialType.Opaque:
                    _cachedMaterials[type][flags] = new Material(baseStandardMaterial);
                    break;
                case MaterialType.Stencil:
                    _cachedMaterials[type][flags] = new Material(baseStandardMaterialCutout);
                    break;
                case MaterialType.Transparent:
                    _cachedMaterials[type][flags] = new Material(baseStandardMaterialTransparent);
                    break;
                case MaterialType.SplatMap:
                    _cachedMaterials[type][flags] = new Material(baseSplatMaterial);
                    break;
                default:
                    break;
            }
            if ((flags & MaterialFlags.Contaminants) == MaterialFlags.Contaminants)
                _cachedMaterials[type][flags].EnableKeyword("CONTAMINANTS");
            else
                _cachedMaterials[type][flags].DisableKeyword("CONTAMINANTS");

            if ((flags & MaterialFlags.Grass) == MaterialFlags.Grass)
                _cachedMaterials[type][flags].EnableKeyword("GRASS");
            else
                _cachedMaterials[type][flags].DisableKeyword("GRASS");

            foreach (var item in vectorProperties)
            {
                _cachedMaterials[type][flags].SetVector(item.Key, item.Value);
            }
            foreach (var item in textureProperties)
            {
                _cachedMaterials[type][flags].SetTexture(item.Key, item.Value);
            }
        }
    }
コード例 #36
0
 public Material GetMaterial(MaterialType type, MaterialFlags flags)
 {
     return _cachedMaterials[type][flags];
 }
コード例 #37
0
 public UnityEngine.Material[] GetMaterials(MaterialFlags flags)
 {
     return GetMaterials(flags, x => {});
 }
コード例 #38
0
        /// <summary>
        /// Reads RawData into structured data.
        /// </summary>
        public void StructureData(CFGData cfg)
        {
            this.Name = cfg.Name;

            this.Strength     = cfg.Attributes[0];
            this.Intelligence = cfg.Attributes[1];
            this.Willpower    = cfg.Attributes[2];
            this.Agility      = cfg.Attributes[3];
            this.Endurance    = cfg.Attributes[4];
            this.Personality  = cfg.Attributes[5];
            this.Speed        = cfg.Attributes[6];
            this.Luck         = cfg.Attributes[7];

            this.PrimarySkill1 = (Skills)cfg.PrimarySkill1;
            this.PrimarySkill2 = (Skills)cfg.PrimarySkill2;
            this.PrimarySkill3 = (Skills)cfg.PrimarySkill3;
            this.MajorSkill1   = (Skills)cfg.MajorSkill1;
            this.MajorSkill2   = (Skills)cfg.MajorSkill2;
            this.MajorSkill3   = (Skills)cfg.MajorSkill3;
            this.MinorSkill1   = (Skills)cfg.MinorSkill1;
            this.MinorSkill2   = (Skills)cfg.MinorSkill2;
            this.MinorSkill3   = (Skills)cfg.MinorSkill3;
            this.MinorSkill4   = (Skills)cfg.MinorSkill4;
            this.MinorSkill5   = (Skills)cfg.MinorSkill5;
            this.MinorSkill6   = (Skills)cfg.MinorSkill6;

            this.HitPointsPerLevel = cfg.HitPointsPerLevel;

            float value = (cfg.AdvancementMultiplier >> 16) + ((cfg.AdvancementMultiplier & 0xffff)) / 65536f;

            try
            {
                this.AdvancementMultiplier = float.Parse(string.Format("{0:0.00}", value), NumberStyles.Float, CultureInfo.InvariantCulture);
            }
            catch
            {
                this.AdvancementMultiplier = value;
            }

            this.Paralysis = GetTolerance(cfg, EffectFlags.Paralysis);
            this.Magic     = GetTolerance(cfg, EffectFlags.Magic);
            this.Poison    = GetTolerance(cfg, EffectFlags.Poison);
            this.Fire      = GetTolerance(cfg, EffectFlags.Fire);
            this.Frost     = GetTolerance(cfg, EffectFlags.Frost);
            this.Shock     = GetTolerance(cfg, EffectFlags.Shock);
            this.Disease   = GetTolerance(cfg, EffectFlags.Disease);

            this.ForbiddenMaterials     = (MaterialFlags)cfg.ForbiddenMaterialsFlags;
            this.ForbiddenShields       = (ShieldFlags)((cfg.WeaponArmorShieldsBitfield >> 9) & 0x0f);
            this.ForbiddenArmors        = (ArmorFlags)((cfg.WeaponArmorShieldsBitfield >> 6) & 0x07);
            this.ForbiddenProficiencies = (ProficiencyFlags)(cfg.WeaponArmorShieldsBitfield & 0x3f);
            this.ExpertProficiencies    = (ProficiencyFlags)((cfg.WeaponArmorShieldsBitfield >> 16) & 0x3f);

            this.ShortBlades    = GetProficiency(ProficiencyFlags.ShortBlades);
            this.LongBlades     = GetProficiency(ProficiencyFlags.LongBlades);
            this.HandToHand     = GetProficiency(ProficiencyFlags.HandToHand);
            this.Axes           = GetProficiency(ProficiencyFlags.Axes);
            this.BluntWeapons   = GetProficiency(ProficiencyFlags.BluntWeapons);
            this.MissileWeapons = GetProficiency(ProficiencyFlags.MissileWeapons);

            this.SpellPointMultiplier      = GetSpellPointMultiplier(cfg);
            this.SpellPointMultiplierValue = GetSpellPointMultiplierValue(this.SpellPointMultiplier);

            this.DarknessPoweredMagery = (DarknessMageryFlags)((cfg.AbilityFlagsAndSpellPointsBitfield & 0x300) >> 8);
            this.LightPoweredMagery    = (LightMageryFlags)((cfg.AbilityFlagsAndSpellPointsBitfield & 0x00C0) >> 6);

            this.SpellAbsorption = (SpellAbsorptionFlags)cfg.SpellAbsorptionFlags;

            this.NoRegenSpellPoints = HasSpecialAbility(cfg, SpecialAbilityFlags.NoRegenSpellPoints);

            this.AcuteHearing   = HasSpecialAbility(cfg, SpecialAbilityFlags.AcuteHearing);
            this.Athleticism    = HasSpecialAbility(cfg, SpecialAbilityFlags.Athleticism);
            this.AdrenalineRush = HasSpecialAbility(cfg, SpecialAbilityFlags.AdrenalineRush);

            this.Regeneration = (RegenerationFlags)cfg.Regeneration;
            this.RapidHealing = (RapidHealingFlags)cfg.RapidHealing;

            this.DamageFromSunlight   = HasSpecialAbility(cfg, SpecialAbilityFlags.SunDamage);
            this.DamageFromHolyPlaces = HasSpecialAbility(cfg, SpecialAbilityFlags.HolyDamage);

            this.UndeadAttackModifier   = GetAttackModifier(cfg, EnemyGroups.Undead);
            this.DaedraAttackModifier   = GetAttackModifier(cfg, EnemyGroups.Daedra);
            this.HumanoidAttackModifier = GetAttackModifier(cfg, EnemyGroups.Humanoid);
            this.AnimalsAttackModifier  = GetAttackModifier(cfg, EnemyGroups.Animals);
        }
コード例 #39
0
        /// <summary>
        /// Reads RawData into structured data.
        /// </summary>
        public void StructureData(CFGData cfg)
        {
            this.Name = cfg.Name;

            this.Strength = cfg.Attributes[0];
            this.Intelligence = cfg.Attributes[1];
            this.Willpower = cfg.Attributes[2];
            this.Agility = cfg.Attributes[3];
            this.Endurance = cfg.Attributes[4];
            this.Personality = cfg.Attributes[5];
            this.Speed = cfg.Attributes[6];
            this.Luck = cfg.Attributes[7];

            this.PrimarySkill1 = (Skills)cfg.PrimarySkill1;
            this.PrimarySkill2 = (Skills)cfg.PrimarySkill2;
            this.PrimarySkill3 = (Skills)cfg.PrimarySkill3;
            this.MajorSkill1 = (Skills)cfg.MajorSkill1;
            this.MajorSkill2 = (Skills)cfg.MajorSkill2;
            this.MajorSkill3 = (Skills)cfg.MajorSkill3;
            this.MinorSkill1 = (Skills)cfg.MinorSkill1;
            this.MinorSkill2 = (Skills)cfg.MinorSkill2;
            this.MinorSkill3 = (Skills)cfg.MinorSkill3;
            this.MinorSkill4 = (Skills)cfg.MinorSkill4;
            this.MinorSkill5 = (Skills)cfg.MinorSkill5;
            this.MinorSkill6 = (Skills)cfg.MinorSkill6;

            this.HitPointsPerLevelOrMonsterLevel = cfg.HitPointsPerLevelOrMonsterLevel;

            float value = (cfg.AdvancementMultiplier >> 16) + ((cfg.AdvancementMultiplier & 0xffff)) / 65536f;
            try
            {
                this.AdvancementMultiplier = float.Parse(string.Format("{0:0.00}", value), NumberStyles.Float, CultureInfo.InvariantCulture);
            }
            catch
            {
                this.AdvancementMultiplier = value;
            }

            this.Paralysis = GetTolerance(cfg, EffectFlags.Paralysis);
            this.Magic = GetTolerance(cfg, EffectFlags.Magic);
            this.Poison = GetTolerance(cfg, EffectFlags.Poison);
            this.Fire = GetTolerance(cfg, EffectFlags.Fire);
            this.Frost = GetTolerance(cfg, EffectFlags.Frost);
            this.Shock = GetTolerance(cfg, EffectFlags.Shock);
            this.Disease = GetTolerance(cfg, EffectFlags.Disease);

            this.ForbiddenMaterials = (MaterialFlags)cfg.ForbiddenMaterialsFlags;
            this.ForbiddenShields = (ShieldFlags)((cfg.WeaponArmorShieldsBitfield >> 9) & 0x0f);
            this.ForbiddenArmors = (ArmorFlags)((cfg.WeaponArmorShieldsBitfield >> 6) & 0x07);
            this.ForbiddenProficiencies = (ProficiencyFlags)(cfg.WeaponArmorShieldsBitfield & 0x3f);
            this.ExpertProficiencies = (ProficiencyFlags)((cfg.WeaponArmorShieldsBitfield >> 16) & 0x3f);

            this.ShortBlades = GetProficiency(ProficiencyFlags.ShortBlades);
            this.LongBlades = GetProficiency(ProficiencyFlags.LongBlades);
            this.HandToHand = GetProficiency(ProficiencyFlags.HandToHand);
            this.Axes = GetProficiency(ProficiencyFlags.Axes);
            this.BluntWeapons = GetProficiency(ProficiencyFlags.BluntWeapons);
            this.MissileWeapons = GetProficiency(ProficiencyFlags.MissileWeapons);

            this.SpellPointMultiplier = GetSpellPointMultiplier(cfg);
            this.SpellPointMultiplierValue = GetSpellPointMultiplierValue(this.SpellPointMultiplier);

            this.DarknessPoweredMagery = (DarknessMageryFlags)((cfg.AbilityFlagsAndSpellPointsBitfield & 0x300) >> 8);
            this.LightPoweredMagery = (LightMageryFlags)((cfg.AbilityFlagsAndSpellPointsBitfield & 0x00C0) >> 6);

            this.SpellAbsorption = (SpellAbsorptionFlags)cfg.SpellAbsorptionFlags;

            this.NoRegenSpellPoints = HasSpecialAbility(cfg, SpecialAbilityFlags.NoRegenSpellPoints);

            this.AcuteHearing = HasSpecialAbility(cfg, SpecialAbilityFlags.AcuteHearing);
            this.Athleticism = HasSpecialAbility(cfg, SpecialAbilityFlags.Athleticism);
            this.AdrenalineRush = HasSpecialAbility(cfg, SpecialAbilityFlags.AdrenalineRush);

            this.Regeneration = (RegenerationFlags)cfg.Regeneration;
            this.RapidHealing = (RapidHealingFlags)cfg.RapidHealing;

            this.DamageFromSunlight = HasSpecialAbility(cfg, SpecialAbilityFlags.SunDamage);
            this.DamageFromHolyPlaces = HasSpecialAbility(cfg, SpecialAbilityFlags.HolyDamage);

            this.UndeadAttackModifier = GetAttackModifier(cfg, EnemyGroups.Undead);
            this.DaedraAttackModifier = GetAttackModifier(cfg, EnemyGroups.Daedra);
            this.HumanoidAttackModifier = GetAttackModifier(cfg, EnemyGroups.Humanoid);
            this.AnimalsAttackModifier = GetAttackModifier(cfg, EnemyGroups.Animals);
        }
コード例 #40
0
 /// <summary>
 /// Determines if material type is forbidden.
 /// </summary>
 /// <param name="flags">MaterialFlags to test.</param>
 /// <returns>True if material forbidden.</returns>
 public bool IsMaterialForbidden(MaterialFlags flags)
 {
     return ((ForbiddenMaterials & flags) == flags) ? true : false;
 }
コード例 #41
0
 static extern void btSoftBody_Material_setFlags(IntPtr obj, MaterialFlags value);
コード例 #42
0
        public UnityEngine.Material[] GetMaterials(MaterialFlags flags,
            Action<UnityEngine.Material> setupMaterial)
        {
            if (_materials.ContainsKey(flags)) {
                return _materials[flags];
            }

            var mats = _geom.Materials.Select(x => {
                var mat = Convert(x, _textureDictionaries, flags);
                setupMaterial(mat);
                return mat;
            }).ToArray();

            mats = _geom.MaterialSplits.Select(x => mats[x.MaterialIndex]).ToArray();

            _materials.Add(flags, mats);

            return mats;
        }
コード例 #43
0
            public FrameContainer AttachFrames(Transform destParent, MaterialFlags flags)
            {
                var transforms = Frames.ToDictionary(x => x, x => {
                    var trans = new GameObject(x.Name).transform;
                    trans.localPosition = x.Position;
                    trans.localRotation = x.Rotation;
                    return trans;
                });

                var container = destParent.gameObject.AddComponent<FrameContainer>();

                foreach (var frame in Frames) {
                    if (frame.ParentIndex != -1) {
                        transforms[frame].SetParent(transforms[Frames[frame.ParentIndex]], false);
                    } else {
                        transforms[frame].SetParent(destParent, false);
                    }

                    if (frame.GeometryIndex != -1) {
                        var gobj = transforms[frame].gameObject;
                        var geometry = Geometry[frame.GeometryIndex];

                        HierarchyAnimation hAnim = null;
                        var parent = frame;
                        while ((hAnim = parent.Source.HAnim) == null || hAnim.NodeCount == 0) {
                            if (parent.ParentIndex == -1) {
                                hAnim = null;
                                break;
                            }
                            parent = Frames[parent.ParentIndex];
                        }

                        Renderer renderer;
                        if (hAnim != null) {
                            var smr = gobj.AddComponent<SkinnedMeshRenderer>();

                            var bones = Convert(hAnim, transforms, Frames);

                            smr.rootBone = bones[0];
                            smr.bones = bones;

                            smr.sharedMesh = geometry.Mesh;

                            if (smr.sharedMesh != null) {
                                smr.sharedMesh.bindposes = geometry.SkinToBoneMatrices
                                    .Select(x => x.transpose)
                                    .ToArray();
                            }

                            renderer = smr;
                        } else {
                            var mf = gobj.AddComponent<MeshFilter>();
                            mf.sharedMesh = geometry.Mesh;

                            renderer = gobj.AddComponent<MeshRenderer>();
                        }

                        renderer.sharedMaterials = geometry.GetMaterials(flags);

                        // filter these out for now
                        if (frame.Name.EndsWith("_vlo") ||
                            frame.Name.EndsWith("_dam")) {
                            gobj.SetActive(false);
                        }
                    }
                }

                container.Initialize(Frames, transforms);

                return container;
            }
コード例 #44
0
        public SceneObject BuildSquareMesh(Func <int, int, bool> shouldNotRenderTile, MaterialFlags materialProperties, RectangleF bounds, string description = null)
        {
            var trianglesPerRow = MaxTileRows;
            var trianglesPerCol = MaxTileColumns;
            var triangles       = new List <IndexedTriangleWithNormal>(trianglesPerRow * trianglesPerCol * 2);

            for (var row = 0; row < trianglesPerRow; row++)
            {
                for (var col = 0; col < trianglesPerCol; col++)
                {
                    if (shouldNotRenderTile(col, row))
                    {
                        continue;
                    }

                    var topLeft     = GetIndexAt(row, col);
                    var topRight    = GetIndexAt(row, col + 1);
                    var bottomLeft  = GetIndexAt(row + 1, col);
                    var bottomRight = GetIndexAt(row + 1, col + 1);

                    if (IsOutOfBounds(topLeft, bounds) &&
                        IsOutOfBounds(topRight, bounds) &&
                        IsOutOfBounds(bottomLeft, bounds) &&
                        IsOutOfBounds(bottomRight, bounds))
                    {
                        continue;
                    }

                    triangles.Add(MakeTriangle(bottomLeft, topRight, topLeft));
                    triangles.Add(MakeTriangle(topRight, bottomLeft, bottomRight));
                }
            }

            if (triangles.Count == 0)
            {
                return(null);
            }

            var vertices = _vertices.ToArray();

            return(new SceneObject
            {
                Bounds = BoundingBox.FromPoints(vertices),
                MaterialProperties = materialProperties,
                Geometry = new TriangleMesh
                {
                    Vertices = vertices,
                    Triangles = triangles.ToArray()
                },
                Description = description
            });
        }
コード例 #45
0
        private static UnityEngine.Material Convert(RenderWareStream.Material src, TextureDictionary[] txds, MaterialFlags flags)
        {
            LoadedTexture diffuse;
            LoadedTexture mask = null;

            var overrideAlpha = (flags & MaterialFlags.OverrideAlpha) == MaterialFlags.OverrideAlpha;
            var vehicle = (flags & MaterialFlags.Vehicle) == MaterialFlags.Vehicle;

            if (!overrideAlpha && src.Colour.A != 255) {
                flags |= MaterialFlags.Alpha;
            }

            if (src.TextureCount > 0) {
                var tex = src.Textures[0];
                diffuse = txds.GetDiffuse(tex.TextureName);

                if (src.TextureCount > 1) {
                    Debug.LogFormat("Something has {0} textures!", src.TextureCount);
                }

                if (diffuse == null) {
                    Debug.LogWarningFormat("Unable to find texture {0}", tex.TextureName);
                }

                if (!string.IsNullOrEmpty(tex.MaskName)) {
                    mask = txds.GetAlpha(tex.MaskName) ?? diffuse;
                } else if (vehicle) {
                    mask = diffuse;
                }

                if (!overrideAlpha && mask != null && mask.HasAlpha) {
                    flags |= MaterialFlags.Alpha;
                }
            } else {
                diffuse = WhiteTex;
            }

            var shader = GetShader(flags);
            var mat = new UnityEngine.Material(shader);

            var clr = Types.Convert(src.Colour);

            if (vehicle) {
                var found = false;
                for (var i = 1; i < _sKeyColors.Length; ++i) {
                    var key = _sKeyColors[i];
                    if (key.r != clr.r || key.g != clr.g || key.b != clr.b) continue;
                    mat.SetInt(CarColorIndexId, i);
                    found = true;
                    break;
                }

                if (found) {
                    mat.color = Color.white;
                } else {
                    mat.color = clr;
                }
            } else {
                mat.color = clr;
            }

            if (diffuse != null) mat.SetTexture(MainTexId, diffuse.Texture);
            if (mask != null) mat.SetTexture(MaskTexId, mask.Texture);

            mat.SetFloat(MetallicId, src.Specular);
            mat.SetFloat(SmoothnessId, src.Smoothness);

            return mat;
        }
コード例 #46
0
 /// <summary>
 /// Determines if material type is forbidden.
 /// </summary>
 /// <param name="flags">MaterialFlags to test.</param>
 /// <returns>True if material forbidden.</returns>
 public bool IsMaterialForbidden(MaterialFlags flags)
 {
     return(((ForbiddenMaterials & flags) == flags) ? true : false);
 }
コード例 #47
0
        private static Shader GetShader(MaterialFlags flags)
        {
            if (_sShaders.ContainsKey(flags)) return _sShaders[flags];

            var shader = GetShaderNoCache(flags);
            _sShaders.Add(flags, shader);
            return shader;
        }