Ejemplo n.º 1
0
    private void ReadTexture(ReadChunk chunk)
    {
        Texture3D texture      = null;
        bool      optimized    = chunk.Bytes.ReadBoolean();
        int       typeMode     = chunk.Bytes.ReadSByte();
        int       formatMode   = chunk.Bytes.ReadSByte();
        int       texture_type = chunk.Bytes.ReadSByte();

        switch (texture_type)
        {
        case Texture_EMBED:
            int    length = (int)chunk.Bytes.ReadUInt32();
            byte[] data   = chunk.Bytes.ReadBytes(length);
            texture = new Texture3D(data, optimized, formatMode, typeMode);
            //chunk.Bytes.BaseStream.Seek(chunk.Bytes.BaseStream.Position + length, SeekOrigin.Begin);
            break;

        default:
            return;
        }
        texture.Name       = ReadUtil.ReadUTF(chunk.Bytes);
        texture.FilterMode = chunk.Bytes.ReadSByte();
        texture.WrapMode   = chunk.Bytes.ReadSByte();
        texture.MipMode    = chunk.Bytes.ReadSByte();

        resource[chunk.Id] = texture;
    }
Ejemplo n.º 2
0
    private void ReadBuffer(ReadChunk chunk)
    {
        List <float> verticesVector = new List <float>();

        while (chunk.BytesAvailable() > 0)
        {
            verticesVector.Add(chunk.Bytes.ReadSingle());
        }
        resource[chunk.Id] = verticesVector;
    }
Ejemplo n.º 3
0
    private void ReadIndices(ReadChunk chunk)
    {
        List <uint> indicesVector = new List <uint>();

        while (chunk.BytesAvailable() > 0)
        {
            indicesVector.Add(chunk.Bytes.ReadUInt16());
        }
        resource[chunk.Id] = indicesVector;
    }
Ejemplo n.º 4
0
    private void ReadObject(ReadChunk chunk)
    {
        ReadChunk    data;
        BinaryReader input = chunk.Bytes;
        string       type  = ReadUtil.ReadUTF(chunk.Bytes);
        string       name  = ReadUtil.ReadUTF(chunk.Bytes);

        //名字不能包含\
        name = System.Text.RegularExpressions.Regex.Replace(name, @"/+|\*+|\\+", string.Empty);
        if (!uniqueName.ContainsKey(name))
        {
            uniqueName.Add(name, 1);
        }
        else
        {
            uniqueName[name]++;
            if (uniqueName[name] > 1)
            {
                name = name + uniqueName[name].ToString();
            }
        }


        UnityEngine.Matrix4x4 matrix = ReadMatrix3D(chunk.Bytes, _compressionLevel);
        int   layer      = chunk.Bytes.ReadInt16();
        int   parent     = chunk.Bytes.ReadInt16();
        float frameSpeed = chunk.Bytes.ReadSingle();

        if (parent != -1)
        {
            matrix = cascadeTransform[parent] * matrix;
        }
        cascadeTransform[chunk.Id] = matrix;

        while (chunk.BytesAvailable() > 0)
        {
            data = new ReadChunk(input);
            switch (data.Name)
            {
            case "particleSysterm":
                ReadParticleSystem(name, layer, matrix, data, parent, chunk.Id);
                break;

            case "extends":
                ReadExtends(data);
                break;

            default:
                System.Diagnostics.Debug.WriteLine("未识别属性{0}", data.Name);
                break;
            }
            data.Next();
        }
    }
Ejemplo n.º 5
0
    private void ReadPSSurface(ReadChunk chunk)
    {
        Surface3D surf  = new Surface3D();
        int       bufId = chunk.Bytes.ReadInt16();
        int       idx   = chunk.Bytes.ReadInt16();

        surf.VertexVector = resource[bufId] as List <float>;
        surf.IndexVector  = resource[idx] as List <uint>;

        surf.NumTriangles = chunk.Bytes.ReadInt32();
        surf.FirstIndex   = chunk.Bytes.ReadInt32();

        surf.SizePerVertex = chunk.Bytes.ReadSByte();

        for (int i = 0; i < surf.Offset.Count; i++)
        {
            surf.Offset[i] = chunk.Bytes.ReadSByte();
            if (surf.Offset[i] != -1)
            {
                switch (surf.Offset[i])
                {
                case Surface3D.POSITION:
                case Surface3D.NORMAL:
                case Surface3D.TANGENT:
                case Surface3D.BITANGENT:
                case Surface3D.COLOR0:
                case Surface3D.COLOR1:
                case Surface3D.COLOR2:
                    surf.Format[i] = "float3";
                    break;

                case Surface3D.UV0:
                case Surface3D.UV1:
                case Surface3D.SKIN_WEIGHTS:
                case Surface3D.SKIN_INDICES:
                    surf.Format[i] = "float2";
                    break;

                default:
                    break;
                }
            }
        }

        resource[chunk.Id] = surf;
    }
