Exemple #1
0
        private void SetValue(byte **pAssets, FacePoint point, int index, int type)
        {
            //Input data from asset cache
            switch (type)
            {
            case 1:
                Vector3 *tIn1 = (Vector3 *)pAssets[type] + index;
                point.Normal = *tIn1;
                break;

            case 2:
            case 3:
                uint *tIn2 = (uint *)pAssets[type] + index;
                point.Color[type - 2] = *tIn2++;
                break;

            default:
                float *tIn3 = (float *)pAssets[type] + index;
                point.UVs[type - 4] = (*tIn3++);
                point.UVs[type - 3] = (*tIn3++);
                break;
            }
        }
Exemple #2
0
        private FacePoint ExtractFacepoint(ref byte *addr, byte **pAssets)
        {
            int       weight = 0;
            int       index  = 0;
            FacePoint fp     = new FacePoint();

            fixed(ushort *pNode = _script.Nodes)
            {
                if (_elemDef.Weighted)
                {
                    weight = pNode[*addr++ / 3];
                }
                for (int i = 0; i < 8; i++)
                {
                    if (_elemDef.TexMatrices[i])
                    {
                        addr++;
                    }
                }

                if (_elemDef.PositionFmt != XFDataFormat.None) //Vertices
                {
                    if (_elemDef.PositionFmt != XFDataFormat.Direct)
                    {
                        if (_elemDef.PositionFmt == XFDataFormat.Index16)
                        {
                            index = *(bushort *)addr;
                            addr += 2;
                        }
                        else
                        {
                            index = *(byte *)addr++;
                        }
                        //Match weight and index with remap table
                        int  mapEntry = (weight << 16) | index;
                        int *pTmp     = (int *)RemapTable.Address;

                        //Find matching index, starting at end of list
                        index = RemapSize;
                        while ((--index >= 0) && (pTmp[index] != mapEntry))
                        {
                            ;
                        }

                        //No match, create new entry
                        //Will be processed into vertices at the end!
                        if (index < 0)
                        {
                            pTmp[index = RemapSize++] = mapEntry;
                        }

                        //Write index
                        fp.VertexId = (ushort)index;
                    }
                    else //Direct
                    {
                    }
                }
                if (_elemDef.Normals)
                {
                    if (_elemDef.NormalFmt != XFDataFormat.Direct)
                    {
                        if (_elemDef.NormalFmt == XFDataFormat.Index16)
                        {
                            index = *(bushort *)addr;
                            addr += 2;
                        }
                        else
                        {
                            index = *(byte *)addr++;
                        }
                        SetValue(pAssets, fp, index, 1);
                    }
                    else //Direct
                    {
                    }
                }
                for (int i = 0; i < 2; i++) //Colors
                {
                    if (_elemDef.Colors[i])
                    {
                        if (_elemDef.ColorFmt[i] != XFDataFormat.Direct)
                        {
                            if (_elemDef.ColorFmt[i] == XFDataFormat.Index16)
                            {
                                index = *(bushort *)addr;
                                addr += 2;
                            }
                            else
                            {
                                index = *(byte *)addr++;
                            }
                            SetValue(pAssets, fp, index, i + 2);
                        }
                        else //Direct
                        {
                        }
                    }
                }
                for (int i = 0; i < 8; i++) //UVs
                {
                    if (_elemDef.UVs[i])
                    {
                        if (_elemDef.UVFmt[i] != XFDataFormat.Direct)
                        {
                            if (_elemDef.UVFmt[i] == XFDataFormat.Index16)
                            {
                                index = *(bushort *)addr;
                                addr += 2;
                            }
                            else
                            {
                                index = *(byte *)addr++;
                            }
                            SetValue(pAssets, fp, index, i + 4);
                        }
                        else //Direct
                        {
                        }
                    }
                }
            }

            return(fp);
        }