## FBX SDK

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page

# ViewScene and Lighting/Texturing revisited

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

44 Views, 6 Replies

01-29-2012 02:40 PM

About 4 years ago there was a discussion about the lighting and texturing of the ViewScene example and I am using the 2011.3 SDK and I only ever get Wire Mesh objects in ViewScene. I can force them to draw if I set

lGLPrimitive = GL_POLYGON;

in GlDrawMesh(

but no Textures.

Have the issues from the 2008 discussion been added to the latest SDK or is there an update.

Anyone have an improvement on the the ViewScene example they are willing to share?

Incidentally, I have tried various ways to get the ViewScene code to link in with my OpenGL program and whilst it links and mostly runs some of the FBX structures appear to be corrupted, so I would not even get the Meshes. When I build it into a dll and dynamically link in, all is fine. Anyone else had experience with this. It works fine in the dll I build -VC2008.

Simon

lGLPrimitive = GL_POLYGON;

in GlDrawMesh(

but no Textures.

Have the issues from the 2008 discussion been added to the latest SDK or is there an update.

Anyone have an improvement on the the ViewScene example they are willing to share?

Incidentally, I have tried various ways to get the ViewScene code to link in with my OpenGL program and whilst it links and mostly runs some of the FBX structures appear to be corrupted, so I would not even get the Meshes. When I build it into a dll and dynamically link in, all is fine. Anyone else had experience with this. It works fine in the dll I build -VC2008.

Simon

Please use plain text.

# Re: ViewScene and Lighting/Texturing revisited

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-29-2012 05:57 PM in reply to:
simonwakley

Hello Simon,

As a sample, Viewscene supports tga texture for a pretty long time already. Please check this out:

http://area.autodesk.com/forum/autodesk-fbx/fbx-sdk/viewscene-texture-mapping-issue/

As a sample, Viewscene supports tga texture for a pretty long time already. Please check this out:

http://area.autodesk.com/forum/autodesk-fbx/fbx-sd

Please use plain text.

# Re: ViewScene and Lighting/Texturing revisited

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-07-2012 10:02 AM in reply to:
simonwakley

Hi,

Thanks. I see the code in the ViewScene program, but the provided Humanoid does not texture so I assume it is using a different texture type. Is there a sample file with TGA texturing I can try?

Thanks. I see the code in the ViewScene program, but the provided Humanoid does not texture so I assume it is using a different texture type. Is there a sample file with TGA texturing I can try?

Please use plain text.

# Re: ViewScene and Lighting/Texturing revisited

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-07-2012 07:56 PM in reply to:
simonwakley

Sorry, the samples I have are from other customers which I cannot post without their permission.

You may contact m210 who posted the http://area.autodesk.com/forum/autodesk-fbx/fbx-sdk/viewscene-texture-mapping-issue/, the one he posted there has the supported targa textures.

You may contact m210 who posted the http://area.autodesk.com/forum/autodesk-fbx/fbx-sd

Please use plain text.

# Re: ViewScene and Lighting/Texturing revisited

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-15-2012 11:16 AM in reply to:
simonwakley

So the latest on this is that the existing version of ViewScene as per 2011.3 only shows wireframe unless the model has a .tga texture (apparently, but no .tga textured model is supplied :-{

If there is no texture, then it defaults to wireframe. I have added a menu option (which is also in the 2012.2 SDK) to allow you to choose wireframe, textured or lighted

I hacked this together from my OpenGL code so it is very ugly but functional and easy to follow (I think)

Since I have been asking for the code myself it is only fair I post this :-) If anyone has a better solution, I'd love to see it. ViewScene will now draw wireframe or lighted and will apparently texture when it can. If ANYONE has other than .tga texturing for ViewScene I'm very interested.

Simon

in main.cxx create menus

int lDrawModeMenu = glutCreateMenu(DrawModeSelectionCallback);

glutAddMenuEntry("Wire Frame", 0);

glutAddMenuEntry("Lighted", 1);

glutAddMenuEntry("Textured", 2);

bit later in same function

// Build the main menu.

glutCreateMenu(MenuSelectionCallback);

glutAddSubMenu("Select Camera", lCameraMenu);

glutAddSubMenu("Select Animation Stack", lAnimStackMenu);

if (lBindPoseCount>0 || lRestPoseCount>0)

glutAddSubMenu("Go to Pose", lPoseMenu);

glutAddMenuEntry("Play", PLAY_ANIMATION);

glutAddSubMenu("Draw Mode", lDrawModeMenu); ADDED SJW

glutAddMenuEntry("Exit", EXIT_ITEM);

glutAttachMenu(GLUT_RIGHT_BUTTON);

call function added global in main.cxx

int gDrawMode = 0;

void DrawModeSelectionCallback(int pItem)

{

gDrawMode = pItem;

gSceneStatus = MUST_BE_REFRESHED;

}

// Modify call to GlDrawMesh in DrawMesh() file DrawScene.cxx

GlDrawMesh(pGlobalPosition,

lMesh,

lVertexArray,

gDrawMode);

In GlFunctions.cxx

// This is commented out lDrawMode = (lDrawMode == DRAW_MODE_TEXTURED && lTexture) ? lDrawMode : DRAW_MODE_WIREFRAME;

lDrawMode = (lDrawMode != DRAW_MODE_TEXTURED) ? lDrawMode : (lTexture ? lDrawMode : DRAW_MODE_WIREFRAME);

//printf("Want to draw %d, going to %d\n", pDrawMode, lDrawMode);

int lGLPrimitive = lDrawMode == DRAW_MODE_WIREFRAME ? GL_LINE_LOOP : GL_POLYGON;

Then in the polygon BEFORE the vertex loop add

// Polygon loop for (lPolygonIndex = 0; lPolygonIndex < lPolygonCount; lPolygonIndex++)

// Shaded, just find the normal for the surface

if (lDrawMode == DRAW_MODE_LIGHTED)

{

VECTOR normal;

POLYGON poly;

// Need 3 points for a normal on a plane.

pVertex = (GLdouble *)pVertexArray;

poly.x1 = *pVertex++;

poly.y1 = *pVertex++;

poly.z1 = *pVertex++;

pVertex = (GLdouble *)pVertexArray;

poly.x2 = *pVertex++;

poly.y2 = *pVertex++;

poly.z2 = *pVertex++;

pVertex = (GLdouble *)pVertexArray;

poly.x3 = *pVertex++;

poly.y3 = *pVertex++;

poly.z3 = *pVertex++;

determine_normal(&poly, normal);

glNormal3fv(normal);

}

NEEDED DEFS and FUNCTIONS

typedef struct tagPOLYGON

{ /* Polygon information */

float x1; /* First vertex x coordinate */

float y1; /* First vertex y coordinate */

float z1; /* First vertex z coordinate */

float x2; /* Second vertex x coordinate */

float y2; /* Second vertex y coordinate */

float z2; /* Second vertex z coordinate */

float x3; /* Third vertex x coordinate */

float y3; /* Third vertex y coordinate */

float z3; /* Third vertex z coordinate */

float x4; /* Fourth vertex x coordinate */

float y4; /* Fourth vertex y coordinate */

float z4; /* Fourth vertex z coordinate */

}POLYGON;

typedef POLYGON *PPOLYGON;

typedef GLfloat VECTOR; /* 3 vector */

#ifndef VSMALL

#define VSMALL (1e-10) /* Small float */

#endif

float vecnorm(VECTOR v)

{

/* Normalize vector to unit length. Return its original length. */

float x, y, z, s, r, rr;

/* Make the vector components positive */

x = v; y = v; z = v;

if( x < 0.0 )

x = -x;

if( y < 0.0 )

y = -y;

if( z < 0.0 )

z = -z;

/* Find the square of the length */

s = x * x + y * y + z * z;

/* The best guess of the length is the largest component. Find it. */

if( x < y )

x = y;

if( x < z )

x = z;

if( x < VSMALL )

{

rr = 0.0;

v = v = v = 0.0;

}

else

{

/* Polish up the guess using 3 in-line N-R iterations */

r = x + s / x;

r = 0.25 * r + s / r;

r = 0.5 * ( r + s / r );

/* Normalize the vector */

rr = r;

r = 1.0 / r;

v *= r;

v *= r;

v *= r;

}

/* Return the length */

return( rr );

}

void determine_normal(PPOLYGON poly, VECTOR normal)

{

/* It is necessary to determine the normals of each polygon in order to */

/* do the lighting correctly. Note only the first three vertices of the */

/* polygon are used for this normal calculation. */

float A, B, C;

/* Firstly, find the plane coefficients */

/* (page 308, "Computer Graphics", Hearn and Baker) */

A = poly->y1*(poly->z2 - poly->z3) + poly->y2*(poly->z3 - poly->z1) + poly->y3*(poly->z1 - poly->z2);

B = poly->z1*(poly->x2 - poly->x3) + poly->z2*(poly->x3 - poly->x1) + poly->z3*(poly->x1 - poly->x2);

C = poly->x1*(poly->y2 - poly->y3) + poly->x2*(poly->y3 - poly->y1) + poly->x3*(poly->y1 - poly->y2);

/* The surface normal vector has coordinates (A, B, C) */

normal = A;

normal = B;

normal = C;

vecnorm(normal);

}

If there is no texture, then it defaults to wireframe. I have added a menu option (which is also in the 2012.2 SDK) to allow you to choose wireframe, textured or lighted

I hacked this together from my OpenGL code so it is very ugly but functional and easy to follow (I think)

Since I have been asking for the code myself it is only fair I post this :-) If anyone has a better solution, I'd love to see it. ViewScene will now draw wireframe or lighted and will apparently texture when it can. If ANYONE has other than .tga texturing for ViewScene I'm very interested.

Simon

in main.cxx create menus

int lDrawModeMenu = glutCreateMenu(DrawModeSelectionCallback);

glutAddMenuEntry("Wire Frame", 0);

glutAddMenuEntry("Lighted", 1);

glutAddMenuEntry("Textured", 2);

bit later in same function

// Build the main menu.

glutCreateMenu(MenuSelectionCallback);

glutAddSubMenu("Select Camera", lCameraMenu);

glutAddSubMenu("Select Animation Stack", lAnimStackMenu);

if (lBindPoseCount>0 || lRestPoseCount>0)

glutAddSubMenu("Go to Pose", lPoseMenu);

glutAddMenuEntry("Play", PLAY_ANIMATION);

glutAddSubMenu("Draw Mode", lDrawModeMenu); ADDED SJW

glutAddMenuEntry("Exit", EXIT_ITEM);

glutAttachMenu(GLUT_RIGHT_BUTTON);

call function added global in main.cxx

int gDrawMode = 0;

void DrawModeSelectionCallback(int pItem)

{

gDrawMode = pItem;

gSceneStatus = MUST_BE_REFRESHED;

}

// Modify call to GlDrawMesh in DrawMesh() file DrawScene.cxx

GlDrawMesh(pGlobalPosition,

lMesh,

lVertexArray,

gDrawMode);

In GlFunctions.cxx

// This is commented out lDrawMode = (lDrawMode == DRAW_MODE_TEXTURED && lTexture) ? lDrawMode : DRAW_MODE_WIREFRAME;

lDrawMode = (lDrawMode != DRAW_MODE_TEXTURED) ? lDrawMode : (lTexture ? lDrawMode : DRAW_MODE_WIREFRAME);

//printf("Want to draw %d, going to %d\n", pDrawMode, lDrawMode);

int lGLPrimitive = lDrawMode == DRAW_MODE_WIREFRAME ? GL_LINE_LOOP : GL_POLYGON;

Then in the polygon BEFORE the vertex loop add

// Polygon loop for (lPolygonIndex = 0; lPolygonIndex < lPolygonCount; lPolygonIndex++)

// Shaded, just find the normal for the surface

if (lDrawMode == DRAW_MODE_LIGHTED)

{

VECTOR normal;

POLYGON poly;

// Need 3 points for a normal on a plane.

pVertex = (GLdouble *)pVertexArray;

poly.x1 = *pVertex++;

poly.y1 = *pVertex++;

poly.z1 = *pVertex++;

pVertex = (GLdouble *)pVertexArray;

poly.x2 = *pVertex++;

poly.y2 = *pVertex++;

poly.z2 = *pVertex++;

pVertex = (GLdouble *)pVertexArray;

poly.x3 = *pVertex++;

poly.y3 = *pVertex++;

poly.z3 = *pVertex++;

determine_normal(&poly, normal);

glNormal3fv(normal);

}

NEEDED DEFS and FUNCTIONS

typedef struct tagPOLYGON

{ /* Polygon information */

float x1; /* First vertex x coordinate */

float y1; /* First vertex y coordinate */

float z1; /* First vertex z coordinate */

float x2; /* Second vertex x coordinate */

float y2; /* Second vertex y coordinate */

float z2; /* Second vertex z coordinate */

float x3; /* Third vertex x coordinate */

float y3; /* Third vertex y coordinate */

float z3; /* Third vertex z coordinate */

float x4; /* Fourth vertex x coordinate */

float y4; /* Fourth vertex y coordinate */

float z4; /* Fourth vertex z coordinate */

}POLYGON;

typedef POLYGON *PPOLYGON;

typedef GLfloat VECTOR; /* 3 vector */

#ifndef VSMALL

#define VSMALL (1e-10) /* Small float */

#endif

float vecnorm(VECTOR v)

{

/* Normalize vector

float x, y, z, s, r, rr;

/* Make the vector components positive */

x = v; y = v; z = v;

if( x < 0.0 )

x = -x;

if( y < 0.0 )

y = -y;

if( z < 0.0 )

z = -z;

/* Find the square of the length */

s = x * x + y * y + z * z;

/* The best guess of the length is the largest component. Find it. */

if( x < y )

x = y;

if( x < z )

x = z;

if( x < VSMALL )

{

rr = 0.0;

v = v = v = 0.0;

}

else

{

/* Polish up the guess using 3 in-line N-R iterations */

r = x + s / x;

r = 0.25 * r + s / r;

r = 0.5 * ( r + s / r );

/* Normalize the vector */

rr = r;

r = 1.0 / r;

v *= r;

v *= r;

v *= r;

}

/* Return the length */

return( rr );

}

void determine_normal(PPOLYGON poly, VECTOR normal)

{

/* It is necessary to determine the normals of each polygon in order to */

/* do the lighting correctly. Note only the first three vertices of the */

/* polygon are used for this normal calculation. */

float A, B, C;

/* Firstly, find the plane coefficients */

/* (page 308, "Computer Graphics", Hearn and Baker) */

A = poly->y1*(poly->z2 - poly->z3) + poly->y2*(poly->z3 - poly->z1) + poly->y3*(poly->z1 - poly->z2);

B = poly->z1*(poly->x2 - poly->x3) + poly->z2*(poly->x3 - poly->x1) + poly->z3*(poly->x1 - poly->x2);

C = poly->x1*(poly->y2 - poly->y3) + poly->x2*(poly->y3 - poly->y1) + poly->x3*(poly->y1 - poly->y2);

/* The surface normal vector has coordinates (A, B, C) */

normal = A;

normal = B;

normal = C;

vecnorm(normal);

}

Please use plain text.

# Re: ViewScene and Lighting/Texturing revisited

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-15-2012 11:17 AM in reply to:
simonwakley

Plus

#define DRAW_MODE_WIREFRAME 0

#define DRAW_MODE_LIGHTED 1

#define DRAW_MODE_TEXTURED 2

#define DRAW_MODE_WIREFRAME 0

#define DRAW_MODE_LIGHTED 1

#define DRAW_MODE_TEXTURED 2

Please use plain text.

# Re: ViewScene and Lighting/Texturing revisited

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-07-2012 02:05 AM in reply to:
simonwakley

Hi Simon,

In the meantime, I have managed to get lighting/texturing in a customized version of ViewScene sample. But you'd need to do your due-diligence as well, as I don't have physical time to pack it as a stand-alone sample. would you like to send it to you?

Best regards,

Rumen Filkov

In the meantime, I have managed to get lighting/texturing in a customized version of ViewScene sample. But you'd need to do your due-diligence as well, as I don't have physical time to pack it as a stand-alone sample. would you like to send it to you?

Best regards,

Rumen Filkov

Please use plain text.