[IronPython] WPF 3D: Missing Viewport3D when importing

walgri walgri at gmail.com
Wed Aug 15 01:54:02 PDT 2007


Hello,

I have some Python experience, but I'm very new to .Net/WPF programming.
I find that Media3D is missing Viewport3D in 2.0A3:

IronPython console: IronPython 2.0A3 (2.0.10724.00) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import clr
>>> clr.AddReferenceByPartialName("PresentationCore")
>>> import System.Windows.Media.Media3D as media3d
>>> dir(media3d)
['AffineTransform3D', 'AmbientLight', 'AxisAngleRotation3D', 'Camera', 'Converte
rs', 'DiffuseMaterial', 'DirectionalLight', 'EmissiveMaterial', 'Geometry3D', 'G
eometryModel3D', 'HitTestParameters3D', 'Light', 'Material', 'MaterialCollection
', 'MaterialGroup', 'Matrix3D', 'Matrix3DConverter', 'MatrixCamera', 'MatrixTran
sform3D', 'MeshGeometry3D', 'Model3D', 'Model3DCollection', 'Model3DGroup', 'Mod
elVisual3D', 'OrthographicCamera', 'PerspectiveCamera', 'Point3D', 'Point3DColle
ction', 'Point3DCollectionConverter', 'Point3DConverter', 'Point4D', 'Point4DCon
verter', 'PointLight', 'PointLightBase', 'ProjectionCamera', 'Quaternion', 'Quat
ernionConverter', 'QuaternionRotation3D', 'RayHitTestParameters', 'RayHitTestRes
ult', 'RayMeshGeometry3DHitTestResult', 'Rect3D', 'Rect3DConverter', 'RotateTran
sform3D', 'Rotation3D', 'ScaleTransform3D', 'Size3D', 'Size3DConverter', 'Specul
arMaterial', 'SpotLight', 'Transform3D', 'Transform3DCollection', 'Transform3DGr
oup', 'TranslateTransform3D', 'Vector3D', 'Vector3DCollection', 'Vector3DCollect
ionConverter', 'Vector3DConverter', 'Viewport3DVisual', 'Visual3D', 'Visual3DCol
lection']
>>> v=Viewport3D()
Traceback (most recent call last):
  File , line 0, in <string>##18
NameError: name 'Viewport3D' is not defined

>>>


In Ipy 1.1, with previous import of avalon.py, Viewport3D is still
missing, but is actually avaliable:

IronPython 1.1 (1.1) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>>
>>> from avalon import *
>>> clr.AddReferenceByPartialName("PresentationCore")
>>> import System.Windows.Media.Media3D as media3d
>>> dir(media3d)
['AffineTransform3D', 'AmbientLight', 'AxisAngleRotation3D', 'Camera', 'Converte
rs', 'DiffuseMaterial', 'DirectionalLight', 'EmissiveMaterial', 'Geometry3D', 'G
eometryModel3D', 'HitTestParameters3D', 'Light', 'Material', 'MaterialCollection
', 'MaterialGroup', 'Matrix3D', 'Matrix3DConverter', 'MatrixCamera', 'MatrixTran
sform3D', 'MeshGeometry3D', 'Model3D', 'Model3DCollection', 'Model3DGroup', 'Mod
elVisual3D', 'OrthographicCamera', 'PerspectiveCamera', 'Point3D', 'Point3DColle
ction', 'Point3DCollectionConverter', 'Point3DConverter', 'Point4D', 'Point4DCon
verter', 'PointLight', 'PointLightBase', 'ProjectionCamera', 'Quaternion', 'Quat
ernionConverter', 'QuaternionRotation3D', 'RayHitTestParameters', 'RayHitTestRes
ult', 'RayMeshGeometry3DHitTestResult', 'Rect3D', 'Rect3DConverter', 'RotateTran
sform3D', 'Rotation3D', 'ScaleTransform3D', 'Size3D', 'Size3DConverter', 'Specul
arMaterial', 'SpotLight', 'Transform3D', 'Transform3DCollection', 'Transform3DGr
oup', 'TranslateTransform3D', 'Vector3D', 'Vector3DCollection', 'Vector3DCollect
ionConverter', 'Vector3DConverter', 'Viewport3DVisual', 'Visual3D', 'Visual3DCol
lection', '__builtins__', '__dict__', '__name__']
>>> v=Viewport3D()
>>>

Actually the following code works if I cut and paste it in an Ipy 1.1
session, but fails as a standalone app:

###for IronPython 1.1:
#from avalon import *

### for IronPython 2.0A3:
import clr
clr.AddReferenceByPartialName("PresentationCore")
clr.AddReferenceByPartialName("PresentationFramework")

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

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)

#let there be light:
lightmodel = ModelVisual3D()
light = DirectionalLight()
light.Color=Colors.White
light.Direction=Vector3D(-2,-3,-1)
lightmodel.Content = light
v.Children.Add(lightmodel)

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


Any help or advice in getting this code running as an application
would be very appreciated.
Best regards,
Walgri


More information about the Users mailing list