Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


Exporting from pandasoft and 3ds max


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
16 replies to this topic

#1 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 15 February 2013 - 03:57 AM

I'd like to export a mesh to direct3d.

I have, in max, rotated 90 degrees in the x-axis

and -180 degrees in the z-axis

so that the mesh's bottom, in the front view,  is facing me. And the "front" of the mesh is pointing upward. It is exported as a left-handed coordinate system, while 3ds max is right-handed

The mesh is displayed correctly.

In my engine, I set the pos to D3DXVECTOR3(10,0,10);

However there is a problem, the mesh has been raised up to about 10 units so that I have to offset it downward to reach the ground level. It seems like some axis is wrong.

 Does anyone have some instructions on how to export stuff from max by pandasoft to direct3d?

Thanks

Jack

Attached Thumbnails

  • axis.png

Edited by lucky6969b, 15 February 2013 - 04:30 AM.


Sponsor:

#2 belfegor   Crossbones+   -  Reputation: 2689

Like
0Likes
Like

Posted 15 February 2013 - 06:46 AM

After you done all transformations in MAX you must apply "Reset X form"

 

maxexp.jpg

 

and then export.



#3 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 15 February 2013 - 11:59 PM

Having selected the object, the reset selected button remained dimmed



#4 belfegor   Crossbones+   -  Reputation: 2689

Like
0Likes
Like

Posted 16 February 2013 - 12:26 AM

If you have multiple objects grouped, un-group them and then reset.



#5 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 16 February 2013 - 12:32 AM

The model is seriously distorted.

It seems like every part was reset to 0,0,0



#6 belfegor   Crossbones+   -  Reputation: 2689

Like
0Likes
Like

Posted 16 February 2013 - 01:47 AM

I don't know how to help you further. If i have model composed of different parts i usually just work on each separately and have no problems with that.

Only that i know for sure is that "Reset X Form" is necessary after all transformations, otherwise it will not export correctly.



#7 ankhd   Members   -  Reputation: 1322

Like
0Likes
Like

Posted 16 February 2013 - 03:01 AM

Hi there. It sounds like the world of the grouped mesh is not located on the centre of the 3dsmax's world.



#8 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 16 February 2013 - 03:22 AM

Thanks ankhd,

It is like what you said. Here comes another problem.

When I set the object to D3DXVECTOR3(0,0,10) and transform it when I want to draw it.

I still get the Z axis pointing upward. Like this

const D3DXMATRIX& GetWorldMatrix()
    {
        
        D3DXMATRIX mat;
        
        if(rot.x != 0.0f || rot.y != 0.0f || rot.z != 0.0f)
        {
            D3DXQuaternionRotationYawPitchRoll(&quatRot, rot.x, rot.y, rot.z);
            D3DXMatrixTransformation(&mat, &scaleCenter, NULL, &scale,
                &rotCenter, &quatRot, &pos);
        }
        else
        {
            D3DXMatrixTransformation(&mat, &scaleCenter, NULL, &scale,
            NULL, NULL, &pos);
        }
        return mat;

     }

 

Attached Thumbnails

  • coordinate.png


#9 belfegor   Crossbones+   -  Reputation: 2689

Like
0Likes
Like

Posted 16 February 2013 - 03:33 AM

You have a bug in your code, returning reference to a local var witch is destroyed after return!


Edited by belfegor, 16 February 2013 - 03:34 AM.


#10 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 16 February 2013 - 03:41 AM

The debugger shows the correct matrix however... strange no?

Attached Thumbnails

  • matrix.png


#11 belfegor   Crossbones+   -  Reputation: 2689

Like
0Likes
Like

Posted 16 February 2013 - 03:59 AM

It might do that but it is still a bug that can possibly hurt you later. Just return matrix by value, there is no need for super-sonic-optimized functions at this time, to be 100% sure that everything is by the book.

 

How do you build your view & proj matrices? Is it left handed? Did you thick "Left handed axis" at export from MAX?

 

I just took a better look at your picture from project window, and i don't see where did you combine object world matrix with view & proj.

Its name is "xWorldViewProj" but i can see only view * proj?

Can you show what ViewMatrix and ProjMatrix functions looks like?


Edited by belfegor, 16 February 2013 - 04:12 AM.


#12 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 16 February 2013 - 04:45 AM

Let's summarize what I have done

First, I didn't export the meshes to left-handed system and now I didn't flip the axis

