"Original" DX graphic display basic process (based on MESH static model drawing ---- hosting code)

xiaoxiao2021-03-05  53

Fengye - Published in - 2005030509514603MESH to get a Mesh.FromFile method. Of course it has a lot of overload.

Generally use Public Static Mesh fromfile (String, Meshflags, Device, Out ExtendedMaterial); method. It should be noted that the read of Mesh is later in the initial D3D device. D3D devices are required in the initial method of Mesh, and the MESH drawing is also used in the future.

Set a general display attribute in the initialization of the D3D device, such as: depth test, multiple sample, light rendering switch, and so on.

PresentParameters Presentparams = New Presentparameters ();

Presentparams.windowed = true;

Presentparams.swaPeffect = swapeffect.discard;

Presentparams.enableAutodepthstencil = true;

Presentparams.autodepthstencilFormat = depthformat.d16;

Presentparams.MultiSample = MultiSampleType.nonmaskable;

MyDev = New Device (0, DeviceType.hardware, this, createflags.hardwarevertexprocessing, presentparams);

Mydev.renderstate.multiSampleantialias = true;

Mydev.renderstate.lighting = true;

Mydev.renderstate.cullmode = Cull.none;

Mydev.renderstate.zbufferenable = true;

Mydev.renderstate.zbufferfunction = compare.lesequal;

Mydev.renderstate.zbufferwriteenable = true;

Mydev.renderstate.Ambient = matcolor;

PresentParameters Presentparams = New Presentparameters ();

Presentparams.windowed = true;

Presentparams.swaPeffect = swapeffect.discard;

Presentparams.enableAutodepthstencil = true;

Presentparams.autodepthstencilFormat = depthformat.d16;

Presentparams.MultiSample = MultiSampleType.nonmaskable;

MyDev = New Device (0, DeviceType.hardware, this, createflags.hardwarevertexprocessing, presentparams);

Mydev.renderstate.multiSampleantialias = true;

Mydev.renderstate.lighting = true;

Mydev.renderstate.cullmode = Cull.none;

Mydev.renderstate.zbufferenable = true;

Mydev.renderstate.zbufferfunction = compare.lesequal;

Mydev.renderstate.zbufferwriteenable = true; mydev.renderstate.Ambient = matcolor;

For the settings of the light, it can be adjusted within the per detective dye function as needed, or the fixed light can be placed before drawing.

Generally draw a MESH, each model block uses the same world matrix. Set WORLDMATRIX before drawing Mesh. Sometimes there is too much in a scene, while some Mesh integrates an object, adjusting WorldMatrix can be very troublesome for each Mesh. Therefore, it is best to adjust the coordinates of these Mesh according to the corresponding relative coordinates, which will then use the same worldmatrix. Before modifying the Mesh vertex data, you can use Mesh.clone to copy a Mesh that controls the vertex data format.

Public Mesh Clone (Meshflags, VertexFormats, Device);

Depending on the VertexFormats format you need, you can easily modify the vertex data. Of course, don't forget the data stream you want to modify before modifying.

For the materials and textures contained in Mesh, you need you to manually adjust. In the Mesh's fromFile, an OUT has already an extendedMaterial group containing texture.

We must declare a material group, a texture group.

Texture [] Meshtextures = New Texture [Materials.Length];

Material [] meshmaterials = new direct3d.material [matials.length];

After the material and texture are separated.

For (int i = 0; i

{

Meshmaterials [i] = matials [i] .material3d;

// set the Ambient color for the massage. Direct3D

// does not do this by default.

Meshmaterials [i] .ambient = meshmaterials [i] .diffuse;

// CREATE The texture.

Meshtextures [i] = textureloader.fromfile (dev, matials [i] .texturefilename);

}

Now we can draw mesh.

For (int i = 0; i

{

// set the massial and texture for this subset.

Device.material = meshmaterials [i];

Device.Settexture (0, Meshtextures [i]);

// Draw the mesh subs.

Mesh.drawsubset (i);

}

Don't forget Device.Endscene (); device.Present ();

At the beginning of the D3D device, we launched a tested test, so when drawing each detection, call the CLEAR function, one to clean up the depth buffer, otherwise the draw will be confused.

The above is the basic MESH static model drawn. For other high-level effects, write it later.

转载请注明原文地址:https://www.9cbs.com/read-36639.html

New Post(0)