Twili Posted November 15, 2014 Share Posted November 15, 2014 It's finally time. Let's rip a textured model from A Link Between Worlds! For this tutorial, you will need... Windows. (Unless you can run a .NET program on another OS.) Patience. A trained eye. A hex editor. (HxD will be used in the tutorial images.) Calculator and text editor. xdaniel's N3DSCmbViewer. (For exporting textures. ) I'm linking the second-to-final build, as the final build doesn't work for me, and may not for others. Plus, there aren't any drawbacks. http://magicstone.de/dzd/random/3ds/N3DSCmbViewer_test9.rar A good OoT 3D model to manipulate the texture of. http://www.mediafire.com/download/r7z0y10o4omy8ic/bdan_tdoor_yari_model.cmb szstools. (For decompressing Yaz0-compressed SZS archives. Contains yaz0dec.exe.) http://amnoid.de/gc/szstools.zip An ALBW SZS archive to decompress and extract. http://www.mediafire.com/download/tc9a42vxi37yu6d/Demo1.szs A pack of tools that I wrote. (sext.exe (SARC EXTract), texturegetter.exe, printgroups.exe, vgen.exe, and fgen.exe) http://www.mediafire.com/download/uuaqmeyo30dm8hr/myconversiontools.zip A 3D model viewer/editor capable of reading OBJ files. Part 1: Ripping textures. Extract myconversiontools.zip and only yaz0dec.exe from szstools.zip to some folder and put Demo1.szs in there as well. Click and drag Demo1.szs into yaz0dec.exe, and you'll get this: You can delete Demo1.szs now and rename Demo1.szs 0.rarc to Demo1.sarc. Click and drag Demo1.sarc into sext.exe and you'll get these: My extractor detects the file type (either .bch or generic .bin) and gives the files appropriate filenames if possible. If it's a number, it's simply the index number of the file in the archive. (0 being first.) Alright. We're going to rip the textures for Link. To do that, we need to start by giving texturegetter.exe the arguments it needs. This is where the "trained eye" aspect comes into play. There's no simple pointer to the texture name table (that I know of) in a BCH model, so we have to locate it manually. Open LinkDemo.bch in your hex editor. This pointer, always at offset 0xC of the header, is to the symbol chunk. It's every label for everything in the model. (Joints, cameras, textures, etc.) It needs to be wordswapped: 000031A0 Go there. It should look like this on the text side: Etc. We need to find the first text string that's a texture name. As a rule of thumb, it nearly always comes after a string containing "silhouette" in it. So search for that: The first texture name is in fact "boots.0" at 0x3309. This needs to be subtracted from the start of the symbol chunk. 3309 - 31A0 = 169 Now we have a pointer that's part of the texture name table. It needs to be little endian: 69010000 Go back to the start of LinkDemo.bch and search for that pointer! Every 0xC bytes is an entry in the texture name table, the last 4 being the relative pointer inside the symbol chunk. It's obviously not only to do with the name of the texture, but it's all we care about. The table started at 0x1C8, so that's the second argument that texturegetter.exe needs. Make a batch file: @echo off texturegetter LinkDemo.bch 0x1C8 > LinkDemo_textures.txt Save as texturegetter.bat in the same folder and double-click... There's another table further in with the offsets to the textures themselves that the program takes care of. You also get that text document with important information: This file has 40 textures. 00|Dimensions: 20002000 Name: boots.0 01|Dimensions: 20002000 Name: boots.1 02|Dimensions: 20002000 Name: bracelet.0 03|Dimensions: 20002000 Name: bracelet.1 ... Etc. A good texture to export first is "main.0", so we'll do that. Now it's time to have some fun with bdan_tdoor_yari_model.cmb and N3DSCmbViewer. I'm going to load it just so there's a before and after comparison... Open main.0.bin in your hex editor, select all, and copy. Then open bdan_tdoor_yari_model.cmb and paste main.0.bin at the end of it: Note that 0x10600 was the old end offset of this OoT 3D model. It's now where we're going to repoint the texture data pointer in the file. Also note that (not pictured) the new end offset of the entire file is 0x1B080. Go to the start of this .cmb file and make these changes: Recall the entry for the main.0 texture in LinkDemo_textures.txt: 20|Dimensions: 80000001 Name: main.0 80000001 needs to be pasted somewhere in this .cmb file. By the way, you also need the size of main.0.bin, which is 0xAA80 if you haven't closed it. Make these changes in these spots: Save your changes and reload the model in N3DSCmbViewer for a pleasant surprise. CONTINUED LATER IN PART 1.5! Link to comment Share on other sites More sharing options...
Twili Posted November 16, 2014 Author Share Posted November 16, 2014 Bump. Reserved for part 1.5. Link to comment Share on other sites More sharing options...
xdaniel Posted November 16, 2014 Share Posted November 16, 2014 xdaniel's N3DSCmbViewer. (For exporting textures. ) I'm linking the second-to-final build, as the final build doesn't work for me, and may not for others. Plus, there aren't any drawbacks. http://magicstone.de/dzd/random/3ds/N3DSCmbViewer_test9.rarYou mentioned elsewhere, "The latest version before xdaniel bundled the source with it works for me, but I can't update .NET Framework for the final one.", emphasis mine. From the start, I had targeted the highest overall version of the Framework that VC# 2010 can target, which is .NET 4.0, and I had never changed that, nor do I think I updated my local installation of the Framework while working on the viewer. So if older versions work for you, that latest one should as well. And even if the binary doesn't, there's nothing stopping you from trying to compile the code yourself. Plus, why are you not able to update the Framework in the first place, if I may ask? But all the .NET stuff aside, https://github.com/xdanieldzd/ETC1Lib - that's a somewhat cleaner version of the old ETC1.dll responsible for decoding ETC1 textures in the OoT3D viewer, written - which you'll probably like, considering your apparent dislike of C# and/or .NET - in C++. Even better, that updated library actually converts ETC1A4 textures correctly, unlike the old one from the viewer. You could build that library and then interface with it directly in one of your tools (texturegetter, I'd imagine), cutting out the viewer and silly cmb file hackery entirely. Link to comment Share on other sites More sharing options...
haddockd Posted November 16, 2014 Share Posted November 16, 2014 xDan, you need to start charging for your services Seriously though Twili, great tutorial. Cant wait for the rest! Link to comment Share on other sites More sharing options...
Twili Posted November 17, 2014 Author Share Posted November 17, 2014 You mentioned elsewhere, "The latest version before xdaniel bundled the source with it works for me, but I can't update .NET Framework for the final one.", emphasis mine. From the start, I had targeted the highest overall version of the Framework that VC# 2010 can target, which is .NET 4.0, and I had never changed that, nor do I think I updated my local installation of the Framework while working on the viewer. So if older versions work for you, that latest one should as well. And even if the binary doesn't, there's nothing stopping you from trying to compile the code yourself. Plus, why are you not able to update the Framework in the first place, if I may ask? But all the .NET stuff aside, https://github.com/xdanieldzd/ETC1Lib - that's a somewhat cleaner version of the old ETC1.dll responsible for decoding ETC1 textures in the OoT3D viewer, written - which you'll probably like, considering your apparent dislike of C# and/or .NET - in C++. Even better, that updated library actually converts ETC1A4 textures correctly, unlike the old one from the viewer. You could build that library and then interface with it directly in one of your tools (texturegetter, I'd imagine), cutting out the viewer and silly cmb file hackery entirely. All I know is that trying to launch the binary in N3DSCmbViewer-bin-src.rar returns an error saying I need to update the Framework, but N3DSCmbViewer_test9 doesn't. When I try to update the Framework, the progress bar never moves. The reason I don't compile it myself is because I don't want to; I would need to install Microsoft Visual Studio. So I figured that linking to the version that does work for me is perfectly fine and acceptable, because the changes you made in the final build weren't texture-related. And yes, for the very reason that viewers like BMDView2 for GameCube models don't rely on .NET Framework at all and run perfectly fine, I have disdain for .NET Framework when an application fails to launch for whatever reason related to it. So, I propose that someone else write another OoT 3D viewer with eventual animation support that doesn't rely on .NET. I know it won't be you, because you've made your stance clear, both on OoT 3D and .NET, and that's fine. I would do it myself if I had the programming knowledge required. Also, ETC1A4 textures from ALBW don't use the alpha channel. See this series of posts on GBAtemp: https://gbatemp.net/threads/extracting-models-and-textures-from-3ds-games.370788/page-16#post-5157827 But I have used the newer ETC1.dll in your viewer, taken from Tharsis, and I can say nice job, but I won't be using that version for anything texture-related in ALBW, due to the above reason. Link to comment Share on other sites More sharing options...
xdaniel Posted November 17, 2014 Share Posted November 17, 2014 All I know is that trying to launch the binary in N3DSCmbViewer-bin-src.rar returns an error saying I need to update the Framework, but N3DSCmbViewer_test9 doesn't. When I try to update the Framework, the progress bar never moves. The reason I don't compile it myself is because I don't want to; I would need to install Microsoft Visual Studio. So I figured that linking to the version that does work for me is perfectly fine and acceptable, because the changes you made in the final build weren't texture-related. And yes, for the very reason that viewers like BMDView2 for GameCube models don't rely on .NET Framework at all and run perfectly fine, I have disdain for .NET Framework when an application fails to launch for whatever reason related to it. So, I propose that someone else write another OoT 3D viewer with eventual animation support that doesn't rely on .NET. I know it won't be you, because you've made your stance clear, both on OoT 3D and .NET, and that's fine. I would do it myself if I had the programming knowledge required. Also, ETC1A4 textures from ALBW don't use the alpha channel. See this series of posts on GBAtemp: https://gbatemp.net/threads/extracting-models-and-textures-from-3ds-games.370788/page-16#post-5157827 But I have used the newer ETC1.dll in your viewer, taken from Tharsis, and I can say nice job, but I won't be using that version for anything texture-related in ALBW, due to the above reason. Alright, that's an explanation, and an opinion I can respect, even though I also don't understand why that happens for you. As for ETC1A4, I am lurking GBATemp and have seen those posts. Couldn't really say what ALBW might use the data from the alpha channel for instead, tho, either. That said, you could use either of the DLLs just fine, if you make your tools invoke it directly instead of going through the viewer, as I mentioned. Call the conversion function for ETC1A4, then zero out (or rather "0xFF out", I guess) the alpha channel's data after conversion. And regardless of the whole alpha channel situation, directly using that library would be more convenient for anyone who wants to follow your tutorial, as there would be no more need for all the copy and pasting, running the viewer, dumping the model, etc. Link to comment Share on other sites More sharing options...
Twili Posted November 17, 2014 Author Share Posted November 17, 2014 I'm putting the rest of the tutorial on hold to ask if anyone would like to try fixing the UV mapping issues on Link? http://www.mediafire.com/download/ge17qu7xa1a6e1t/LinkDemoOBJ.zip The only face groups that are perfect as-is are "group1," "group5," "group7," "group9," and "group10." Those are the eyebrows, eyes, open hands, fists, and sheath. The 9 textures contained are .bmp instead of the original .png I exported them as because the viewer I used to view the model only likes .bmp or .jpg. Here's all 40 of Link's textures, though, in .png form (you'll have to edit the .mtl file to use them): http://www.mediafire.com/download/q2h39dpj79716ow/LinkDemo_textures.zip There are only 9 different materials, but there's 40 textures in all because of variants. 2 Link to comment Share on other sites More sharing options...
Zeth Ryder Posted November 17, 2014 Share Posted November 17, 2014 I went ahead and fixed all the UVmapping errors it had though it looked more like the game just mirrored these sections vertically and horizontally. But at the time of writing this post I saw you already had someone fix the model for you from facepunch. Oh well either way it was fun to mess with. Link to comment Share on other sites More sharing options...
Twili Posted November 18, 2014 Author Share Posted November 18, 2014 Facepunch version: http://www.mediafire.com/download/hdk1vv5avn9lo54/LoZALBW-LinkDemoFix.zip Link to comment Share on other sites More sharing options...
Recommended Posts