0

AutoCAD に組み込まれているアプリケーションの 3D パーツ プレビューアに取り組んでいます。

3D は、SlimDX (2.0 バージョン) 経由で DirectX を使用して実装されます。

.NET Framework 3.5 を使用しています

次のコードは、DirectX デバイスを初期化します

foreach (var item in ObjectTable.Objects)
    item.Dispose();

_presentParameters = new PresentParameters()
    {
        BackBufferFormat = Format.Unknown,
        SwapEffect = SwapEffect.Discard,

        BackBufferWidth = 1500,
        BackBufferHeight = 1500,

        EnableAutoDepthStencil = true,

        AutoDepthStencilFormat = Format.D16,
        PresentationInterval = PresentInterval.Immediate
    };

_device = new Device(new Direct3D(), 0, DeviceType.Hardware, preview3DTarget.Handle, CreateFlags.HardwareVertexProcessing, _presentParameters);

_device.SetRenderState(RenderState.ZEnable, true);
_device.SetRenderState(RenderState.Lighting, false);
_device.SetRenderState(RenderState.CullMode, Cull.None);  

次のコードは、コントロールの OnPaint メソッドから呼び出され、プレビューをレンダリングします。

_device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

_device.BeginScene();

float ratio = (float)preview3DTarget.ClientSize.Width / preview3DTarget.ClientSize.Height;

_device.SetTransform(TransformState.Projection, Matrix.OrthoLH(200, 200, 0.0f, 200.0f));

_device.SetTransform(TransformState.World, Matrix.Translation(-center.X, -center.Y, -center.Z));

_device.SetTransform(TransformState.View, Matrix.RotationYawPitchRoll(Math.radians(0),
                                    Math.radians(0), 0.0f) *
                                    Matrix.Translation(0f, 0f, 100));

for (int i = 0; i < this.vertices.Count; i += 4)
{
    _device.DrawPrimitives(PrimitiveType.TriangleStrip, i, 2);
}


for (int i = 0; i < this.points.Count; i += 5)
{
    _device.DrawPrimitives(PrimitiveType.LineStrip, i + this.vertices.Count, 4);
}

_device.EndScene();

_device.Present();

このコードはすべて正しく機能しますが、最初にプレビューがレンダリングされた後、AutoCAD は正しく機能しなくなります。AutoCAD モデル空間内のオブジェクトは選択できません。REGEN が呼び出された場合、画面はクリアされ、何も再描画されません。新しいオブジェクトを描画すると表示されますが、既存のオブジェクトと同様に選択できません。

私のアプリケーションが何らかの形で DirectX エンジンの制御を乗っ取り、AutoCAD がそれを使用するのを止めているのではないかと推測しています。私のアプリケーションと AutoCAD が同時に DirectX を使用できるようにするために、私が見逃しているある種のリリース/ディスポーズ コールはありますか?

4

1 に答える 1

0

しばらく前に同様の問題がありましたが、解決策が見つかりませんでした。DirectX 側でマルチスレッドを有効にしようとしましたか?

AutoCAD グラフィックス システムを使用してモデルを画面外にレンダリングすることもできます: through-the-interface.typepad.com/through_the_interface/2007/04/rendering_autoc.html

于 2012-06-09T08:48:13.673 に答える