3DS MAX plugin (2) ry

Source: Internet
Author: User

Start with simple Encounter Geometry

Download

It is quite easy to export the ry.NodeTo obtain the information of the ry.

The main information of the ry concerned is the vertex and triangle surface. Naturally, there are texture coordinates, normal, vertex color, and tangent,BinnormalAnd so on, but these are all things. First, we only care about vertices and faces.

At the same time, another important information is matrix information. Note that in differentFrameThe matrix information may change.

Based on the first example Only a fewCode.

First, we need to determine whether the node contains the body information:

Bool onlygeometry: nodeenum (inode * node, int indent)

{

......

Objectstate OS = node-> evalworldstate (m_ip-> gettime ());

If (OS. OBJ)

{

If (OS. obj-> superclassid () = geomobject_class_id)

{

Exportgeomobject (node, indent );

}

}

For (int c = 0; C <node-> numberofchildren (); C ++ ){

If (! Nodeenum (node-> getchildnode (C), indent + 1 ))

Return false;

}

Return true;

}

Then, in the specific function for exporting the ry, We need to judge again:

Void onlygeometry: exportgeomobject (inode * node, int indent)

{

Timevalue time = m_ip-> gettime ();

Objectstate OS = node-> evalworldstate (time );

If (! OS. OBJ)

Return;

If (OS. obj-> classid () = class_id (target_class_id, 0 ))

Return;

.......................

This is because3DS MAXThere are also many other objects that contain information about the body, such as cameras and lights.TargetPart, so you need to filter it out.

Then we can directly obtain the information we need, first, the matrix: we use

Inode ::Getobjecttmafterwsm ()Come. HereWSMYesWorld Space Modifier. This means that you are usingWorld Space ModifierThe following matrix. AboutWorld Space ModifierFor more information, seeSDKBecause noWorld Space Modifier. So if you useInode: getobjecttm ()The same is true.

 

Matrix3 TM = node-> getobjtmafterwsm (time );

Point3 ROW = TM. getrow (0 );

Fprintf (m_filestream, "% S <% F> \ n", getindent (indent), _ T ("matrix row 0:"), row. x, row. y, row. z );

Row = TM. getrow (1 );

Fprintf (m_filestream, "% S <% F> \ n", getindent (indent), _ T ("matrix row 1:"), row. x, row. y, row. z );

Row = TM. getrow (2 );

Fprintf (m_filestream, "% S <% F> \ n", getindent (indent), _ T ("matrix row 2:"), row. x, row. y, row. z );

Row = TM. getrow (3 );

Fprintf (m_filestream, "% S <% F> \ n", getindent (indent), _ T ("matrix row 3:"), row. x, row. y, row. z );

 

The next step is to export the vertex and triangle.MaxThe node in is not saved directly.MeshIf you want to obtainMeshFirstObjectConvertMeshAnd thenMeshObtain specific information:

Triobject * triobj = 0;

Triobj = (triobject *) OS. obj-> converttotype (time, class_id (triobj_class_id, 0 ));

HereMaxIt is actuallyDeep copySo we can release the memory after the conversion is complete.

If (triobj! = OS. OBJ) // deep copy

{

Mesh * mesh = & (triobj-> getmesh ());

If (mesh)

{

Mesh-> buildnormals ();

Fprintf (m_filestream, "% S % s \ n", getindent (indent), _ T ("Geometry Data :"));

Fprintf (m_filestream, "% S % d \ n", getindent (indent + 1), _ T ("vertex number :"), mesh-> getnumverts (), _ T ("Face Number:"), mesh-> getnumfaces ());

//Vertex Information

For (INT I = 0; I <mesh-> getnumverts (); ++ I)

{

Point3 vert = TM * mesh-> Verts [I];

Fprintf (m_filestream, "% s vertex % d: <% F, % F, % F> \ n", getindent (indent), I, vert. x, vert. y, vert. z );

}

//Surface Information

For (INT I = 0; I <mesh-> getnumfaces (); I ++)

{

Fprintf (m_filestream, "% s face % d -- verts: <% d, % d, % d> edgevis: <% d, % d, % d> smoothgrp: <0x % x> matid: <% d> \ n ",

Getindent (indent ),

I,

Mesh-> faces [I]. V [0],

Mesh-> faces [I]. V [1],

Mesh-> faces [I]. V [2],

Mesh-> faces [I]. getedgevis (0 )? 1: 0,

Mesh-> faces [I]. getedgevis (1 )? 1: 0,

Mesh-> faces [I]. getedgevis (2 )? 1: 0,

Mesh-> faces [I]. getsmgroup (),

Mesh-> faces [I]. getmatid ());

}

}

}

Delete triobj;

Fprintf (m_filestream, "% S % s \ n", getindent (indent), _ T ("Geometry end "));

Fprintf (m_filestream, "\ n ");

}

 

