2 wslzj2003 wslzj2003 于 2014.08.25 18:34 提问

Viewport3D 导入3d信息 的时候报错,但是可以运行。

问题:我把3d图形转成xaml,拷贝进来之后,发现会报错误,但是点击运行,可以运行,我测试过,如果把

 <DiffuseMaterial >
                                                        <DiffuseMaterial.Brush >
                                                            <SolidColorBrush Color="#B2B200" Opacity="1.000000"/>
                                                        </DiffuseMaterial.Brush>
                                                    </DiffuseMaterial>

删除掉,就不会报错。不知道是什么原因。

报错内容如下
**引发异常 **

NullReferenceException: 未将对象引用设置到对象的实例。

InnerException: 无
StackTrace
在 Microsoft.Expression.DesignSurface.View.XamlHitTestHelper.WalkHitTestPath(Viewport3D rootViewport, ViewNode currentViewNode, List1 path)
在 Microsoft.Expression.DesignSurface.View.XamlHitTestHelper.Record3DHitTestResult(Viewport3D rootViewport, RectangleHitTestResult summary)
在 Microsoft.Expression.DesignSurface.View.XamlHitTestHelper.FilterPotentialHit(IViewObject viewObject, IParentChainProvider parentChain)
在 Microsoft.Expression.WpfPlatform.ViewObjects.WpfViewVisual.HitTestFilterCallback(DependencyObject potentialHitTestTarget)
在 System.Windows.Media.Visual.HitTestPoint(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, PointHitTestParameters pointParams)
在 System.Windows.Media.Visual.HitTestPoint(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, PointHitTestParameters pointParams)
在 System.Windows.Media.Visual.HitTestPoint(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, PointHitTestParameters pointParams)
在 System.Windows.Media.Visual.HitTestPoint(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, PointHitTestParameters pointParams)
在 System.Windows.Media.Visual.HitTestPoint(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, PointHitTestParameters pointParams)
在 System.Windows.Media.Visual.HitTestPoint(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, PointHitTestParameters pointParams)
在 System.Windows.Media.Visual.HitTestPoint(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, PointHitTestParameters pointParams)
在 System.Windows.Media.Visual.HitTestPoint(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, PointHitTestParameters pointParams)
在 System.Windows.Media.Visual.HitTestPoint(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, PointHitTestParameters pointParams)
在 System.Windows.Media.Visual.HitTest(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, HitTestParameters hitTestParameters)
在 System.Windows.Media.VisualTreeHelper.HitTest(Visual reference, HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, HitTestParameters hitTestParameters)
在 Microsoft.Expression.WpfPlatform.ViewObjects.WpfViewVisual.HitTest(ViewHitTestFilterCallback filterCallback, ViewHitTestResultCallback resultCallback, HitTestParameters hitTestParameters, List
1& invisibleHits)
在 Microsoft.Expression.DesignSurface.View.XamlHitTestHelper.PerformHitTest(HitTestParameters hitTestParameters, HitTestModifier hitTestModifier, InvisibleObjectHitTestModifier invisibleObjectHitTestModifier, ICollection1 ignoredElements, Boolean stopAfterFirstHit, Boolean skipFullyContainedSelectionInObject, ViewHitTestFilterCallback filterCallback)
在 Microsoft.Expression.DesignSurface.View.XamlSceneView.GetElementAtPoint(Point point, HitTestModifier hitTestModifier, InvisibleObjectHitTestModifier invisibleObjectHitTestModifier, ICollection
1 ignoredElements)
在 Microsoft.Expression.DesignSurface.View.XamlSceneView.HitElementHelper.GetSelectableElementAtPoint(Point point)
在 Microsoft.Expression.DesignSurface.View.XamlSceneView.GetSelectableElementAtPoint(Point point, SelectionFor3D selectionFor3D, Boolean selectedOnly, Boolean smartInvisiblePanelSelect)
在 Microsoft.Expression.DesignSurface.View.SceneView.GetCachedSelectableElementAtPoint(Point point, SelectionFor3D selectionFor3D)
在 Microsoft.Expression.DesignSurface.Tools.ToolBehavior.CachedHitTest(Point pointerPosition)
在 Microsoft.Expression.DesignSurface.Tools.Selection.ElementEditorBehavior.OnHoverOverNonAdorner(Point pointerPosition)
在 Microsoft.Expression.DesignSurface.Tools.ElementToolBehavior.OnHover(Point pointerPosition)
在 Microsoft.Expression.DesignSurface.Tools.EventRouter.ScopeElement_MouseMove(Object sender, MouseEventArgs args)
在 System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
在 System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
在 System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
在 System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
在 System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
在 System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
在 System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
在 System.Windows.Input.InputManager.ProcessStagingArea()
在 System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
在 System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
在 System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
在 System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