But I converted my Cameras as follows

 

            //// Start exporting View and projection matrices
                                    Interface *ip2 = GetCOREInterface();
                                    ViewExp * pView = ip2->GetActiveViewport();  //  Get the viewport in question
                                    GraphicsWindow *gw = pView->getGW();  //  Get the GraphicsWindow context

        
                                    

                                    
                                    

                
                                
                        
                                    
                                    

                                    gw->getCameraMatrix( mat, &invTM, &persp, &hither, &yon); // getting these values to work with ... see above for their types

                                    float oneOverDepth = 1.0f / (yon - hither);

            

                                        // Set the Direct3D Camera View Position and Camera Projection Transforms.
                                        //
                                        // The first matrix is the full projection transformation matrix that
                                        // converts World Coordinates into NPC.  This means that the matrix is the
                                        // product of the Camera View Position transformation matrix and the Camera
                                        // Projection matrix.  The second matrix is the inverse of the Camera View
                                        // Position transformation matrix so if we multiply this second matrix by
                                        // the first, we get the Camera Projection matrix.  If we take the inverse
                                        // of the second matrix, we get the Camera View Position matrix.
                                        //
                                        // The Camera View Position transformation converts World coordinates into
                                        // Camera View Position coordinates where the camera is located at the
                                        // origin.  We have been given the inverse of the Camera View Position
                                        // matrix so the first step is to take the inverse of this transform to
                                        // obtain the Camera View Position matrix.

                                        // General conversion from 3ds max coords to Direct3D coords:
                                        //
                                        // 3ds max:  (Up, Front, Right) == (+Z, +Y, +X)
                                        //
                                        // Direct3D: (Up, Front, Right) == (+Y, +Z, +X)
                                        //
                                        // Conversion from 3ds max to Direct3D coords:
                                        //
                                        // 3ds max * conversion matrix = Direct3D
                                        //
                                        // [ x y z w ] * | +1  0  0  0 | = [ X Y Z W ]
                                        //               |  0  0 +1  0 |
                                        //               |  0 +1  0  0 |
                                        //               |  0  0  0 +1 |
                                        //
                                        // The View transform below accomplishes this.  The standard View transform
                                        // received makes the rotation about the X axis because the assumption was
                                        // to transform to RH coords with the XY plane being the vertical plane
                                        // instead of the XZ plane.  The negation of the the Z column does the RH
                                        // to LH flip.  Thus, the View transform makes the transition from RH 3ds
                                        // max coords to LH Direct3D coords.


                                    // View Matrix in 3ds max, inverse's inverse to become original [Jacky Luk]
                                    Matrix3 camTM = Inverse(invTM);

        

                                        // We now have an affine matrix (4x3) with no perspective column (it is
                                        // understood to be (0, 0, 0, 1)).  We add the fourth column and flip the
                                        // Z-axis because Direct3D uses a left-handed coordinate system and MAX
                                        // uses a right-handed coordinate system.

                                        // Copy the affine view matrix data


                                int ki, kj;
                                MRow *pcvm = camTM.GetAddr();
                                for (ki = 0; ki < 4; ki++) {
                                    for (kj = 0; kj < 3; kj++) {
                                        d3dViewXform.m[ki][kj] = pcvm[ki][kj];
                                    }
                                }

                                    // Assign the fourth column (perspective terms)

                                d3dViewXform.m[0][3] = d3dViewXform.m[1][3] = d3dViewXform.m[2][3] = 0.0f;
                                d3dViewXform.m[3][3] = 1.0f;

        
                                    // Scale the Z-axis (third column) by -1 to flip to left-handed Direct3D
                                    // coordinate system

                                for (ki = 0; ki < 4; ki++) {
                                    d3dViewXform.m[ki][2] *= -1.0f;
                                }


        
                                        // Calculate the Direct3D Camera Projection transformation matrix.
                                        //
                                        // First, multiply the MAX full projection matrix by the inverse of the MAX
                                        // Camera View Position matrix to obtain the MAX Camera Projection matrix.
                                        //
                                        // This gives us a correct Direct3D Camera Projection matrix except for the
                                        // lower right quadrant.
                                        //

                                    MRow *pa = invTM.GetAddr();
                                    for (ki = 0; ki < 4; ki++) {
                                        float val = (float)(ki==3);
                                        for (kj = 0; kj < 4; kj++) {
                                            d3dProjXform.m[ki][kj] = pa[ki][0] * mat[0][kj] +
                                                pa[ki][1] * mat[1][kj] +
                                                pa[ki][2] * mat[2][kj] +
                                                val         * mat[3][kj];
                                        }
                                    }

        
                                        // Now calculate the lower right quadrant of the Camera Projection matrix
                                        // using the facts that MAX uses an NPC Z-axis range of +1 to -1 whereas
                                        // Direct3D uses an NPC Z-axis range of zero to +1.
                                        //
                                        // For ease of reference, the general forms of the Direct3D Projection
                                        // matrix for perspective and orthographic projections are given below.
                                        //
                                        // Please note that the matrices are specified in row-major order.  This
                                        // means that the translate terms are located in the fourth row and the
                                        // projection terms in the fourth column.  This is consistent with the way
                                        // MAX, Direct3D, and OpenGL all handle matrices.  Even though the OpenGL
                                        // documentation is in column-major form, the OpenGL code is designed to
                                        // handle matrix operations in row-major form.
        
                                    if (persp) {

        
                                        // Perspective projection.  The general form of the Direct3D Camera
                                        // Projection matrix is:
                                        //
                                        // |    2n/(r-l)       0            0            0       |
                                        // |      0          2n/(t-b)       0            0       |
                                        // | (r+l)/(r-l)  (t+b)/(t-b)      f/(f-n)       1       |
                                        // |      0            0         -fn/(f-n)       0       |
                                        //
                                        // Construct the lower right four terms correctly for Direct3D.
                                        //

                                        d3dProjXform.m[2][2] = yon*oneOverDepth;
                                        d3dProjXform.m[2][3] = 1.0f;
                                        d3dProjXform.m[3][2] = -(yon*hither*oneOverDepth);
                                        d3dProjXform.m[3][3] = 0.0f;
        
                                    } else {

        
                                        // Orthographic projection.  The general form of the Direct3D Camera
                                        // Projection matrix is:
                                        //
                                        // |     2/(r-l)       0            0            0       |
                                        // |      0           2/(t-b)       0            0       |
                                        // |      0            0           1/(f-n)       0       |
                                        // | (r+l)/(r-l)  (t+b)/(t-b)     -n/(f-n)       1       |
                                        //
                                        // Construct the lower right four terms correctly for Direct3D.
                                        //

                                        d3dProjXform.m[2][2] = oneOverDepth;
                                        d3dProjXform.m[2][3] = 0.0f;
                                        d3dProjXform.m[3][2] = -(hither*oneOverDepth);
                                        d3dProjXform.m[3][3] = 1.0f;
                                    }


                                    D3DXMATRIX invView;
                                    D3DXMatrixInverse(&invView, NULL, &d3dViewXform);

                                    D3DXVECTOR3 v;
                                    D3DXQUATERNION q;
                                    D3DXVECTOR3 s;

                                    D3DXMatrixDecompose(&s, &q, &v, &invView);
                                    //D3DXVECTOR3 v(d3dViewXform.m[3][0], d3dViewXform.m[3][1], d3dViewXform.m[3][2]);
                                    DOMElement *elem1 = doc->createElement(L"Eye-Pos");


                                    this->SetXYZ(e1, elem1, v);
                        
                        

                                    DOMElement *elem2 = doc->createElement(L"ViewTransformation");
                                    this->SetMatrix(e1, elem2, d3dViewXform);
                                    DOMElement *elem3 = doc->createElement(L"ProjectionTransformation");
                                    this->SetMatrix(e1, elem3, d3dProjXform);

 

