[IronPython] WPF 3D: Missing Viewport3D when importing

Dino Viehland dinov at exchange.microsoft.com
Wed Aug 15 16:49:32 CEST 2007


This is hanging due to the way avalon.py works.  It's primarily intended for working at the interactive console.  When Avalon.py gets started it hijacks the console execution so that all execution occurs on another thread.  This other thread is the primary thread for the app's window and its constantly pumping messages.  This allows you to continue to work at the console while the app remains responsive.

When you run this from a script that's not going to work because the script isn't being entered at the console.  The key thing you need to do is app = Application() and then app.Run() at the bottom of your script.  I copied the necessary lines out of Avalon.py and ended up with:

import clr

#from avalon import *

clr.AddReferenceByPartialName("PresentationCore")
clr.AddReferenceByPartialName("PresentationFramework")
clr.AddReferenceByPartialName("WindowsBase")


from System import *
from System.Windows import *
from System.Windows.Media import *
from System.Windows.Media.Animation import *
from System.Windows.Controls import *
from System.Windows.Shapes import *
from System.Windows.Threading import *
from System.Windows import *
from System.Windows.Media import *
from System.Windows.Media.Media3D import * #from System.Windows.Media.Media3D import Viewport3D


w=Window()
v=Viewport3D()

cam = PerspectiveCamera()
cam.FarPlaneDistance = 100
cam.LookDirection = Vector3D(-11,-10,-9)
cam.UpDirection = Vector3D(0,0,1)
cam.NearPlaneDistance = 1
cam.Position = Point3D(11,10,9)
cam.FieldOfView = 70
v.Camera = cam

triangleMesh = MeshGeometry3D()
point0 = Point3D(0, 0, 0)
point1 = Point3D(5, 0, 0)
point2 = Point3D(0, 0, 5)
triangleMesh.Positions.Add(point0)
triangleMesh.Positions.Add(point1)
triangleMesh.Positions.Add(point2)
triangleMesh.TriangleIndices.Add(0)
triangleMesh.TriangleIndices.Add(2)
triangleMesh.TriangleIndices.Add(1)
normal = Vector3D(0, 1, 0)
triangleMesh.Normals.Add(normal)
triangleMesh.Normals.Add(normal)
triangleMesh.Normals.Add(normal)
material = DiffuseMaterial(SolidColorBrush(Colors.Lime))
triangleModel = GeometryModel3D(triangleMesh, material)
model = ModelVisual3D()
model.Content = triangleModel
v.Children.Add(model)

#aggiungo una luce
lightmodel = ModelVisual3D()
light = DirectionalLight()
light.Color=Colors.White
light.Direction=Vector3D(-2,-3,-1)
lightmodel.Content = light
v.Children.Add(lightmodel)

#visualizza:
w.Content=v
w.Show()
app = Application()
app.Run()
#############################

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of walgri
Sent: Wednesday, August 15, 2007 7:01 AM
To: users at lists.ironpython.com
Subject: Re: [IronPython] WPF 3D: Missing Viewport3D when importing

Sorry, please replace the previous script with the following one.
Running this script as standalone actually shows what I meant and
hangs. But I guess this is unrelated to the Viewport3D issue.
#############################
import clr

from avalon import *

clr.AddReferenceByPartialName("PresentationCore")
clr.AddReferenceByPartialName("PresentationFramework")


from System.Windows import *
from System.Windows.Media import *
from System.Windows.Media.Media3D import *
#from System.Windows.Media.Media3D import Viewport3D


w=Window()
v=Viewport3D()

cam = PerspectiveCamera()
cam.FarPlaneDistance = 100
cam.LookDirection = Vector3D(-11,-10,-9)
cam.UpDirection = Vector3D(0,0,1)
cam.NearPlaneDistance = 1
cam.Position = Point3D(11,10,9)
cam.FieldOfView = 70
v.Camera = cam

triangleMesh = MeshGeometry3D()
point0 = Point3D(0, 0, 0)
point1 = Point3D(5, 0, 0)
point2 = Point3D(0, 0, 5)
triangleMesh.Positions.Add(point0)
triangleMesh.Positions.Add(point1)
triangleMesh.Positions.Add(point2)
triangleMesh.TriangleIndices.Add(0)
triangleMesh.TriangleIndices.Add(2)
triangleMesh.TriangleIndices.Add(1)
normal = Vector3D(0, 1, 0)
triangleMesh.Normals.Add(normal)
triangleMesh.Normals.Add(normal)
triangleMesh.Normals.Add(normal)
material = DiffuseMaterial(SolidColorBrush(Colors.Lime))
triangleModel = GeometryModel3D(triangleMesh, material)
model = ModelVisual3D()
model.Content = triangleModel
v.Children.Add(model)

#aggiungo una luce
lightmodel = ModelVisual3D()
light = DirectionalLight()
light.Color=Colors.White
light.Direction=Vector3D(-2,-3,-1)
lightmodel.Content = light
v.Children.Add(lightmodel)

#visualizza:
w.Content=v
w.Show()
#############################

Best regards,
Walgri

_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list