So far, our preliminary ExportGeometryYou can openMaxTry it. The output simple file is as follows:

Begin do Header

 

Begin do nodes

Totoal node number: 3

Root name: Scene Root

Node name: box01

Matrix row 0: <1.000000 0.000000 0.000000>

Matrix row 1: <0.000000 1.000000 0.000000>

Matrix row 2: <0.000000 0.000000 1.000000>

Matrix row 3: <-19.448299-3.523636 0.000000>

Geometry Data:

Vertex number: 8 face number: 12

Vertex 0: <-40.204018,-28.128052, 0.000000>

Vertex 1: <1.307419,-28.128052, 0.000000>

Vertex 2: <-40.204018, 21.080780, 0.000000>

Vertex 3: <1.307419, 21.080780, 0.000000>

Vertex 4: <-40.204018,-28.128052, 24.273842>

Vertex 5: <1.307419,-28.128052, 24.273842>

 Vertex 6: <-40.204018, 21.080780, 24.273842>

Vertex 7: <1.307419, 21.080780, 24.273842>

Face 0 -- verts: <0, 2, 3> edgevis: <1, 1, 0> smoothgrp: <0x2> matid: <1>

Face 1 -- verts: <3, 1, 0> edgevis: <1, 1, 0> smoothgrp: <0x2> matid: <1>

Face 2 -- verts: <4, 5, 7> edgevis: <1, 1, 0> smoothgrp: <0x4> matid: <0>

Face 3 -- verts: <7, 6, 4> edgevis: <1, 1, 0> smoothgrp: <0x4> matid: <0>

Face 4 -- verts: <, 5> edgevis: <, 0> smoothgrp: <0x8> matid: <4>

Face 5 -- verts: <5, 4, 0> edgevis: <1, 1, 0> smoothgrp: <0x8> matid: <4>

Face 6 -- verts: <1, 3, 7> edgevis: <1, 1, 0> smoothgrp: <0x10> matid: <3>

Face 7 -- verts: <7, 5, 1> edgevis: <1, 1, 0> smoothgrp: <0x10> matid: <3>

Face 8 -- verts: <3, 2, 6> edgevis: <1, 1, 0> smoothgrp: <0x20> matid: <5>

Face 9 -- verts: <6, 7, 3> edgevis: <1, 1, 0> smoothgrp: <0x20> matid: <5>

Face 10 -- verts: <2, 0, 4> edgevis: <1, 1, 0> smoothgrp: <0x40> matid: <2>

Face 11 -- verts: <4, 6, 2> edgevis: <1, 1, 0> smoothgrp: <0x40> matid: <2>

Geometry end

 

Node name: pyramid01

Matrix row 0: <1.000000 0.000000 0.000000>

Matrix row 1: <0.000000 1.000000 0.000000>

Matrix row 2: <0.000000 0.000000 1.000000>

Matrix row 3: <24.578979-52.777748 0.005000>