Next, I set the Warehouse to 0,0,0 and no rotation at all

and then I set the counter balance to 0,10,0 and no rotation at all, and it sits on the ground level

 

What steps was I doing wrong so that it made the y and z axis pointing in the wrong directions?

Thanks

Jack

                              
                             



#13 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 16 February 2013 - 04:53 AM

Whoops, you can ignore the name, it should be mViewProj



#14 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 16 February 2013 - 04:58 AM

The projection matrix is a little bit scary. The view matrix is normal

 

Attached Thumbnails

  • projmatrix.png
  • viewmatrix.png


#15 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 16 February 2013 - 09:36 PM

Anyone shed some lights on this?

Thanks in advance

Jack



#16 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 17 February 2013 - 10:43 PM

It has been confirmed that the camera conversion process is errant.

 

The exporter exports the warehouse and the counter balance correctly.

With left-handed coordinate system, and the counter balance is currently located at D3DXVECTOR3(0,60,0);

which seems to be correct.

Please look at the previous post for why my cameras are inverted (upside-down)

Thanks

Jack

Attached Thumbnails

  • inverted camera.png
  • max render.png


#17 lucky6969b   Members   -  Reputation: 624

Like
0Likes
Like

Posted 18 February 2013 - 04:42 AM

The camera pos has been converted from e.g. -80,-300,10 to m41 [80] ,m42 [-10] , m43[300], which seems to be correct, the matrix should be the opposite direction of the eye pos, but the application results in a camera looking down from the top

It seems to be a must to flip certain axis in max. But if I do invert the whole scene, the cameras are to be inverted as well. puzzled?!

Attached Thumbnails

  • warehouse.png

Edited by lucky6969b, 18 February 2013 - 05:20 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS