Exemplo n.º 1
0
 string[] GetAttributeNames(List <RipAttribute> attrs, int[] indices)
 {
     string[] rlt = new string[indices.Length + 1];
     rlt[0] = "Ignore";
     for (int i = 0; i < indices.Length; i++)
     {
         RipAttribute attr = attrs[indices[i]];
         rlt[i + 1] = attrs[indices[i]].semantic + ((attr.semanticIndex != 0)?(attr.semanticIndex + 1).ToString() :"");
     }
     return(rlt);
 }
Exemplo n.º 2
0
 int GetDefaultIndexValue(List <RipAttribute> attrs, string defaultName)
 {
     for (int i = 0; i < attrs.Count; i++)
     {
         RipAttribute attr     = attrs[i];
         string       attrName = attr.semantic + ((attr.semanticIndex != 0) ? (attr.semanticIndex + 1).ToString() : "");
         if (attrName == defaultName)
         {
             return(i);
         }
     }
     return(-1);
 }
Exemplo n.º 3
0
    static RipModel ReadModel(BinaryReader bin)
    {
        RipModel model = ScriptableObject.CreateInstance <RipModel>();

        model.signature = bin.ReadUInt32();
        model.version   = bin.ReadUInt32();
        int facesCnt            = bin.ReadInt32();
        int vertexesCnt         = bin.ReadInt32();
        int vertexSize          = bin.ReadInt32();
        int textureFilesCnt     = bin.ReadInt32();
        int shaderFilesCnt      = bin.ReadInt32();
        int vertexAttributesCnt = bin.ReadInt32();

        model.vertexesCnt  = vertexesCnt;
        model.faces        = new int[facesCnt * 3];
        model.textureFiles = new string[textureFilesCnt];
        model.shaderFiles  = new string[shaderFilesCnt];
        model.attributes   = new List <RipAttribute>();// new RipAttribute[vertexAttributesCnt];//8

        for (int i = 0; i < vertexAttributesCnt; i++)
        {
            RipAttribute attr = ScriptableObject.CreateInstance <RipAttribute>();
            attr.semantic      = ReadString(bin);
            attr.semanticIndex = bin.ReadInt32();
            attr.offset        = bin.ReadInt32();
            attr.size          = bin.ReadInt32();
            int elementCnt = bin.ReadInt32();//3
            attr.vertexAttribTypesArray = new int[elementCnt];
            for (int e = 0; e < elementCnt; e++)
            {
                int typeElement = bin.ReadInt32();
                attr.vertexAttribTypesArray[e] = typeElement;
            }
            model.attributes.Add(attr);
        }
        for (int t = 0; t < model.textureFiles.Length; t++)
        {
            model.textureFiles[t] = ReadString(bin);
        }
        for (int s = 0; s < model.shaderFiles.Length; s++)
        {
            model.shaderFiles[s] = ReadString(bin);
        }
        for (int f = 0; f < facesCnt; f++)
        {
            model.faces[f * 3 + 0] = bin.ReadInt32();
            model.faces[f * 3 + 1] = bin.ReadInt32();
            model.faces[f * 3 + 2] = bin.ReadInt32();
        }
        for (int a = 0; a < vertexAttributesCnt; a++)
        {
            model.attributes[a].values = new Vector4[vertexesCnt];
        }
        for (int v = 0; v < vertexesCnt; v++)
        {
            for (int a = 0; a < vertexAttributesCnt; a++)
            {
                float[] values = new float[4];
                for (int i = 0; i < model.attributes[a].vertexAttribTypesArray.Length; i++)
                {
                    values[i] = bin.ReadSingle();
                }
                model.attributes[a].values[v] = new Vector4(values[0], values[1], values[2], values[3]);
            }
        }
        return(model);
    }