标签:
原文:WPF动态加载3D 放大-旋转-平移
WavefrontObjLoader.cs
第二步:ModelVisual3DWithName.cs
public class ModelVisual3DWithName:ModelVisual3D
{
public string Name { get; set; }
public object Tag { get; set; }
}
第三步:MainWindow.xmal
<Grid x:Name="lay">
<Viewport3D x:Name="vp"
Margin="0">
<Viewport3D.Camera>
<PerspectiveCamera
FieldOfView="45" FarPlaneDistance="100"
LookDirection="0,0,-3.4142135623731" NearPlaneDistance="0.1"
Position="0,0,3.4142135623731"
UpDirection="0,3,0"/>
</Viewport3D.Camera>
</Viewport3D>
<Slider Height="23" HorizontalAlignment="Left"
Margin="220,288,0,0" Name="slider1" VerticalAlignment="Top"
Width="100" Maximum="2000" />
<Slider Height="23" HorizontalAlignment="Left"
Margin="49,288,0,0" Name="slider2" VerticalAlignment="Top"
Width="100" Maximum="1000" />
<Slider Height="23" HorizontalAlignment="Left"
Margin="367,288,0,0" Name="slider3" VerticalAlignment="Top"
Width="100" Minimum="200" Maximum="2000" />
<Slider Height="23" HorizontalAlignment="Left"
Margin="567,288,0,0" Name="slider4" VerticalAlignment="Top"
Width="100" Minimum="200" Maximum="2000" />
</Grid>
第四步:MainWindow.xmal
PerspectiveCamera myPCamera;
DirectionalLight myDirectionalLight;
Model3DGroup myModel3DGroup;
WavefrontObjLoader wfl;
ModelVisual3DWithName mv3dw;
public MainWindow()
{
InitializeComponent();
wfl = new
WavefrontObjLoader();
slider1.ValueChanged += new
RoutedPropertyChangedEventHandler<double>(slider1_ValueChanged);
slider2.ValueChanged += new
RoutedPropertyChangedEventHandler<double>(slider2_ValueChanged);
slider3.ValueChanged += new
RoutedPropertyChangedEventHandler<double>(slider3_ValueChanged);
slider4.ValueChanged += new
RoutedPropertyChangedEventHandler<double>(slider4_ValueChanged);
createCamera();
createLight();
createModel3D();
create360();
//createAnimation();
}
#region //光源
private void createLight()
{
myDirectionalLight = new DirectionalLight();
myDirectionalLight.Color = Colors.White;
myDirectionalLight.Direction = new Vector3D(-0.61, -0.5,
-0.61);
}