[Bf-python] Geometry Data

Campbell Barton cbarton at metavr.com
Tue Aug 1 12:34:25 CEST 2006



Theres a few factors.
I agree its nicer to have data in separate types, each having its own 
methods

But if all the data is an array of vectors, It should be done in a way 
that we dont have to write 3-4 new PyObjects
or that the pyobjects can share operations.

sometimes I need to just have a bunch of floats, it would be good if 
whatever we go with allows somebody to say- I want an array of 
300vectors without constraining their use too much. if that is a Line 
type maybe its ok..

maybe 1 datatype can have a type setting, that can be changes, but in a 
way where generic functions still work.

eg- youd want to be able to transform a line or a point cloud by a matrix.

Also, in the line/polyline case. maybe they could be the same datatype 
with a line.closed property
unless you meant a line as a vector pair

About using an external Geometry library, Id rather mix the operations 
in with the bpython code, what do others think?
In some cases we may want to make them accessible to Blender also so 
those functions could be moved out.

- Cam



Gilbert, Joseph T. wrote:
> This should be divided into more logical groupings.
> Geometry should be split into Line, polygon, etc. with associated
> methods. 
>
> A Polygon object would be more appropriate I think then a VectorArray in
> the Geometry module. Also a Line object, etc. for testing intersections.
> Calculating bounds is only useful on something with a volume....
>
> -----Original Message-----
> From: bf-python-bounces at projects.blender.org
> [mailto:bf-python-bounces at projects.blender.org] On Behalf Of Campbell
> Barton
> Sent: Sunday, July 30, 2006 9:47 PM
> To: Blender Foundation Python list
> Subject: [Bf-python] Geometry Data
>
> Hi Guys,
>
> Iv been thinking about having more abstract geometry data types.
>
> I posted this before but here are some more details,
>
> First, Id like to impliment a vector array type - basicly an iterator 
> that provides wrapped vector access to a C array. it would have the same
>
> malloc problems ans Mesh but youd just need to define the size to begin 
> with.
>
> once you had this data you could operate on it as a blob, apart from 
> being faster it would be easier to read and reuire a lot less looping in
>
> python.
>
> va= Geometry.VectorArray(200, 3) # 3d vec init as (0,0,0) 200 items
>
> or it could be initialized from a a list of vectors
>
> va=Geometry.VectorArray(me.verts)
>
> now you could transform it just like a mesh
> va.transform(matrix)
>
> or get the bounds (annoying to do in Python)
>
> bounds=va.bounds() # possibly have a function to intersect bounds also
>
> Other functions could be
>
> .removeDoubles() # remove points
> .convexHull() # return indicies
> .nearest(someVec) # finds the closest point to a vector
> if Vector in VectorArray  #  would search for the point in the array.
>
> It could also be  used to define a poly line 2d or 3d
>
> va_poly2d.area() #area of the poly
> va_poly2d.PolyPoint(pt) #is the point inside the 2d poly
> va_poly2d.PolySelfIntersec(pt) # does the poly intersect its self
> va_poly2d.PolyIntersectPoly(poly2d)
> and of course the existing poly fill ;)
>
>
> I think this could also save memory too- how much memory does a BPy 
> vector take up by its self?
>
> Theeth, respect your opinion (that this isnt a bottlenack) but Id like 
> to prove myself wrong before assuming these functions would not be much 
> faster in C /python
> also depends on the scripts you write I suppose.
>
> I could make some tests and use a Mesh  as an example of a python array 
> (pretend of course) - then compare with a list of vectors.
>
> Maybe we should look an numarray first?
> Pygame had some examples of pixel operations in in numarray - Realtime 
> image distortion, that you could no way do in Python, so I think there 
> may be a use for this.
>
>   


-- 
Campbell J Barton

133 Hope Street
Geelong West, Victoria 3218 Australia

URL:    http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241



More information about the Bf-python mailing list