3ds и WPF в C# 2008
От: Voucik  
Дата: 12.11.08 03:07
Оценка:
Помогите пожалуйста разобраться с WPF в C# 2008.
Подскажите пожалуйста
1. Могу ли я использовать в WPF application анимацию из 3D Max-а (сам объект я уже переконвертил из .3ds в XAML)
2. Если могу, то как (дайте пожалуйста хоть какую ни будь информацию, а то в интернете нахожу только информацию про то как создавать анимацию в самом WPF, а мне надо использовать уже сделанную мною в 3D Max-е )
Мои действия

1. В 3d Max-e я сделал простенький параллелепипед который сгибается
2. Для конвертирования из 3ds в XAML, я использую бесплатную программу Viewer 3ds
Код из Viewer3d:
<!-- Exported with Viewer3ds (www.wpf-graphics.com) (c) 2006 by Andrej Benedik. Original file name: 'E:\del\OOO.3DS' -->
<Viewport3D x:Name="Ab3dViewport1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Viewport3D.Resources>
<MeshGeometry3D x:Key="mesh_0"
Positions="-2.175734,-3.3300076,0 1.6923871,-3.3300076,0 -2.175734,4.3034019,0 1.6923871,4.3034019,0 -2.175734,-3.3300076,7.7951255 1.6923871,-3.3300076,7.7951255 -2.175734,4.3034019,7.7951255 1.6923871,4.3034019,7.7951255 -2.175734,-3.3300076,0 1.6923871,-3.3300076,0 1.6923871,-3.3300076,7.7951255 1.6923871,-3.3300076,7.7951255 -2.175734,-3.3300076,7.7951255 -2.175734,-3.3300076,0 1.6923871,4.3034019,0 1.6923871,-3.3300076,7.7951255 1.6923871,4.3034019,0 -2.175734,4.3034019,0 -2.175734,4.3034019,7.7951255 -2.175734,4.3034019,7.7951255 1.6923871,4.3034019,7.7951255 1.6923871,4.3034019,0 -2.175734,4.3034019,0 -2.175734,-3.3300076,7.7951255 -2.175734,-3.3300076,7.7951255 -2.175734,4.3034019,0 "
TriangleIndices="0 2 3  3 1 0  4 5 7  7 6 4  8 9 10  11 12 13  1 14 7  7 15 1  16 17 18  19 20 21  22 0 23  24 6 25  "
TextureCoordinates="1,0 0,0 1,1 0,1 0,0 1,0 0,1 1,1 0,0 1,0 1,1 1,1 0,1 0,0 1,0 0,1 0,0 1,0 1,1 1,1 0,1 0,0 0,0 1,1 1,1 0,0 "
Normals=""
/>

    </Viewport3D.Resources>
    <Viewport3D.Camera>
<PerspectiveCamera Position="-16.987746,-11.9525302,13.5843928"
LookDirection="16.7460725338562,12.4392274169699,-9.68683002636721"
UpDirection="3.10032755378545E-17,0,1"
NearPlaneDistance="1"
FarPlaneDistance="92"
FieldOfView="50" />
    </Viewport3D.Camera>
    <ModelVisual3D>
      <ModelVisual3D.Content>
        <Model3DGroup>
<GeometryModel3D Geometry="{StaticResource mesh_0}">
<GeometryModel3D.Material><DiffuseMaterial><DiffuseMaterial.Brush><SolidColorBrush Color="#FFC0C0C0" /></DiffuseMaterial.Brush></DiffuseMaterial></GeometryModel3D.Material>
</GeometryModel3D>
<DirectionalLight Color="#FFFFFFFF" Direction="0,0,-1" />

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


Код из WPF:

