Use of InitBakeTexture and BakeTexture?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/12/2007 at 18:28, xxxxxxxx wrote:
No problem.
It is quite possible that I get some time to work on that exporter some more in the next few days. So if you find out something about exporting the proper UV coordinates (I'm guessing you're also wanting to export the ones used for rendering by C4D?), please keep me updated. If I find something before that, I'll post my findings.Good luck!
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/12/2007 at 20:49, xxxxxxxx wrote:
I tried some things out today and so far, no joy. I'm currently working with the R9.1 SDK, but it looks like there were substantial changes made by R9.6, so later versions may work (or work differently).
The current problem I'm seeing is that InitBakeTexture() is not filling in the destUVTag under any circumstances that I've tried so far. I had the thought that maybe BakeTexture() is actually supposed to alter it, but so far, it's not either.
The R9.1 c4d_tools.h file has the following comments.../* textag : the texture tag you want to bake (must be assigned to an object) data : bake parameters - see below bmp : the destination bitmap th : the current thread texuvw : must be valid, if UVW pojection is selected in the tag, ignored otherwise destuvw : if not NULL, the current projection is transformed into the uvw tag */
...but neither function is altering the destuvw tag as expected.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/12/2007 at 11:04, xxxxxxxx wrote:
Ok, I'm giving up on InitBakeTexture() and BakeTexture() for getting the UVs fixed... I'm just not having an luck getting them to work at all.
Instead, I've developed a work-around by using GenerateUVW() (c4d_baseobject.h utility function). It seems to handle the various Projection types and texture axis adjustments for me, but I still have to jump through some hoops to handle the Offset/Length/Tiles values of the Texture Tag, as well as account for the fact that there may be multiple Texture Tags on a mesh, each with different Projection types, but restricted to some subset of polygons.
Fortunately, my exporter pre-parsing has already determined which texture tags affect which polygons and set up structures for easy access to everything. Here's my current code (it uses many internal structures, but you should be able to follow along)...//------------------------------------------------------------------------------------------------------ //****************************************************************************************************** // BakeUVs() - create a consolidated and uv-mapping resolved UVWTag // // Because a mesh can have multiple Texture Tags on it (usually restricted to a subset of polygons of // that mesh), with each potentially set to some different Projection type, this routine will loop // through all the various Texture Tags on the mesh and create a consolidated UVWTag for the export // code to use. It also resolves all Offset and Scaling (tiling) adjustments of those tags. //****************************************************************************************************** //------------------------------------------------------------------------------------------------------ Bool ObjSaver::BakeUVs(PolygonObject *op, UVWTag *pDstUVs) { Matrix mg = op->GetMg(); DWORD i,j; // start by grabbing the current UVWTag UVWTag *pSrcUVs = (UVWTag* )(op->GetTag(Tuvw, 0)); if( !pSrcUVs ) return false; // create a working sand-box UVWTag *pWrkUVs = UVWTag::Alloc(m_numFaces); if( !pWrkUVs ) return false; // before we start, set the default state of caller's UVWTag to src for(i=0; i<m_numFaces; i++) pDstUVs->Cpy(i, pSrcUVs, i); objMaterial *pMat = &m_pMats[0]; for(i=0; i<m_numMaterials; i++) { // ================================================================================== // if we have a pointer to a TextureTag for this material, we may need to adjust the // uv values for the polygons assigned to it. If we don't have a pointer, then the // default values filled in above should be good. // ================================================================================== if( pMat->pTex ) { // ================================================================================== // if the texture tag projection is set to something besides UVW, then GenerateUVW() // will resolve it into UVW format. This operation also includes any texture matrix // adjustments, but does not include the offset and tiling values of the tag. If the // call returns NULL, then it's already set to UVW, so we just copy the orginal UVs // into our working tag. // ================================================================================== UVWTag *pGenUVs = GenerateUVW(op, mg, pMat->pTex, mg, NULL); if( pGenUVs ) { for(i=0; i<m_numFaces; i++) pWrkUVs->Cpy(i, pGenUVs, i); UVWTag::Free(pGenUVs); } else { for(i=0; i<m_numFaces; i++) pWrkUVs->Cpy(i, pSrcUVs, i); } // ================================================================================== // next we need to get the offset and tiling (scaling) values from the tag... // ================================================================================== Real uScale = 1.0; Real vScale = 1.0; BaseContainer tagvals = pMat->pTex->GetData(); Real uOffset = -tagvals.GetReal(TEXTURETAG_OFFSETX); Real vOffset = -tagvals.GetReal(TEXTURETAG_OFFSETY); Real lenX = tagvals.GetReal(TEXTURETAG_LENGTHX); Real lenY = tagvals.GetReal(TEXTURETAG_LENGTHY); if( lenX ) uScale /= lenX; if( lenY ) vScale /= lenY; // ================================================================================== // and finally, we loop through all the polygons assigned to this particular Texture // Tag and apply any offset and scaling, transfering the resulting UVs into the caller's // UVWTag // ================================================================================== for(j=0; j<pMat->numFaces; j++) { objFacet *pFacet = &m_pFaces[pMat->pFaceIndices[j]]; // get working uv values UVWStruct uvw = pWrkUVs->Get(pFacet->iPolyNdx); // apply offset and scaling uvw.a.x = (uvw.a.x * uScale) + uOffset; uvw.b.x = (uvw.b.x * uScale) + uOffset; uvw.c.x = (uvw.c.x * uScale) + uOffset; uvw.d.x = (uvw.d.x * uScale) + uOffset; uvw.a.y = (uvw.a.y * vScale) + vOffset; uvw.b.y = (uvw.b.y * vScale) + vOffset; uvw.c.y = (uvw.c.y * vScale) + vOffset; uvw.d.y = (uvw.d.y * vScale) + vOffset; // store adjusted values in caller's UVWTag pDstUVs->Set(pFacet->iPolyNdx, uvw); } } pMat++; } UVWTag::Free(pWrkUVs); return true; }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/12/2007 at 18:09, xxxxxxxx wrote:
wow, that looks much simpler than I was afraid of Thx for posting this, would have taken me quite a while to figure that out, I guess.
I have something along the lines of your TextureTag->Polygons relation already implemented (I'm writing an Ogre export, so I have to work with submeshes anyway for multiple materials on one object), so I should be able to use that code 1:1 more or less. Thx again! -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/12/2007 at 18:46, xxxxxxxx wrote:
Sure thing... after a bit of testing, it looks like it may not be fully cooked yet, but I haven't had a chance to look into it again yet. If I find/fix anything, I'll report back.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/12/2007 at 02:05, xxxxxxxx wrote:
Ahh.. ok, too much cutting and pasting... change this:
if( pGenUVs ) { for(i=0; i<m_numFaces; i++) pWrkUVs->Cpy(i, pGenUVs, i); UVWTag::Free(pGenUVs); } else { for(i=0; i<m_numFaces; i++) pWrkUVs->Cpy(i, pSrcUVs, i); }
...to this...
if( pGenUVs ) { for(j=0; j<m_numFaces; j++) pWrkUVs->Cpy(j, pGenUVs, j); UVWTag::Free(pGenUVs); } else { for(j=0; j<m_numFaces; j++) pWrkUVs->Cpy(j, pSrcUVs, j); }
...replace the 'i' variable with 'j'. The original code above was re-using i inside an i loop, so it was blowing out of the outer loop early :).
Aside from that typo, it looks like it's working now (barring any misunderstanding on my part about the order the math is applied). -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/12/2007 at 04:02, xxxxxxxx wrote:
I implemented UV baking two days ago. Thx for your help. Although the structure I'm working in didn't allow to just copy & paste your method especially the pointer to GenerateUVW(...) was extremely helpful.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/12/2007 at 09:09, xxxxxxxx wrote:
Cool.. btw, you don;t happen to know where I can find the DTS file format specs (Torque engine) do you?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/12/2007 at 13:49, xxxxxxxx wrote:
No, sorry. I'm exporting for Ogre, the currently available exporter discards phong breaks for example, and I'm implementing an exporter for complete scenes. So, I've only looked into Ogre's XML file format for meshes, haven't looked into Torque at all.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/12/2008 at 09:41, xxxxxxxx wrote:
Hey Match,
Hehe... this is kinda funny... I just looked up this thread for someone else and re-read it to refresh my memory. I just saw your post above about exporting for Ogre... guess what I've been working on recently?
Frankly, it never registered with me that you were working on an Ogre exporter when you wrote that a year ago, because I didn't even know what Ogre was until June of this year (I was surprised just now to see Ogre mentioned in your post above).
At that time (June 2008) I got interested/curious and tried out the existing exporter. It's broke in more than one way... I started with the thought of just fixing a few bugs for him, but as I was doing that, I kept running into more and more issues and finally scrapped that source and started from scratch (well, re-working and re-using a lot of my own pre-existing code from Riptide).
I have the .mesh part mostly working and done now, but am still working on the .skeleton file (specifically the animation export part).