Tuesday, 19th June, 2007

Exporting from 3ds max to Virtools using Real World Scale

Filed under: 3ds max, Virtools, Virtools Tutorials, Tips and Tricks — dominique @ 01:06

I have a case where I procedurally create content in 3ds max. Using the quite new feature "RealWorld Scale" UV coordinates I also get usable UV generated. But when I imported the geometries into Virtools, the UVs had an offset of 0.5. I saw that if I turn off the Real World Scale, in 3ds max, I lost that offset. I also tried the new Dev4 Collada import but it seems to totally ignore tiling and offset values. So, here are the code snippets for a quick Max2Virtools.dle source code Mod, enabling RealWorldScale support. I only tested it for my case, so maybe it doesn't work for other cases - in that case it might serve as starting point.

In file export.cpp find the section that looks like this

    //– Apply tiling
    u=-uvgen.UOffset + 0.5f + ((u-0.5f)*uvgen.UScale);
    v=uvgen.VOffset + 0.5f + ((v-0.5f)*uvgen.VScale);

replace it with something like this

    //– Apply tiling
    // dbo 19.07.2007 - when using real world coords offset by 0.5
    // warning - just tested for my case - use this only as a starting point
    if (! uvgen.RealWorldCoords)
    {
        u=-uvgen.UOffset + 0.5f + ((u-0.5f)*uvgen.UScale);
        v=uvgen.VOffset + 0.5f + ((v-0.5f)*uvgen.VScale);
    }
    else
    {
        u=-uvgen.UOffset + ((u-0.5f)*uvgen.UScale);
        v=uvgen.VOffset  + ((v-0.5f)*uvgen.VScale);
    }

in that same file you have something like

    uvgen.AngleMap        = uvs->GetAng(0);
    uvgen.Cropping        = FALSE;
    uvgen.UCropOffset    = 0;
    uvgen.VCropOffset    = 0;
    uvgen.UCropScale    = 1.0f;
    uvgen.VCropScale    = 1.0f;

 append one line so it looks like this:

    uvgen.AngleMap        = uvs->GetAng(0);
    uvgen.Cropping        = FALSE;
    uvgen.UCropOffset    = 0;
    uvgen.VCropOffset    = 0;
    uvgen.UCropScale    = 1.0f;
    uvgen.VCropScale    = 1.0f;

    uvgen.RealWorldCoords = uvs->GetUseRealWorldScale();

In the file Max2Nemo.h replace this

struct TextureUVGen {
    BOOL TileU,TileV;
    BOOL MirrorU,MirrorV;
    BOOL Cropping;
    float UOffset,VOffset;
    float UScale,VScale;
    float AngleMap;
    float UCropOffset,VCropOffset;
    float UCropScale,VCropScale;
    TextureUVGen() {
        TileU = TileV = MirrorU = MirrorV = Cropping = FALSE;
        UOffset = VOffset = AngleMap = UCropOffset =VCropOffset = 0.0f;
        UScale = VScale = UCropScale = VCropScale                = 0.0f;
    }
};

with this

struct TextureUVGen {
    BOOL TileU,TileV;
    BOOL MirrorU,MirrorV;
    BOOL Cropping;
    BOOL RealWorldCoords;
    float UOffset,VOffset;
    float UScale,VScale;
    float AngleMap;
    float UCropOffset,VCropOffset;
    float UCropScale,VCropScale;
    TextureUVGen() {
        RealWorldCoords = TileU = TileV = MirrorU = MirrorV = Cropping = FALSE;
        UOffset = VOffset = AngleMap = UCropOffset =VCropOffset = 0.0f;
        UScale = VScale = UCropScale = VCropScale                = 0.0f;
    }
};

You are ready! Note this is for 3ds max8 and +
If you need the binary for 3ds max8, send me an eMail.

Bookmark and Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • Digg
  • Reddit
  • Google Bookmarks
  • YahooMyWeb
  • Live-MSN
  • Facebook

No Comments »

No comments yet.

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .

Bookmark and Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • Digg
  • Reddit
  • Google Bookmarks
  • YahooMyWeb
  • Live-MSN
  • Facebook