Greetings,
I am attempting to use the Display Conduit to load several mesh objects from separate .3dm files. Once loaded I would like to apply different transformations to each of the mesh objects then display them. I have started with and an example script from @MkMrA2
import rhinoscriptsyntax as rs
import scriptcontext
import Rhino
import System
import System.Drawing
import time
def Main():
# The 3dm file to open and read
pathname = "C:\Test_Box.3dm"
# Open it and get the objects
drawObjs = Load3DMFile(pathname)
# Make the display conduit object for drawing
dc = DisplayConduit(drawObjs)
start=time.time()
Rotate=360
for i in range(Rotate):
Xform=rs.XformRotation2(i,[0,0,1],[0,0,0])
# Draw
dc.xform = Xform
dc.Enabled = True
rs.Redraw()
# Stop drawing
dc.Enabled = False
rs.Redraw()
end=time.time()
print "Display Frames/Second: "+str((end-start)/Rotate)
# Read the 3dm file and return a list of the objects within it
def Load3DMFile(pathname):
f3dm = Rhino.FileIO.File3dm.Read(pathname)
if (f3dm):
objs = f3dm.Objects
return objs
# Display Conduit class to draw in the viewports
class DisplayConduit(Rhino.Display.DisplayConduit):
def __init__(self, objs):
# Store the objects we are to draw
self.drawObjs = objs
print self.drawObjs
# Store the transformation to apply - initially none
self.xform = Rhino.Geometry.Transform.Identity
# Get the bounding box for all the objects passed
self.drawObjsBBox = Rhino.Geometry.BoundingBox(Rhino.Geometry.Point3d(-1,-1,-1), Rhino.Geometry.Point3d(1,1,1))
for item in self.drawObjs:
bbox = item.Geometry.GetBoundingBox(False)
if (bbox):
self.drawObjsBBox.Union(bbox)
# Expand the bbox by 5% of the diagonal length for use in zoom extents
amount = self.drawObjsBBox.Diagonal.Length*0.05
self.drawObjsBBox.Inflate(amount)
# Init the material to draw with
self.material = Rhino.Display.DisplayMaterial()
self.material.Diffuse = System.Drawing.Color.OrangeRed # Kuka robot color!
self.material.Shine = 0.8
# Called to quickly return the bounding box for the scene including our objects
def CalculateBoundingBox(self, calculateBoundingBoxEventArgs):
calculateBoundingBoxEventArgs.IncludeBoundingBox(self.drawObjsBBox)
# Called to quickly return the zoom extents bounding box including our objects
def CalculateBoundingBoxZoomExtents(self, calculateBoundingBoxEventArgs):
calculateBoundingBoxEventArgs.IncludeBoundingBox(self.drawObjsBBox)
# Called to draw the objects to the viewport. This is done before any Rhino
# objects which will be drawn over ours.
def PreDrawObjects(self, drawEventArgs):
drawEventArgs.Display.DrawBox(self.drawObjsBBox, System.Drawing.Color.White)
drawEventArgs.Display.PushModelTransform(self.xform) # Apply the transform
for item in self.drawObjs:
if item.Geometry.ObjectType == Rhino.DocObjects.ObjectType.Curve:
drawEventArgs.Display.DrawCurve(item.Geometry, System.Drawing.Color.Green)
elif item.Geometry.ObjectType == Rhino.DocObjects.ObjectType.Brep:
drawEventArgs.Display.DrawBrepWires(item.Geometry, System.Drawing.Color.Red)
elif item.Geometry.ObjectType == Rhino.DocObjects.ObjectType.Mesh:
#drawEventArgs.Display.DrawMeshWires(item.Geometry, System.Drawing.Color.Blue)
drawEventArgs.Display.DrawMeshShaded(item.Geometry, self.material)
elif item.Geometry.ObjectType == Rhino.DocObjects.ObjectType.Point:
drawEventArgs.Display.DrawPoint(item.Geometry.Location, System.Drawing.Color.White)
drawEventArgs.Display.PopModelTransform() # Remove the transformation
# Run it...
if (__name__ == "__main__"):
Main()
I can load multiple files using Rhino.FileIO.File3dm.Read(file).Objects
But I am unsure how I might go about applying separate transformation matrices to each loaded mesh (say to rotate on clockwise and one counter clockwise). This seems like this should be possible using the display conduit but I have not been able to decipher a solution from the documentation.
If anyone has any advice on this subject I would greatly appreciate it.
Thanks,
5chmidt
Test_Box.3dm (46.4 KB) DisplayConduitTest.py (3.5 KB)