public static vms_vector operator+(vms_vector a, vms_vector b)
        {
            vms_vector ret = a;

            ret.x.n += b.x.n;
            ret.y.n += b.y.n;
            ret.z.n += b.z.n;
            return(ret);
        }
Exemple #2
0
        static void AddPoint(int bitmap, ref vms_vector norm, ref vms_vector p, ref g3s_uvl uvl)
        {
            var uPoint = new UPoint {
                norm = norm, p = p, uvl = uvl
            };
            int idx;

            if (!uPointIdx.TryGetValue(uPoint, out idx))
            {
                uPointIdx[uPoint] = idx = uPoints.Count;
                uPoints.Add(uPoint);
            }
            tris[bitmap].Add(idx);
        }
Exemple #3
0
        static void DumpModelData(BinaryReader r, List <int> flatColors, int texCount)
        {
            //Debug.Log("Sub start " + r.BaseStream.Position);
            int glow_idx = -1; // only 0 is actually used

            for (PolyOp op; (op = (PolyOp)r.ReadInt16()) != PolyOp.EOF;)
            {
                int        n, s, i, color, bitmap, i1, i2;
                ushort[]   pointIdx;
                g3s_uvl[]  uvls;
                vms_vector v = default(vms_vector), norm = default(vms_vector);
                //vms_vector[] pvs;
                vms_vector oldPointPos;
                g3s_uvl    uvl      = default(g3s_uvl);
                var        startPos = r.BaseStream.Position - 2;
                //Debug.Log(startPos + ": " + op + " ");
                switch (op)
                {
                case PolyOp.DEFPOINTS:
                    n = r.ReadInt16();
                    //pvs = new vms_vector[n];
                    //pvs.Read(r);
                    for (i = 0; i < n; i++)
                    {
                        points[i].Read(r);
                        points[i] += pointPos;
                    }
                    //Debug.Log(n + " " + string.Join(", ", pvs.Select(x => x.ToString()).ToArray()));
                    break;

                case PolyOp.DEFP_START:
                    n = r.ReadInt16();
                    s = r.ReadInt16();
                    r.ReadInt16();     // align
                                       //pvs = new vms_vector[n];
                                       //pvs.Read(r);
                    for (i = 0; i < n; i++)
                    {
                        points[i + s].Read(r);
                        points[i + s] += pointPos;
                    }
                    //Debug.Log(s + " " + n + " " + string.Join(", ", pvs.Select(x => x.ToString()).ToArray()));
                    break;

                case PolyOp.FLATPOLY:
                    n = r.ReadInt16();
                    v.Read(r);
                    norm.Read(r);
                    color    = r.ReadInt16();
                    pointIdx = new ushort[n];
                    pointIdx.Read(r);
                    if ((n & 1) == 0)
                    {
                        r.ReadInt16();     // align
                    }
                    //Debug.Log(v + " " + norm + " c=" + color + " " + n + " " + string.Join(", ", pointIdx.Select(x => x.ToString()).ToArray()));
                    int colIdx = flatColors.IndexOf(color);
                    if (colIdx == -1)
                    {
                        colIdx = flatColors.Count;
                        flatColors.Add(color);
                    }
                    for (i = 2; i < n; i++)
                    {
                        AddPoint(texCount + colIdx, ref norm, ref points[pointIdx[0]], ref uvl);
                        AddPoint(texCount + colIdx, ref norm, ref points[pointIdx[i - 1]], ref uvl);
                        AddPoint(texCount + colIdx, ref norm, ref points[pointIdx[i]], ref uvl);
                    }
                    break;

                case PolyOp.TMAPPOLY:
                    n = r.ReadInt16();
                    v.Read(r);
                    norm.Read(r);
                    bitmap   = r.ReadInt16();
                    pointIdx = new ushort[n];
                    pointIdx.Read(r);
                    if ((n & 1) == 0)
                    {
                        r.ReadInt16();     // align
                    }
                    uvls = new g3s_uvl[n];
                    uvls.Read(r);
                    //Debug.Log(v + " " + norm + " bm=" + bitmap + " " + n + " " + string.Join(", ", pointIdx.Select(x => x.ToString()).ToArray()) + " " + string.Join(", ", uvls.Select(x => x.ToString()).ToArray()));
                    for (i = 2; i < n; i++)
                    {
                        AddPoint(bitmap, ref norm, ref points[pointIdx[0]], ref uvls[0]);
                        AddPoint(bitmap, ref norm, ref points[pointIdx[i - 1]], ref uvls[i - 1]);
                        AddPoint(bitmap, ref norm, ref points[pointIdx[i]], ref uvls[i]);
                    }
                    glow_idx = -1;
                    break;

                case PolyOp.SORTNORM:
                    r.ReadInt16();     // align
                    v.Read(r);
                    norm.Read(r);
                    i1 = r.ReadInt16();
                    i2 = r.ReadInt16();
                    //Debug.Log(v + " " + norm + " " + i1 + " " + i2);
                    var pos = r.BaseStream.Position;
                    r.BaseStream.Position = startPos + i1;
                    DumpModelData(r, flatColors, texCount);
                    r.BaseStream.Position = startPos + i2;
                    DumpModelData(r, flatColors, texCount);
                    r.BaseStream.Position = pos;
                    break;

                case PolyOp.RODBM:
                    bitmap = r.ReadInt16();     // align
                    v.Read(r);
                    i1 = r.ReadInt16();
                    r.ReadInt16();     // align
                    norm.Read(r);
                    i2 = r.ReadInt16();
                    r.ReadInt16();     // align
                    //Debug.Log(v + " " + norm + " " + i1 + " " + i2);
                    break;

                case PolyOp.SUBCALL:
                    i2 = r.ReadInt16();
                    v.Read(r);
                    i1 = r.ReadInt16();
                    r.ReadInt16();     // align
                    //Debug.Log("anim=" + i2 + " " + v + " " + i1);
                    pos = r.BaseStream.Position;
                    r.BaseStream.Position = startPos + i1;
                    oldPointPos           = pointPos;
                    pointPos += v;
                    DumpModelData(r, flatColors, texCount);
                    pointPos = oldPointPos;
                    r.BaseStream.Position = pos;
                    break;

                case PolyOp.GLOW:
                    glow_idx = r.ReadInt16();
                    //Debug.Log(i1.ToString());
                    break;

                default:
                    throw new Exception();
                }
            }
            //Debug.Log("Sub done");
        }
Exemple #4
0
 public static Vector3 ToVector3(this vms_vector v)
 {
     return(new Vector3(v.x.ToFloat(), v.y.ToFloat(), v.z.ToFloat()));
 }