Exemplo n.º 1
0
        private List <IResourceConnection> MATD_GetDiffuseSpecular()
        {
            string rootStr = this.GetContentPathRootName();
            List <IResourceConnection> results = new List <IResourceConnection>();
            GenericRCOLResource        rcol    = base.Resource as GenericRCOLResource;

            if (rcol == null)
            {
                return(results);
            }
            string absolutePath, absoluteName;

            Diagnostics.Log("MATD_GetDiffuseSpecular: " +
                            ResourceGraph.PrintRKTag(base.originalKey, rootStr));
            for (int i = 0; i < rcol.ChunkEntries.Count; i++)
            {
                MATD matd = rcol.ChunkEntries[i].RCOLBlock as MATD;
                if (matd == null)
                {
                    continue;
                }

                ShaderDataList sdataList;
                if (matd.ContentFields.Contains("Mtnf"))
                {
                    sdataList    = matd.Mtnf.SData;
                    absolutePath = rootStr + ".ChunkEntries[" + i + "].RCOLBlock.Mtnf.SData[";
                }
                else
                {
                    sdataList    = matd.Mtrl.SData;
                    absolutePath = rootStr + ".ChunkEntries[" + i + "].RCOLBlock.Mtrl.SData[";
                }

                for (int j = 0; j < sdataList.Count; j++)
                {
                    ElementTextureRef texRef = sdataList[i] as ElementTextureRef;
                    if (texRef != null && IsWantedImage(texRef.Field))
                    {
                        TGIBlock tgiblock = rcol.Resources[texRef.Data.TGIBlockIndex];
                        if (ResourceGraph.IsDDS(tgiblock.ResourceType))
                        {
                            absoluteName = rootStr + ".Resources[" + texRef.Data.TGIBlockIndex + "]";
                            results.Add(new DefaultConnection(tgiblock, tgiblock,
                                                              ResourceDataActions.FindWrite, absoluteName));
                        }
                    }
                    else
                    {
                        ElementTextureKey texKey = sdataList[i] as ElementTextureKey;
                        if (texKey != null && IsWantedImage(texKey.Field))
                        {
                            if (ResourceGraph.IsDDS(texKey.Data.ResourceType))
                            {
                                absoluteName = absolutePath + j + "].Data";
                                results.Add(new DefaultConnection(texKey.Data, texKey,
                                                                  ResourceDataActions.FindWrite, absoluteName, rootStr + ".Data"));
                            }
                        }
                    }
                }
            }
            return(results);
        }
Exemplo n.º 2
0
        private IResourceConnection GEOM_getNormalMap()
        {
            Diagnostics.Log("GEOM_getNormalMap");
            //if (geomItem == null) { Diagnostics.Show("GEOM reference not found"); return; }
            if (base.resource == null)
            {
                Diagnostics.Show("GEOM resource not found"); return(null);
            }
            if (!(base.resource is meshExpImp.ModelBlocks.GeometryResource))
            {
                Diagnostics.Show("GEOM resource is not a GeometryResource"); return(null);
            }
            meshExpImp.ModelBlocks.GeometryResource geomResource = base.resource as meshExpImp.ModelBlocks.GeometryResource;
            if (geomResource.ChunkEntries.Count != 1)
            {
                Diagnostics.Show("GeometryResource should have 1 Chunk, found " + geomResource.ChunkEntries.Count); return(null);
            }
            meshExpImp.ModelBlocks.GEOM geom = geomResource.ChunkEntries[0].RCOLBlock as meshExpImp.ModelBlocks.GEOM;
            if (geom == null)
            {
                Diagnostics.Show("GEOM RCOL block not found"); return(null);
            }
            if (geom.Shader == 0)
            {
                return(null);
            }
            MTNF mtnf = geom.Mtnf;

            if (mtnf == null)
            {
                Diagnostics.Show("MTNF expected but was null"); return(null);
            }
            ShaderData sd = mtnf.SData.Find(IsNormalMap);

            if (sd == null)
            {
                Diagnostics.Show("NormalMap not found"); return(null);
            }
            ElementTextureRef tr = sd as ElementTextureRef;

            if (tr == null)
            {
                Diagnostics.Show("NormalMap not an ElementTextureRef"); return(null);
            }
            //This will break when Data stops being a ChunkRef and turns into a plain int...
            int index = -2;

            using (MemoryStream ms = new MemoryStream())
            {
                tr.Data.UnParse(ms);
                ms.Position = 0;
                index       = new BinaryReader(ms).ReadInt32();
            }
            if (index < 0)
            {
                Diagnostics.Show(String.Format("NormalMap index read {0}, expected >= 0", index)); return(null);
            }
            if (index >= geom.TGIBlocks.Count)
            {
                Diagnostics.Show(String.Format("NormalMap index read {0}, expected < {1}", index, geom.TGIBlocks.Count)); return(null);
            }
            //if (rkLookup.ContainsValue(geom.TGIBlocks[index])) { Diagnostics.Show("Already seen NormalMap " + geom.TGIBlocks[index]); }
            //Add("casp.GEOM.NormalMap", geom.TGIBlocks[index]);
            return(new DefaultConnection(geom.TGIBlocks[index], geom.TGIBlocks[index], ResourceDataActions.FindWrite,
                                         "geom.ChunkEntries[0].RCOLBlock.TGIBlocks[" + index + "]"));
        }