Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cutting a mesh

25 views
Skip to first unread message

James X. Li

unread,
Aug 25, 2005, 1:20:26 PM8/25/05
to
I need to investigate the internal structure of some meshes
which are surfaces like torus or cylinders.
It would be nice if I can clip my mesh alone certain plane.

Does managed DirectX provide a generic way to do this?

The device.Trans.Projection property provide a way to clip any
object, but the clipping planes (i.e the front and back clipping
of the frustum) have fixed angle. I need a clipping plane that
can be rotated in 3D space.

Thanks in advance.

James X. Li

Zman

unread,
Aug 25, 2005, 2:45:19 PM8/25/05
to
Do you just want to clip the rendering? Or do you actually want to make a
new mesh which is clipped by the plane?

For the first one see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/c/renderstatemanager/p/clipping.asp?frame=true
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/s/clipstatus/clipstatus.asp?frame=true
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/e/clipstatusflags/clipstatusflags.asp?frame=true
There are 6 appliction defined clipping planes.
I've never used this but it seems like its what you want. The really odd
thing is that I can't find the API to actually set the user defined clipping
planes. I'm sure I'm just overlooking it and someone else will chime in.

For the second one, nothing in DirectX - do some searches for CSG
operations - there are probbly some libraries out there that can help.

--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX


"James X. Li" <donot...@abc.net> wrote in message
news:O3z7ElZq...@TK2MSFTNGP15.phx.gbl...

James X. Li

unread,
Aug 25, 2005, 9:55:50 PM8/25/05
to
I found that there is a SetClipPlane() method in the C++ API, but
could not find a corresponding method in the MDX API.

Is there a way to call the unmanaged code from the managed code?

James

Zman

unread,
Aug 26, 2005, 3:47:50 AM8/26/05
to
Yes but you don't need to, I found how to do it. There is a ClipPlane
object, so just new up one of those, set up the plane coefficients and then
enable it and put in in the device.ClipPlanes collection.

Oh and I've never seen code with this used so I would love to see an example
if you get it working - drop me an email I'll put it up on The ZBuffer, or
link to your blog.

--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX

"James X. Li" <donot...@abc.net> wrote in message

news:eLeAEFeq...@TK2MSFTNGP09.phx.gbl...

James X. Li

unread,
Aug 28, 2005, 11:02:58 AM8/28/05
to
Thanks for your help. The following is a sample that displays a half
torus.

---------- Cut Here -----------
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Threading;

namespace MeshClip {
public class MeshClip : System.Windows.Forms.Form {
private System.ComponentModel.Container components = null;

private Device device;
private float angle = 0;
private static bool stopFlag = false;
private Manifold manifold;

public MeshClip() {
InitializeComponent();
}

protected override void Dispose( bool disposing ) {
if( disposing ) {
if (components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

private void InitializeComponent() {
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(592, 494);
this.Name = "Form1";
this.Text = "Form1";
this.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);
}
#endregion

[STAThread]
static void Main() {
MeshClip frm = new MeshClip();

frm.InitializeGraphics();
frm.Show();

while (frm.Created) {
if ( ! stopFlag ) {
frm.Render();
}
Application.DoEvents();
Thread.Sleep(25);
}

frm.DisposeGraphics();
}

public void InitializeGraphics() {
PresentParameters pp = new PresentParameters();

pp.Windowed = true;
pp.BackBufferFormat = Format.X8R8G8B8;
pp.SwapEffect = SwapEffect.Discard;
pp.AutoDepthStencilFormat = DepthFormat.D16;
pp.EnableAutoDepthStencil = true;

device = new
Device(0,DeviceType.Hardware,this,CreateFlags.SoftwareVertexProcessing,pp);

device.RenderState.Lighting = true;
device.RenderState.Ambient = Color.Gray;

device.Lights[0].Type = LightType.Directional;
device.Lights[0].Direction = new Vector3(2, 2, -4);
device.Lights[0].Diffuse = Color.FromArgb(0xff, 0xcc, 0x99);
device.Lights[0].Enabled = true;

device.Lights[1].Type = LightType.Directional;
device.Lights[1].Direction = new Vector3(-1, -1, 4);
device.Lights[1].Enabled = true;

device.RenderState.Lighting = true;
device.RenderState.CullMode = Cull.None;

device.Transform.Projection =
Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height,0.2f,
10);
manifold = new Torus(device);
}


public void DisposeGraphics() {
device.Dispose();
}

public void Render() {
device.Clear(ClearFlags.Target |
ClearFlags.ZBuffer,Color.CornflowerBlue ,1,0);

device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-5),new
Vector3(0,0,0),new Vector3(0,1,0));
device.Transform.World =
Matrix.Multiply(Matrix.RotationY(Geometry.DegreeToRadian(angle)),Matrix.RotationX

(Geometry.DegreeToRadian(angle)));
device.Transform.World =
Matrix.Multiply(device.Transform.World,Matrix.RotationZ(Geometry.DegreeToRadian(-angle)));

device.BeginScene();

manifold.Render(device);

angle += 2.0f;
if (angle == 360.0f) {
angle = 0;
}

device.EndScene();
device.Present();
}

private void Form1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e) {
if (e.KeyChar.ToString() == "w") {
if (device.RenderState.FillMode == FillMode.WireFrame) {
device.RenderState.FillMode = FillMode.Solid;
device.RenderState.CullMode = Cull.CounterClockwise;
}
else {
device.RenderState.FillMode = FillMode.WireFrame;
device.RenderState.CullMode = Cull.None;
}
} else if (e.KeyChar.ToString() == "s") {
stopFlag = !stopFlag;
} else if (e.KeyChar.ToString() == "q") {
this.Close();
}
}
}

interface Manifold {
void Render(Device dev);
}

class Torus : Manifold {
Mesh mesh;
Material material;
public Torus(Device dev) {
mesh = Mesh.Torus(dev, 0.5f, 1.0f, 100, 100);
material = new Material();
material.Diffuse = Color.Gray;
}

public void Render(Device dev) {
dev.Material = material;

// Clip out half of the torus.
ClipPlane plane0 = dev.ClipPlanes[0] as ClipPlane;
plane0.Enabled = true;
Vector4 v = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
v.Transform(dev.Transform.World);
plane0.SetSingleArray(new float[]{v.X, v.Y, v.Z, v.W});

mesh.DrawSubset(0);
}
}
}

0 new messages