Geometry Data:

Vertex number: 6 face number: 8

Vertex 0: <24.578979,-52.777748, 43.850536>

Vertex 1: <-1.593857,-72.522881, 0.005000>

Vertex 2: <50.751816,-72.522881, 0.005000>

Vertex 3: <50.751816,-33.032616, 0.005000>

Vertex 4: <-1.593857,-33.032616, 0.005000>

Vertex 5: <24.578979,-52.777748, 0.005000>

Face 0 -- verts: <0, 1> edgevis: <1, 1> smoothgrp: <0x4> matid: <0>

Face 1 -- verts: <0, 2, 3> edgevis: <1, 1> smoothgrp: <0x2> matid: <0>

Face 2 -- verts: <0, 3, 4> edgevis: <1, 1> smoothgrp: <0x10> matid: <0>

Face 3 -- verts: <0, 4, 1> edgevis: <1, 1> smoothgrp: <0x20> matid: <0>

Face 4 -- verts: <, 2> edgevis: <, 1> smoothgrp: <0x8> matid: <0>

Face 5 -- verts: <2, 5, 3> edgevis: <1, 1> smoothgrp: <0x8> matid: <0>

Face 6 -- verts: <3, 5, 4> edgevis: <1, 1> smoothgrp: <0x8> matid: <0>

Face 7 -- verts: <4, 5, 1> edgevis: <1, 1> smoothgrp: <0x8> matid: <0>

Geometry end

 

Node name: box02

Matrix row 0: <1.000000 0.000000 0.000000>

Matrix row 1: <0.000000 1.000000 0.000000>

Matrix row 2: <0.000000 0.000000 1.000000>

Matrix row 3: <128.516830 57.409515 0.000000>

Geometry Data:

Vertex number: 8 face number: 12

Vertex 0: <111.216064, 37.396194, 0.000000>

Vertex 1: <145.817596, 37.396194, 0.000000>

Vertex 2: <111.216064, 77.422836, 0.000000>

Vertex 3: <145.817596, 77.422836, 0.000000>

Vertex 4: <111.216064, 37.396194,-40.238293>

Vertex 5: <145.817596, 37.396194,-40.238293>

Vertex 6: <111.216064, 77.422836,-40.238293>

Vertex 7: <145.817596, 77.422836,-40.238293>

Face 0 -- verts: <2, 0, 3> edgevis: <1, 0, 1> smoothgrp: <0x2> matid:

Face 1 -- verts: <1, 3, 0> edgevis: <1, 0, 1> smoothgrp: <0x2> matid: <0>

Face 2 -- verts: <5, 4, 7> edgevis: <1, 0, 1> smoothgrp: <0x4> matid: <1>

Face 3 -- verts: <6, 7, 4> edgevis: <1, 0, 1> smoothgrp: <0x4> matid: <1>

Face 4 -- verts: <1, 0, 5> edgevis: <1, 0, 1> smoothgrp: <0x8> matid: <4>

Face 5 -- verts: <4, 5, 0> edgevis: <1, 0, 1> smoothgrp: <0x8> matid: <4>

Face 6 -- verts: <3, 1, 7> edgevis: <1, 0, 1> smoothgrp: <0x10> matid: <3>

Face 7 -- verts: <5, 7, 1> edgevis: <1, 0, 1> smoothgrp: <0x10> matid: <3>

Face 8 -- verts: <2, 3, 6> edgevis: <1, 0, 1> smoothgrp: <0x20> matid: <5>

Face 9 -- verts: <7, 6, 3> edgevis: <1, 0, 1> smoothgrp: <0x20> matid: <5>

Face 10 -- verts: <, 4> edgevis: <, 1> smoothgrp: <0x40> matid: <2>

Face 11 -- verts: <6, 4, 2> edgevis: <1, 0, 1> smoothgrp: <0x40> matid: <2>

Geometry end

 

end myexporter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.