3DLightEngine Library preview
4 commentaires
I will quickly provide an opensource (ms-pl) library named LightEngine3D. The main goal is to achieve basics 3D scenario that Plane projection can't solve easily. By the way, it is based on Silverlight Matrix3D structure. Automatic Z-sorting, backface culling, Camera, Vector3D ( and maybe directionnal light) will be include and managed without the need of 3D knowledge. The final release will be lite and extensible.
The code for that example is very simple
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | //we define a 60 degres angle double FovY = Matrix3DUtils.DegresToRadians(60); //default displayed bitmap Uri BitmapUri= new Uri("Blend3_logo3.jpg", UriKind.Relative); Element3D E3D; Scene3D s; public MainPage() { // Required to initialize variables InitializeComponent(); ResetBtn.Click += new RoutedEventHandler(ResetBtn_Click); E3D = new Element3D(MonUIElement); E3D.NormalDirectionChanged += new Element3D.DirectionChanged(E3D_NormalDirectionChanged); E3D.DotProductChanged += new Element3D.DirectionChanged(E3D_DotProductChanged); #region Personalize perspective and ViewPort /* Perspective p = new Perspective(FovY, //Field of view LayoutRoot.ActualWidth / LayoutRoot.ActualHeight, //ratio 1.0, //near clip plane 3000.0); //far clip plane Viewport v = new Viewport(LayoutRoot.ActualWidth, LayoutRoot.ActualHeight); s = new Scene3D(LayoutRoot, p, v); */ #endregion #region Personalize clip plane /* s = new Scene3D(LayoutRoot, FovY,1,3000); */ #endregion #region Personalize Field of view angle s = new Scene3D(LayoutRoot, FovY); #endregion } //dot product change event handler void E3D_DotProductChanged(Element3D sender, int normalDirection) { ProduitScalaireTxt.Text = sender.DotProduct.ToString(); } //normal direction change event handler void E3D_NormalDirectionChanged(Element3D sender, int normalDirection) { DirectionTxt.Text = normalDirection.ToString(); Uri BitmapUri = normalDirection == 1 ? new Uri("Blend3_logo3.jpg", UriKind.Relative) : new Uri("Blend3_logo.jpg", UriKind.Relative); MonUIElement.Source = new BitmapImage(BitmapUri); } private void onTranslateXChange(object sender, RoutedPropertyChangedEventArgs<double> e) { E3D.GlobalOffsetX = e.NewValue; s.RenderScene(); } // |
You just have to instanciate Element3D and pass the FrameworkElement in the constructor
Il suffit d'utiliser la classe enveloppante Element3D et d'instancier une nouvelle scène. I will add very quickly ContainerElement3D class. By default the object is not in a container but directly in the Scene3D. This example shows that it is relatively simple to extend the existing capabilities of Silverlight in 3D. The next step, make some features of DirectX ...

