示例#1
0
 private void ApplyNiAVObject(NiAVObject niAVObject, GameObject obj)
 {
     obj.transform.position   = NifUtils.NifPointToUnityPoint(niAVObject.Translation);
     obj.transform.rotation   = NifUtils.NifRotationMatrixToUnityQuaternion(niAVObject.Rotation);
     obj.transform.localScale = niAVObject.Scale * Vector3.one;
 }
示例#2
0
        private MaterialProps NiAVObjectPropertiesToMaterialProperties(NiAVObject obj)
        {
            // Find relevant properties.
            NiTexturingProperty texturingProperty = null;
            //NiMaterialProperty materialProperty = null;
            NiAlphaProperty alphaProperty = null;

            foreach (var propRef in obj.Properties)
            {
                var prop = _file.Blocks[propRef.Value];
                if (prop is NiTexturingProperty)
                {
                    texturingProperty = (NiTexturingProperty)prop;
                }
                //else if (prop is NiMaterialProperty) materialProperty = (NiMaterialProperty)prop;
                else if (prop is NiAlphaProperty)
                {
                    alphaProperty = (NiAlphaProperty)prop;
                }
            }

            // Create the material properties.
            var mp = new MaterialProps();

            if (alphaProperty != null)
            {
                #region AlphaProperty Cheat Sheet

                /*
                 * 14 bits used:
                 *
                 * 1 bit for alpha blend bool
                 * 4 bits for src blend mode
                 * 4 bits for dest blend mode
                 * 1 bit for alpha test bool
                 * 3 bits for alpha test mode
                 * 1 bit for zwrite bool ( opposite value )
                 *
                 * Bit 0 : alpha blending enable
                 * Bits 1-4 : source blend mode
                 * Bits 5-8 : destination blend mode
                 * Bit 9 : alpha test enable
                 * Bit 10-12 : alpha test mode
                 * Bit 13 : no sorter flag ( disables triangle sorting ) ( Unity ZWrite )
                 *
                 * blend modes (glBlendFunc):
                 * 0000 GL_ONE
                 * 0001 GL_ZERO
                 * 0010 GL_SRC_COLOR
                 * 0011 GL_ONE_MINUS_SRC_COLOR
                 * 0100 GL_DST_COLOR
                 * 0101 GL_ONE_MINUS_DST_COLOR
                 * 0110 GL_SRC_ALPHA
                 * 0111 GL_ONE_MINUS_SRC_ALPHA
                 * 1000 GL_DST_ALPHA
                 * 1001 GL_ONE_MINUS_DST_ALPHA
                 * 1010 GL_SRC_ALPHA_SATURATE
                 *
                 * test modes (glAlphaFunc):
                 * 000 GL_ALWAYS
                 * 001 GL_LESS
                 * 010 GL_EQUAL
                 * 011 GL_LEQUAL
                 * 100 GL_GREATER
                 * 101 GL_NOTEQUAL
                 * 110 GL_GEQUAL
                 * 111 GL_NEVER
                 */
                #endregion
                var flags    = alphaProperty.Flags;
                var oldflags = flags;
                var srcbm    = (byte)(BitConverter.GetBytes(flags >> 1)[0] & 15);
                var dstbm    = (byte)(BitConverter.GetBytes(flags >> 5)[0] & 15);
                mp.ZWrite = BitConverter.GetBytes(flags >> 15)[0] == 1; // smush
                if (Utils.ContainsBitFlags(flags, 0x01))                // if flags contain the alpha blend flag at bit 0 in byte 0
                {
                    mp.AlphaBlended = true;
                    mp.SrcBlendMode = FigureBlendMode(srcbm);
                    mp.DstBlendMode = FigureBlendMode(dstbm);
                }
                else if (Utils.ContainsBitFlags(flags, 0x100)) // if flags contain the alpha test flag
                {
                    mp.AlphaTest   = true;
                    mp.AlphaCutoff = (float)alphaProperty.Threshold / 255;
                }
            }
            else
            {
                mp.AlphaBlended = false;
                mp.AlphaTest    = false;
            }
            // Apply textures.
            if (texturingProperty != null)
            {
                mp.Textures = ConfigureTextureProperties(texturingProperty);
            }
            return(mp);
        }
示例#3
0
 void ApplyNiAVObject(NiAVObject niAVObject, GameObject obj)
 {
     obj.transform.position   = niAVObject.Translation.ToUnityVector(ConvertUtils.MeterInUnits);
     obj.transform.rotation   = niAVObject.Rotation.ToUnityQuaternionAsRotationMatrix();
     obj.transform.localScale = niAVObject.Scale * Vector3.one;
 }