Ejemplo n.º 6
0
    private void ReadParticleSystem(string name, int layer, Matrix4x4 matrix, ReadChunk data, int parent, int chunkId)
    {
        int            texId      = data.Bytes.ReadUInt16();
        uint           surfId     = data.Bytes.ReadUInt16();
        string         jsonStr    = ReadUtil.ReadUTF(data.Bytes);
        JObject        jsonObject = JObject.Parse(jsonStr);
        ParticleSystem ps         = new ParticleSystem();

        ps.ChunkId = chunkId;
        ps.Name    = name;
        ps.Layer   = layer;
        ps.Matrix  = ScaleTransform(matrix, Uf3dLoader.vertexScale);
        ps.TexId   = texId;
        ps.SurfId  = surfId;
        ps.Parent  = parent;
        ps.deserialize(jsonObject);
        particleSystemList.Add(ps);
        //System.Diagnostics.Debug.WriteLine("粒子名字:{0}", name);
    }
Ejemplo n.º 7
0
        /// <summary>
        /// Configuration for the tcp connection.
        /// </summary>
        /// <param name="connectionRetry">Retry details for (re)establishing the connection.</param>
        /// <param name="versionSupport">Support for different protocol versions for Kakfa requests and responses.</param>
        /// <param name="requestTimeout">The maximum time to wait for requests.</param>
        /// <param name="encoders">Custom Encoding support for different protocol types</param>
        /// <param name="sslConfiguration">Configuration for SSL encrypted communication</param>
        /// <param name="onDisconnected">Triggered when the tcp socket is disconnected.</param>
        /// <param name="onConnecting">Triggered when the tcp socket is connecting.</param>
        /// <param name="onConnected">Triggered after the tcp socket is successfully connected.</param>
        /// <param name="onWriteEnqueued">Triggered after enqueing async write task for writing to the tcp stream.</param>
        /// <param name="onWriting">Triggered when writing to the tcp stream.</param>
        /// <param name="onWritten">Triggered after having successfully written to the tcp stream.</param>
        /// <param name="onWriteFailed">Triggered after failing to write to the tcp stream.</param>
        /// <param name="onReading">Triggered when starting to read a message's bytes from the tcp stream.</param>
        /// <param name="onReadingChunk">Triggered when reading a chunk of bytes from the tcp stream.</param>
        /// <param name="onReadChunk">Triggered after successfully reading a chunk of bytes from the tcp stream.</param>
        /// <param name="onRead">Triggered after having successfully read a message's bytes from the tcp stream.</param>
        /// <param name="onReadFailed">Triggered after failing to read from the tcp stream.</param>
        /// <param name="onProduceRequestMessages">Triggered when encoding ProduceRequest messages.</param>
        public ConnectionConfiguration(
            IRetry connectionRetry         = null,
            IVersionSupport versionSupport = null,
            TimeSpan?requestTimeout        = null,
            IEnumerable <IProtocolTypeEncoder> encoders = null,
            ISslConfiguration sslConfiguration          = null,
            ConnectError onDisconnected = null,
            Connecting onConnecting     = null,
            Connecting onConnected      = null,
            Writing onWriteEnqueued     = null,
            Writing onWriting           = null,
            WriteSuccess onWritten      = null,
            WriteError onWriteFailed    = null,
            Reading onReading           = null,
            ReadingChunk onReadingChunk = null,
            ReadChunk onReadChunk       = null,
            Read onRead            = null,
            ReadError onReadFailed = null,
            ProduceRequestMessages onProduceRequestMessages = null
            )
        {
            ConnectionRetry = connectionRetry ?? Defaults.ConnectionRetry();
            VersionSupport  = versionSupport ?? Connections.VersionSupport.Kafka8;
            RequestTimeout  = requestTimeout ?? TimeSpan.FromSeconds(Defaults.RequestTimeoutSeconds);
            Encoders        = encoders != null
                ? encoders.ToImmutableDictionary(e => e.Type)
                : ImmutableDictionary <string, IProtocolTypeEncoder> .Empty;

            SslConfiguration         = sslConfiguration;
            OnDisconnected           = onDisconnected;
            OnConnecting             = onConnecting;
            OnConnected              = onConnected;
            OnWriteEnqueued          = onWriteEnqueued;
            OnWriting                = onWriting;
            OnWritten                = onWritten;
            OnWriteFailed            = onWriteFailed;
            OnReading                = onReading;
            OnReadingChunk           = onReadingChunk;
            OnReadChunk              = onReadChunk;
            OnRead                   = onRead;
            OnReadFailed             = onReadFailed;
            OnProduceRequestMessages = onProduceRequestMessages;
        }
Ejemplo n.º 8
0
    private void loadDataChunk(BinaryReader binReader)
    {
        binReader.BaseStream.Seek(0, SeekOrigin.Begin);
        while (binReader.BaseStream.Position < binReader.BaseStream.Length)
        {
            ReadChunk chunk = new ReadChunk(binReader);
            switch (chunk.Name)
            {
            case "data":
                ReadData(chunk);
                break;

            case "tex":
                ReadTexture(chunk);
                break;

            case "buffer":
                ReadBuffer(chunk);
                break;

            case "idx":
                ReadIndices(chunk);
                break;

            case "surf_ps":
                ReadPSSurface(chunk);
                break;

            case "obj":
                ReadObject(chunk);
                break;

            default:
                System.Diagnostics.Debug.Print("未识别的类型 {0}", chunk.Name);
                break;
            }
            chunk.Next();
        }
    }
Ejemplo n.º 9
0
 private void ReadData(ReadChunk chunk)
 {
     _compressionLevel = chunk.Bytes.ReadByte();
 }
Ejemplo n.º 10
0
 private void ReadExtends(ReadChunk data)
 {
     //string jsonObject = ReadUtil.ReadUTF(data.Bytes);
 }