下面这个是源代码:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="596.269" Width="1025">
<Grid>
      <Viewport3D >
            <Viewport3D.Camera>
                <OrthographicCamera Position="0.005436,0.006462,0.004638" LookDirection="-0.577382,-0.577288,-0.577382" UpDirection="-0.408204,0.816541,-0.408204" NearPlaneDistance="0.003497" FarPlaneDistance="0.010491" Width="0.026994"/>
            </Viewport3D.Camera>
            <Viewport3D.Children>
                <ModelVisual3D >
                    <ModelVisual3D.Transform>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D Angle="0" Axis="0,1,0"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                    </ModelVisual3D.Transform>
                    <ModelVisual3D.Children>
                        <ModelVisual3D>
                            <ModelVisual3D.Content>
                                <Model3DGroup x:Name="test">
                                    <Model3DGroup.Children>
                                        <AmbientLight Color="#262626"/>
                                        <DirectionalLight Color="#6F6F6F" Direction="3.150000,-8.090000,-4.960000"/>
                                        <DirectionalLight Color="#454545" Direction="8.610000,4.820000,-1.640000"/>
                                        <DirectionalLight Color="#332835" Direction="-9.490000,3.090000,0.600000"/>
                                    </Model3DGroup.Children>
                                </Model3DGroup>
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                        <ModelVisual3D>
                            <ModelVisual3D.Transform>
                                <MatrixTransform3D Matrix="1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 "/>
                            </ModelVisual3D.Transform>
                            <ModelVisual3D.Content>
                                <Model3DGroup>
                                    <Model3DGroup.Children>



                                        <GeometryModel3D>
                                            <GeometryModel3D.Material  >
                                                <MaterialGroup>
                                                    <DiffuseMaterial >
                                                        <DiffuseMaterial.Brush >
                                                            <SolidColorBrush Color="#B2B200" Opacity="1.000000"/>
                                                        </DiffuseMaterial.Brush>
                                                    </DiffuseMaterial>
                                                    <SpecularMaterial  SpecularPower="0.200000">
                                                        <SpecularMaterial.Brush >
                                                            <SolidColorBrush Color="#333300" Opacity="1.000000"/>
                                                        </SpecularMaterial.Brush>
                                                    </SpecularMaterial>
                                                </MaterialGroup>
                                            </GeometryModel3D.Material>
                                            <GeometryModel3D.Geometry>
                                                <MeshGeometry3D Positions="0.000817,-0.000042,0.000578 0.000817,-0.000044,0.000577 0.000188,-0.000044,0.000577 0.000814,-0.000025,0.000599 0.000813,-0.000025,0.000598 0.000188,-0.000027,0.000594 0.000814,-0.000027,0.000595 0.000814,-0.000025,0.000599 0.000188,-0.000027,0.000594 0.000814,-0.000026,0.000600 0.000188,-0.000026,0.000600 0.000814,-0.000026,0.000601 0.000188,-0.000027,0.000606 0.000814,-0.000027,0.000606 0.000815,-0.000029,0.000612 0.000814,-0.000027,0.000606 0.000188,-0.000029,0.000612 0.000188,-0.000029,0.000612 0.000814,-0.000027,0.000606 0.000188,-0.000027,0.000606 0.000814,-0.000027,0.000606 0.000814,-0.000027,0.000606 0.000815,-0.000033,0.000616 0.000815,-0.000029,0.000612 0.000188,-0.000029,0.000612 0.000815,-0.000029,0.000612 0.000815,-0.000029,0.000612 0.000815,-0.000033,0.000616 0.000188,-0.000029,0.000612 0.000815,-0.000033,0.000617 0.000188,-0.000033,0.000617 0.000816,-0.000037,0.000620 0.000816,-0.000037,0.000620 0.000188,-0.000033,0.000617 0.000816,-0.000038,0.000620 0.000188,-0.000038,0.000621 0.000817,-0.000042,0.000622 0.000817,-0.000042,0.000622 0.000188,-0.000038,0.000621 0.000817,-0.000044,0.000623 0.000188,-0.000044,0.000623 0.000818,-0.000048,0.000624 0.000819,-0.000054,0.000623 0.000819,-0.000054,0.000623 0.000188,-0.000050,0.000624 0.000818,-0.000050,0.000624 0.000188,-0.000044,0.000623 0.000818,-0.000048,0.000624 0.000818,-0.000048,0.000624 0.000819,-0.000054,0.000623 0.000188,-0.000050,0.000624 0.000820,-0.000056,0.000623 0.000188,-0.000056,0.000623 0.000820,-0.000059,0.000622 0.000821,-0.000066,0.000618 0.000821,-0.000065,0.000619 0.000188,-0.000062,0.000621 0.000821,-0.000062,0.000620 0.000188,-0.000056,0.000623 0.000820,-0.000060,0.000621 0.000820,-0.000059,0.000622 0.000821,-0.000066,0.000618 0.000188,-0.000062,0.000621 0.000822,-0.000067,0.000617 0.000188,-0.000067,0.000617 0.000822,-0.000069,0.000614 0.000823,-0.000073,0.000607 0.000823,-0.000072,0.000609 0.000188,-0.000070,0.000612 0.000822,-0.000070,0.000612 0.000188,-0.000067,0.000617 0.000822,-0.000070,0.000613 0.000822,-0.000069,0.000614 0.000823,-0.000073,0.000607 0.000188,-0.000070,0.000612 0.000823,-0.000073,0.000606 0.000188,-0.000073,0.000606 0.000823,-0.000073,0.000604 0.000188,-0.000074,0.000600 0.000823,-0.000073,0.000600 0.000823,-0.000073,0.000600 0.000188,-0.000074,0.000600 0.000823,-0.000074,0.000598 0.000188,-0.000073,0.000594 0.000823,-0.000073,0.000594 0.000822,-0.000070,0.000588 0.000822,-0.000070,0.000588 0.000188,-0.000070,0.000588 0.000823,-0.000073,0.000593 0.000188,-0.000073,0.000594 0.000823,-0.000073,0.000593 0.000823,-0.000073,0.000594 0.000188,-0.000067,0.000583 0.000822,-0.000067,0.000583 0.000822,-0.000067,0.000584 0.000188,-0.000067,0.000583 0.000822,-0.000067,0.000584 0.000188,-0.000070,0.000588 0.000822,-0.000070,0.000587 0.000822,-0.000070,0.000588 0.000820,-0.000060,0.000579 0.000821,-0.000062,0.000580 0.000188,-0.000062,0.000579 0.000821,-0.000063,0.000580 0.000188,-0.000067,0.000583 0.000821,-0.000066,0.000582 0.000822,-0.000067,0.000583 0.000820,-0.000060,0.000579 0.000188,-0.000062,0.000579 0.000820,-0.000059,0.000578 0.000188,-0.000056,0.000577 0.000820,-0.000056,0.000577 0.000818,-0.000048,0.000576 0.000818,-0.000050,0.000576 0.000188,-0.000050,0.000576 0.000819,-0.000053,0.000576 0.000188,-0.000056,0.000577 0.000819,-0.000054,0.000577 0.000820,-0.000056,0.000577 0.000188,-0.000044,0.000577 0.000817,-0.000044,0.000577 0.000188,-0.000050,0.000576 0.000818,-0.000047,0.000576 0.000818,-0.000048,0.000576 0.000816,-0.000036,0.000581 0.000188,-0.000038,0.000579 0.000815,-0.000033,0.000583 0.000188,-0.000033,0.000583 0.000815,-0.000032,0.000584 0.000816,-0.000036,0.000581 0.000816,-0.000037,0.000580 0.000188,-0.000038,0.000579 0.000816,-0.000038,0.000580 0.000188,-0.000044,0.000577 0.000817,-0.000041,0.000578 0.000817,-0.000042,0.000578 0.000814,-0.000027,0.000595 0.000814,-0.000027,0.000595 0.000188,-0.000027,0.000594 0.000814,-0.000027,0.000594 0.000188,-0.000029,0.000588 0.000814,-0.000029,0.000589 0.000814,-0.000029,0.000589 0.000814,-0.000029,0.000589 0.000188,-0.000029,0.000588 0.000815,-0.000029,0.000588 0.000188,-0.000033,0.000583 0.000815,-0.000032,0.000585 0.000815,-0.000032,0.000584 " Normals="0.000000,0.324785,-0.945788 0.000000,0.258958,-0.965888 -0.000000,0.258819,-0.965926 0.000000,0.999144,-0.041376 0.000000,0.995952,-0.089886 -0.000000,0.965926,-0.258819 0.000000,0.973540,-0.228516 0.000000,0.999144,-0.041376 -0.000000,0.965926,-0.258819 0.000000,0.999988,0.004995 -0.000000,1.000000,0.000000 0.000000,0.999187,0.040327 -0.000000,0.965926,0.258819 0.000000,0.965891,0.258948 0.000000,0.871407,0.490560 0.000000,0.962878,0.269937 -0.000000,0.866025,0.500000 -0.000000,0.866025,0.500000 0.000000,0.962878,0.269937 -0.000000,0.965926,0.258819 0.000000,0.965605,0.260012 0.000000,0.965891,0.258948 0.000000,0.731616,0.681717 0.000000,0.866071,0.499922 -0.000000,0.866025,0.500000 0.000000,0.869669,0.493635 0.000000,0.871407,0.490560 0.000000,0.731616,0.681717 -0.000000,0.866025,0.500000 0.000000,0.707338,0.706875 -0.000000,0.707107,0.707107 0.000000,0.542720,0.839914 0.000000,0.542720,0.839914 -0.000000,0.707107,0.707107 0.000000,0.500288,0.865859 -0.000000,0.500000,0.866025 0.000000,0.327009,0.945021 0.000000,0.327009,0.945021 -0.000000,0.500000,0.866025 0.000000,0.259136,0.965841 -0.000000,0.258819,0.965926 0.000000,0.085261,0.996359 0.000000,-0.184039,0.982919 0.000000,-0.158100,0.987423 0.000000,-0.000000,1.000000 0.000000,0.000247,1.000000 -0.000000,0.258819,0.965926 0.000000,0.075910,0.997115 0.000000,0.085261,0.996359 0.000000,-0.184039,0.982919 0.000000,-0.000000,1.000000 0.000000,-0.258642,0.965973 0.000000,-0.258819,0.965926 0.000000,-0.400821,0.916157 0.000000,-0.662570,0.749000 0.000000,-0.617176,0.786825 0.000000,-0.500000,0.866025 0.000000,-0.499897,0.866085 0.000000,-0.258819,0.965926 0.000000,-0.436483,0.899713 0.000000,-0.400821,0.916157 0.000000,-0.662570,0.749000 0.000000,-0.500000,0.866025 0.000000,-0.707078,0.707136 0.000000,-0.707107,0.707107 0.000000,-0.793275,0.608864 0.000000,-0.959457,0.281856 0.000000,-0.920263,0.391301 0.000000,-0.866025,0.500000 0.000000,-0.866044,0.499967 0.000000,-0.707107,0.707107 0.000000,-0.842683,0.538410 0.000000,-0.793275,0.608864 0.000000,-0.959457,0.281856 0.000000,-0.866025,0.500000 0.000000,-0.965967,0.258664 0.000000,-0.965926,0.258819 0.000000,-0.985134,0.171789 0.000000,-1.000000,0.000000 0.000000,-1.000000,-0.000308 0.000000,-1.000000,-0.000308 0.000000,-1.000000,0.000000 0.000000,-0.997691,-0.067920 0.000000,-0.965926,-0.258819 0.000000,-0.965847,-0.259115 0.000000,-0.864661,-0.502355 0.000000,-0.866009,-0.500028 0.000000,-0.866025,-0.500000 0.000000,-0.954367,-0.298636 0.000000,-0.965926,-0.258819 0.000000,-0.959226,-0.282642 0.000000,-0.965847,-0.259115 0.000000,-0.707107,-0.707107 0.000000,-0.707254,-0.706959 0.000000,-0.728183,-0.685383 0.000000,-0.707107,-0.707107 0.000000,-0.728183,-0.685383 0.000000,-0.866025,-0.500000 0.000000,-0.844017,-0.536317 0.000000,-0.864661,-0.502355 0.000000,-0.439127,-0.898425 0.000000,-0.500179,-0.865922 0.000000,-0.500000,-0.866025 0.000000,-0.567153,-0.823613 0.000000,-0.707107,-0.707107 0.000000,-0.665029,-0.746818 0.000000,-0.707254,-0.706959 0.000000,-0.439127,-0.898425 0.000000,-0.500000,-0.866025 0.000000,-0.365459,-0.930827 0.000000,-0.258819,-0.965926 0.000000,-0.258893,-0.965906 0.000000,0.073242,-0.997314 0.000000,0.000045,-1.000000 -0.000000,0.000000,-1.000000 0.000000,-0.128553,-0.991703 0.000000,-0.258819,-0.965926 0.000000,-0.186576,-0.982440 0.000000,-0.258893,-0.965906 -0.000000,0.258819,-0.965926 0.000000,0.258958,-0.965888 -0.000000,0.000000,-1.000000 0.000000,0.116662,-0.993172 0.000000,0.073242,-0.997314 0.000000,0.581704,-0.813401 -0.000000,0.500000,-0.866025 0.000000,0.707303,-0.706910 -0.000000,0.707107,-0.707107 0.000000,0.741925,-0.670483 0.000000,0.581704,-0.813401 0.000000,0.551921,-0.833896 -0.000000,0.500000,-0.866025 0.000000,0.500184,-0.865919 -0.000000,0.258819,-0.965926 0.000000,0.361162,-0.932503 0.000000,0.324785,-0.945788 0.000000,0.973540,-0.228516 0.000000,0.972771,-0.231770 -0.000000,0.965926,-0.258819 0.000000,0.965994,-0.258563 -0.000000,0.866025,-0.500000 0.000000,0.894912,-0.446243 0.000000,0.894912,-0.446243 0.000000,0.884866,-0.465845 -0.000000,0.866025,-0.500000 0.000000,0.866181,-0.499730 -0.000000,0.707107,-0.707107 0.000000,0.764656,-0.644439 0.000000,0.741925,-0.670483 " TriangleIndices="0,1,2 3,4,5 6,5,4 7,8,9 10,9,8 9,10,11 12,11,10 11,12,13 14,15,16 17,18,19 20,19,18 19,20,21 22,23,24 25,24,23 24,25,26 27,28,29 30,29,28 29,30,31 32,33,34 35,34,33 34,35,36 37,38,39 40,39,38 39,40,41 42,43,44 45,44,43 44,45,46 47,46,45 46,47,48 49,50,51 52,51,50 51,52,53 54,55,56 57,56,55 56,57,58 59,58,57 58,59,60 61,62,63 64,63,62 63,64,65 66,67,68 69,68,67 68,69,70 71,70,69 70,71,72 73,74,75 76,75,74 75,76,77 78,77,76 77,78,79 80,81,82 83,82,81 82,83,84 85,86,87 88,87,86 87,88,89 90,89,88 89,90,91 92,93,94 95,96,97 98,97,96 97,98,99 100,101,102 103,102,101 102,103,104 105,104,103 104,105,106 107,108,109 110,109,108 109,110,111 112,113,114 115,114,113 114,115,116 117,116,115 116,117,118 119,120,121 122,121,120 121,122,123 124,125,126 127,126,125 126,127,128 129,130,131 132,131,130 131,132,133 134,133,132 133,134,135 136,137,138 139,138,137 138,139,140 141,140,139 142,143,144 145,144,143 144,145,146 147,146,145 146,147,148 "/>
                                            </GeometryModel3D.Geometry>
                                        </GeometryModel3D>






                                    </Model3DGroup.Children>
                                </Model3DGroup>
                            </ModelVisual3D.Content>
                            <ModelVisual3D.Children/>
                        </ModelVisual3D>
                    </ModelVisual3D.Children>
                </ModelVisual3D>
            </Viewport3D.Children>
        </Viewport3D>

</Grid>

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!