Hi All,
I have a VERY simple 3D space defined in WPF, which defines a 3D rectangle, I was hoping to be able to manipulate each one of the Point3D objects (in the "Positions") property on the MeshGeometry3D, but Im having trouble with it...
Here is my XAML:
<Grid>
<Viewport3D Name="ViewPort"
Focusable="true"
ClipToBounds="true"
Width="{Binding Width, ElementName=canvas, Mode=Default}"
Height="{Binding Height, ElementName=canvas, Mode=Default}">
<Viewport3D.Camera>
<PerspectiveCamera Position="0,0,5"/>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<PointLight Color="White" Position="0,0,0">
<PointLight.Transform>
<Transform3DGroup>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
<ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
<RotateTransform3D d:EulerAngles="0,0,0">
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="0" Axis="0,1,0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="2"/>
</Transform3DGroup>
</PointLight.Transform>
</PointLight>
<GeometryModel3D x:Name="model1" Material="{DynamicResource test1}">
<GeometryModel3D.Transform>
<Transform3DGroup>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="1,0,0" Angle="5" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0,1,0" Angle="-5" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
</GeometryModel3D.Transform>
<GeometryModel3D.Geometry>
<MeshGeometry3D
Positions=" -0.5, 0.5, 0.0
-0.5, -0.5, 0.0
1.5, -0.5, 0.0
1.5, 0.5, 0.0"
TextureCoordinates="0,0 0,1 1,1 1,0"
TriangleIndices="0 1 2 2 3 0" />
</GeometryModel3D.Geometry>
</GeometryModel3D>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
<Canvas Background="Transparent" Grid.Column="0" Grid.Row="0" x:Name="canvas" s:Contacts.ContactDown="canvas_ContactDown" Width="{Binding Width, ElementName=window, Mode=Default}" Height="{Binding Height, ElementName=window, Mode=Default}">
</Canvas>
</Grid>
where test1 is just an image wrapped in a visual brush.
And here is my c#:
private void canvas_ContactDown(object sender, ContactEventArgs e)
{
//Point contactPosition = e.GetPosition(this);
//var rayMeshResult = (RayMeshGeometry3DHitTestResult)VisualTreeHelper.HitTest(ViewPort, e.GetPosition(ViewPort));
translatedX -= 0.25;
translatedY -= 0.25;
model1.Transform = new TranslateTransform3D(translatedX, translatedY, 0.0);
//model1.Transform.Transform(new Point3D(translatedX, translatedY, 0.0));
Console.WriteLine("Changed");
//Apply Z index changes here...
var geometry3D = model1.Geometry as MeshGeometry3D;
Point3DCollection positions = geometry3D.Positions;
foreach (var position in positions)
{
position.Offset(0,0,-15);
}
}
But nothing happens in the visual screen...
One thing I want to specifically mention is that I do not want to apply a transformation to the entire object, just one point at a time.
But if thats the only way then I guess Ill have to look into it
Thanks for any help you can give.
Mark