<Window x:Class="_3DTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="307" Width="496" Loaded="Window_Loaded" MouseMove="Window_MouseMove" Visibility="Collapsed">
    <Grid Width="465">
        <!-- Exported with Viewer3ds (www.wpf-graphics.com) (c) 2006 by Andrej Benedik. Original file name: 'G:\del\OOO.3DS' -->
        <Viewport3D x:Name="Ab3dViewport1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:FieldModifier="public" Margin="0,2,41,0" ClipToBounds="True">
            <Viewport3D.Resources>
                <MeshGeometry3D x:Key="mesh_0" 
Positions="-2.175734,-3.3300076,0 1.6923871,-3.3300076,0 -2.175734,4.3034019,0 1.6923871,4.3034019,0 -2.175734,-3.3300076,7.7951255 1.6923871,-3.3300076,7.7951255 -2.175734,4.3034019,7.7951255 1.6923871,4.3034019,7.7951255 -2.175734,-3.3300076,0 1.6923871,-3.3300076,0 1.6923871,-3.3300076,7.7951255 1.6923871,-3.3300076,7.7951255 -2.175734,-3.3300076,7.7951255 -2.175734,-3.3300076,0 1.6923871,4.3034019,0 1.6923871,-3.3300076,7.7951255 1.6923871,4.3034019,0 -2.175734,4.3034019,0 -2.175734,4.3034019,7.7951255 -2.175734,4.3034019,7.7951255 1.6923871,4.3034019,7.7951255 1.6923871,4.3034019,0 -2.175734,4.3034019,0 -2.175734,-3.3300076,7.7951255 -2.175734,-3.3300076,7.7951255 -2.175734,4.3034019,0 "
TriangleIndices="0 2 3  3 1 0  4 5 7  7 6 4  8 9 10  11 12 13  1 14 7  7 15 1  16 17 18  19 20 21  22 0 23  24 6 25  "
TextureCoordinates="1,0 0,0 1,1 0,1 0,0 1,0 0,1 1,1 0,0 1,0 1,1 1,1 0,1 0,0 1,0 0,1 0,0 1,0 1,1 1,1 0,1 0,0 0,0 1,1 1,1 0,0 "
Normals=""
/>

            </Viewport3D.Resources>
            <Viewport3D.Camera>
                <PerspectiveCamera Position="-17.407934,-12.264652,12.3664819"
LookDirection="17.1662605453237,13.7513492128096,-8.46891918387707"
UpDirection="0,0,1"
NearPlaneDistance="1"
FarPlaneDistance="92"
FieldOfView="50" />
            </Viewport3D.Camera>
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <Model3DGroup>
                        <GeometryModel3D Geometry="{StaticResource mesh_0}" >
                            <GeometryModel3D.Material>
                                <DiffuseMaterial>
                                    <DiffuseMaterial.Brush>
                                        <SolidColorBrush Color="Aqua" />
                                    </DiffuseMaterial.Brush>
                                </DiffuseMaterial>
                            </GeometryModel3D.Material>
                        </GeometryModel3D>
                        <DirectionalLight Color="White" Direction="2,2,-1" />

                    </Model3DGroup>
                </ModelVisual3D.Content>
            </ModelVisual3D>
        </Viewport3D>
        <Viewport3D HorizontalAlignment="Right" Margin="0,33,-2,71" Name="viewport3D1" Width="127" />
    
    </Grid>
</Window>




И тут для теста сделал не большую функцию, дабы убедиться, что я могу как-то воздействовать на объект:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
namespace _3DTest
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            Ab3dViewport1.MouseMove +=new MouseEventHandler(MyFun);
            Ab3dViewport1.MouseDown +=new MouseButtonEventHandler(MyDown);
                       
        }
        void MyFun(object sender, MouseEventArgs e)
        {
           
            MessageBox.Show("Work!");
                      
        }
        void MyDown(object sender,MouseButtonEventArgs e)
        {
       //sdesi mne bi i hotelos' dopisat' kodik, citobi u kubika zarabotala animacia     
           
        }

       
     }
}






Заранее благодарю.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.