Commit Graph

40 Commits

Author SHA1 Message Date
Ken Hughes
318a694a25 Get rid of various warnings with gcc under linux 2006-11-17 17:50:43 +00:00
b3a48fe82e removed some unused vars from Curve and matrix
scn.objects.new(None) - adds a new empty
 - new objects are selected by default now

further stripped down the vector struct, the wrapped state was being stored and 2 places.
2006-10-07 11:49:53 +00:00
5dcf97c892 moved vector objects to getseters,
added in place operations.
  Vector_iadd   vec1+=vec2
  Vector_isub   vec1-=vec2
  Vector_imul   vec1*=float or vec1*=mat
  Vector_idiv   vec1/=float

length is now writable vec.length= float
2006-10-03 16:07:48 +00:00
6b7c4e09e8 Mathutils.Vector speedup
removed the need for casting python objects to Vectors pyobjects when performing vec/float arithmatic.
a PyObject for coercing has also been removed from the vector struct so a little less memory will be used also.


Benchmarked before and after this change
___________________________________
import Blender
v= Blender.Mathutils.Vector
m= Blender.Mathutils.Matrix

a= v(1,2,3)
b= v(3,2,1)
c= m()
t= Blender.sys.time()
for i in xrange(20000000):
        a*b
        a*10
        a/10
        a+b
        b-a
        a*c

print Blender.sys.time()-t
_______________________________________

Before 63.5sec
after 49.5

about 3 sec of that is looping
2006-10-03 05:11:33 +00:00
32b1e2383b 3rd attempt to commit, metaball fixes and small vector optimization 2006-09-30 14:14:49 +00:00
0925d80cfa removed the unpopular 'ed' functions, and added .copy() to Mathutils vector and matrix
(inverted, normalized, transposed)

making an inverted copy of an objects matrix used to be.. (2.42)

  imat= Mathutils.Matrix(ob.matrixWorld)
  imat.invert()


# inverted.. I added but now removed

  imat= ob.matrixWorld.inverted()

# with copy (current functionality)...

  imat= ob.matrixWorld.copy().invert()
2006-08-21 13:52:32 +00:00
b227c98c44 Addition to Mathutils
vec.normalized()
 mat.inverted()
 mat.transposed()
 made vec/float possible

 normalize/invert/transpose now return None because they modify the data in place.
 use the ...(ed) versions to return a modified copy.


Fixed Memory leaks from not decreffing PyFloat_AS_DOUBLE from these python functions...
(found when testing above functions)
  ob.rbMass
  ob.rbRadius
  matrix.determinant()
  quat*float
  vec*float
  matrix.transpose()
  EXPP_setModuleConstant

Checked all instances of PyFloat_AS_DOUBLE so I dont think there are any mroe leaks there.
2006-07-27 01:18:21 +00:00
150d36e4da BPy: Mathutils fix: bug #3737
Vector.resize4D() didn't put 1 in the 4th component (the scale factor), as it did in 2.37.
While this is more "correct", it is much less usefull. Also, matrix.resize4x4 puts a 1 there too,
so might as well revert and be consistent.
2006-01-12 01:11:42 +00:00
Ken Hughes
e209676d3d -- Bugfix 3453: coercion operations were doing an extra incref on coerced
objects.  Also found extra increfs on some newly-created quat and matrix
   objects, from calls to Matrix_Identity() and Quaternion_Identity().
2005-12-05 19:02:30 +00:00
b63e26e109 Added some equvalency tests for the other math objects
* ==, != are defined for matrix, quat, euler.
2005-11-22 17:59:49 +00:00
39a243f8d2 Refcount fixes
* fixes posible reference count issues with mathutils
* mathutils classes should no longer memory leak
2005-09-27 17:03:28 +00:00
f1ddb77a48 - added some equivalency testing for vector classes
>, >=, <, <= test vector magnitude
==, != test vector values 'within epsilon' :)
- inspired by ideasman
2005-09-26 20:11:13 +00:00
9656e8be02 Theeth's mathutils patch
- adds intersections for lines
- triangle area
- tracking quaternion from vector
- some helpful normal calculators
2005-09-26 15:06:28 +00:00
Stephen Swaney
a4ca8267cf bugfix: [ #3009 ] possible memory leak in Mathutils
fixed by patch [ #3013 ] patch for memleak in vector
Submitted By: Ken Hughes (khughes)
2005-09-12 06:18:45 +00:00
841ddb4680 A couple of small fixes...
I removed config.h code from the files that had them.
effect.c had nested /* so cleaned that up...

added a newline to vector.c to shut gcc up ;)
buttons_editing.c had a possible unintalized var (height) so I gave
it a default value.

removed an unused var i in interface_draw.c
removed an unused var mti in outliner.c

in BL_SkinDeformer.cpp
commented out a call to bDeformGroup->data which no longer exists so it
compiles again.

Kent
2005-08-11 16:39:51 +00:00
6a9e7ab3f2 _new point class and update_
- adds a new point class
  * point/ vector math (p + v = p, p - p = v, etc.)
  * points can be transformed by matrices/quats
  * wraps 'place vector' type vectors that have no magnitude
- wrapped toXXX() methods work correctly
  * toXXX() will NOT wrap data (this is due to the fact that wrapped data cannot be converted)
  * added a 'wrapped' attribute to mathutils classes to determine wether the object is accessing python or blender data
- added the ability to negate vectors/points with "-vec"
  * deprecated vector.negate()
- added the ability to shorhand inverse matrices with "~mat" (tilde)
- conversion between vector/point with toXXX() methods
2005-07-23 13:46:40 +00:00
2801c8b20a __ bug fix__
- internal methods for mathutils class need to incref before returning a pointer to self
  * memory allocation errors (freeing bad pointers) were appearing after repeatedly calling internal methods on the same object due to ref counts.
2005-07-19 18:47:25 +00:00
e60291d39c Header file clean up and warning fixes
- Mostly this cleans up the #includes and header files in the python project.
- Warning fixes are mostly casting issues and misc fixes. General warning clean up.
- #include Python.h MUST come as the first include to avoid the POSIX redefine warning in the unix makefiles
- fno-strict-aliasing flag added to makefile to fix a unavoidable type punning warning in types.c
2005-07-18 03:50:37 +00:00
b89035906d Mathutils update
- also included is some fixes for preprocessor inclues and some clean up of the previous commit

-rewrite and bugfixes
  ----------------------------------
  Here's my changelog:
  -fixed Rand() so that it doesn't seed everytime and should generate better random numbers
  - changed a few error return types to something more appropriate
  - clean up of uninitialized variables & removal of unneccessary objects
  - NMesh returns wrapped vectors now
  - World returns wrapped matrices now
  - Object.getEuler() and Object.getBoundingBox() return Wrapped data when data is present
  - Object.getMatrix() returns wrapped data if it's worldspace, 'localspace' returns a new matrix
  - Vector, Euler, Mat, Quat, call all now internally wrap object without destroying internal datablocks
  - Removed memory allocation (unneeded) from all methods
  - Vector's resize methods are only applicable to new vectors not wrapped data.
  - Matrix(), Quat(), Euler(), Vector() now accepts ANY sequence list, including tuples, list, or a self object to copy - matrices accept multiple sequences
  - Fixed Slerp() so that it now works correctly values are clamped between 0 and 1
  - Euler.rotate does internal rotation now
  - Slice assignment now works better for all types
  - Vector * Vector and Quat * Quat are defined and return the DOT product
  - Mat * Vec and Vec * Mat are defined now
  - Moved #includes to .c file from headers. Also fixed prototypes in mathutils
  - Added new helper functions for incref'ing to genutils
  - Major cleanup of header files includes - include Mathutils.h for access to math types
  - matrix.toQuat() and .toEuler() now fixed take appropriate matrix sizes
  - Matrix() with no parameters now returns an identity matrix by default not a zero matrix
  - printf() now prints with 6 digits instead of 4
  - printf() now prints output with object descriptor
  - Matrices now support [x][y] assignment (e.g. matrix[x][y] = 5.4)
  - Matrix[index] = value now expectes a sequence not an integer. This will now set a ROW of the matrix through a sequence.  index cannot go above the row size of the matrix.
  - slice operations on matrices work with sequences now (rows of the matrix) example:  mymatrix[0:2] returns a list of 2 wrapped vectors with access to the matrix data.
  - slice assignment will no longer modify the data if the assignment operation fails
  - fixed error in matrix * scalar multiplication
  - euler.toMatrix(), toQuat() no longer causes "creep" from repeated use
  - Wrapped data will generate wrapped objects when toEuler(), toQuat(), toMatrix() is used
  - Quats can be created with angle/axis, axis/angle
  - 4x4 matrices can be multiplied by 3D vectors (by popular demand :))
  - vec *quat / quat * vec is now defined
  - vec.magnitude alias for vec.length
  - all self, internal methods return a pointer to self now so you can do print vector.internalmethod() or vector.internalmethod().nextmethod() (no more print matrix.inverse() returning 'none')
  - these methods have been deprecated (still functioning but suggested to use the corrected functionality):
    * CopyVec() - replaced by Vector() functionality
    * CopyMat() - replaced by Matrix() functionality
    * CopyQuat() - replace by Quaternion() functionality
    * CopyEuler() - replaced by Euler() functionality
    * RotateEuler() - replaced by Euler.rotate() funtionality
    * MatMultVec() - replaced by matrix * vector
    * VecMultMat() - replaced by vector * matrix
  -  New struct containers references to python object data or internally allocated blender data for wrapping
  * Explaination here:  math structs now function as a 'simple wrapper' or a 'py_object' - data that is created on the fly will now be a 'py_object' with its memory managed by python
  *    otherwise if the data is returned by blender's G.main then the math object is a 'simple wrapper' and data can be accessed directly from the struct just like other python objects.
2005-07-14 03:34:56 +00:00
2a1fe1b0cb BPython bug fixes:
- Patch #2491: Mathutils.AngleBetweenVecs BUGFIX
http://projects.blender.org/tracker/?func=detail&aid=2491&group_id=9&atid=127

- #2607: Python String button can segfault if the allowable length is greater than 400
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2607&group_id=9

- #2490: Vector == None gives warning
http://projects.blender.org/tracker/?func=detail&aid=2490&group_id=9&atid=125

- #2476: Image.Draw()
http://projects.blender.org/tracker/?func=detail&aid=2476&group_id=9&atid=125

All reported by Campbell, who also wrote the #2491 patch.  Ken Hughes provided patches for #2490 and #2476.  Thanks guys.
2005-05-25 04:52:52 +00:00
Stephen Swaney
ece00ff04a Roll back changes from Big Mathutils Commit on 2005/05/20. 2005-05-22 17:40:00 +00:00
7586eb28a1 -rewrite and bugfixes
----------------------------------
Here's my changelog:
-fixed Rand() so that it doesn't seed everytime and should generate better random numbers
- changed a few error return types to something more appropriate
- clean up of uninitialized variables & removal of unneccessary objects
- NMesh returns wrapped vectors now
- World returns wrapped matrices now
- Object.getEuler() and Object.getBoundingBox() return Wrapped data when data is present
- Object.getMatrix() returns wrapped data if it's worldspace, 'localspace' returns a new matrix
- Vector, Euler, Mat, Quat, call all now internally wrap object without destroying internal datablocks
- Removed memory allocation (unneeded) from all methods
- Vector's resize methods are only applicable to new vectors not wrapped data.
- Matrix(), Quat(), Euler(), Vector() now accepts ANY sequence list, including tuples, list, or a self object to copy - matrices accept multiple sequences
- Fixed Slerp() so that it now works correctly values are clamped between 0 and 1
- Euler.rotate does internal rotation now
- Slice assignment now works better for all types
- Vector * Vector and Quat * Quat are defined and return the DOT product
- Mat * Vec and Vec * Mat are defined now
- Moved #includes to .c file from headers. Also fixed prototypes in mathutils
- Added new helper functions for incref'ing to genutils
- Major cleanup of header files includes - include Mathutils.h for access to math types
- matrix.toQuat() and .toEuler() now fixed take appropriate matrix sizes
- Matrix() with no parameters now returns an identity matrix by default not a zero matrix
- printf() now prints with 6 digits instead of 4
- printf() now prints output with object descriptor
- Matrices now support [x][y] assignment (e.g. matrix[x][y] = 5.4)
- Matrix[index] = value now expectes a sequence not an integer. This will now set a ROW of the matrix through a sequence.  index cannot go above the row size of the matrix.
- slice operations on matrices work with sequences now (rows of the matrix) example:  mymatrix[0:2] returns a list of 2 wrapped vectors with access to the matrix data.
- slice assignment will no longer modify the data if the assignment operation fails
- fixed error in matrix * scalar multiplication
- euler.toMatrix(), toQuat() no longer causes "creep" from repeated use
- Wrapped data will generate wrapped objects when toEuler(), toQuat(), toMatrix() is used
- Quats can be created with angle/axis, axis/angle
- 4x4 matrices can be multiplied by 3D vectors (by popular demand :))
- vec *quat / quat * vec is now defined
- vec.magnitude alias for vec.length
- all self, internal methods return a pointer to self now so you can do print vector.internalmethod() or vector.internalmethod().nextmethod() (no more print matrix.inverse() returning 'none')
- these methods have been deprecated (still functioning but suggested to use the corrected functionality):
  * CopyVec() - replaced by Vector() functionality
  * CopyMat() - replaced by Matrix() functionality
  * CopyQuat() - replace by Quaternion() functionality
  * CopyEuler() - replaced by Euler() functionality
  * RotateEuler() - replaced by Euler.rotate() funtionality
  * MatMultVec() - replaced by matrix * vector
  * VecMultMat() - replaced by vector * matrix
-  New struct containers references to python object data or internally allocated blender data for wrapping
* Explaination here:  math structs now function as a 'simple wrapper' or a 'py_object' - data that is created on the fly will now be a 'py_object' with its memory managed by python
*    otherwise if the data is returned by blender's G.main then the math object is a 'simple wrapper' and data can be accessed directly from the struct just like other python objects.
2005-05-20 19:28:04 +00:00
c78e44cdc5 big warning hunt commit
lot of casts, added prototypes, missing includes and some true errors
2005-03-09 19:45:59 +00:00
48bc598658 More warning cleanups...
added a casts to:
   blender/blenlib/intern/BLI_memarena.c
   gameengine/Rasterizer/RAS_TexVert.cpp

Removed unused vars from:
   blender/python/api2_2x/vector.c
   gameengine/Ketsji/KX_PyMath.cpp gameengine/Ketsji/KX_Scene.cpp
   gameengine/Physics/Sumo/Fuzzics/src/SM_Object.cpp
   gameengine/Rasterizer/RAS_FramingManager.cpp
   gameengine/Rasterizer/RAS_Polygon.cpp
   gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.cpp

Kent
2005-01-03 18:05:24 +00:00
Stephen Swaney
7dda27fcd7 followup to vector memory leak fixes:
fix for problems with NMesh vertices.
  plug some more leaks in matrix module.
  new vector method newVectorProxy().

In BPy-Land, we have overloaded the meaning of our Vector
type.  One use is for vectors in the traditional mathmatical
sense.  The other legacy use is as a proxy for Blender data.
The recent memory leak fixed have lead to the Vector type
behaving as mathematical vectors.

However, the NMesh module is still using Vector types as a
proxy to manipulate NMVert data.  To support this usage, in
the vector module there is a new factory method
newVectorProxy().  This creates a Vector that references
memory outside the Vector.  Vectors created by
newVectorProxy() do NOT free their referenced memory.  The
newVectorProxy() is used only in bpy code and is not exposed
thru the scripting interface.

Anyone using newVectorProxy() must be aware of object
lifetime and scoping issues because the returned Vector
holds a pointer to memory it does not own.  This works in
the NMVert case since we are referencing memory belonging to
the NMVert object via an NMVert method.
2004-10-14 17:35:16 +00:00
Stephen Swaney
b711409f8d fix numerous memory leaks in the math types.
fixed bug:  #1633  Memory leak in M_Mathutils_Vector

The math types ( matrix, vector, quad ) now make
copies of data passed to them rather than holding
a pointer to memory that cannot be freed, or that
may go away unexpectedly.

This also clarifies the problem of who is responsible
for freeing memory allocations.

Pre-checkin files are tagged mem_leak-1 in case this
breaks something.
2004-10-12 23:58:03 +00:00
Stephen Swaney
a509b8adc9 Another round in the Great BPy Cleanup:
Run everything thru indent to cleanup spaces vs tabs.
Clean up some of the comments by hand.
BGL.c was not touched due to all that macro wackyness.

There are no functional changes to the code.
Pre-indent versions of source are tagged with
tag bpy-cleanup-20040925 , just in case.
2004-09-25 20:30:40 +00:00
Stephen Swaney
a2ea84903e One small part of the Great Bpy Code Cleanup.
Add cvs $Id tag to files
2004-09-18 18:47:03 +00:00
Stephen Swaney
ae20f7a95e bugfix: #1206 Object.getBoundBox() was returning obdata coordinates.
fix memory leak in vector module.  Memory allocated by vector constructor
was not being freed.
2004-05-15 23:10:37 +00:00
f141aed9dc - bugfix #1197 (New Bone.parent/child Access Destructive)
- a major redo of the Bone module
- BPy_Bone structs are separated into Bone data and python vars. This is necessary for the correct memory allocation of bone data between python and the global armature list.
2004-05-11 08:26:44 +00:00
8f3a9815ba Mathutils library for the python API
- support for quaternions, euler, vector, matrix operations.
- euler supports unique rotation calculation
- new matrix memory construction and internal functions
- quaternion slerp and diff calculation
- 2d, 3d, 4d vector construction and handling
- full conversion support between types
- update to object/window to reflect to matrix type
- update to types/blender/module to reflect new module
2004-02-29 13:20:34 +00:00
775f006bf1 Exppython:
- Window: implemented .SetCursorPos, .GetViewMatrix, .GetViewVector
- Lamp: .setDist was not in the methods table:
    Fix by new bpython developer Stephen Swaney
- Scene: .frameSettings was crashing Blender (pointed by jms)
- Added site dirs to sys.path (patch by Stephen Swaney)
- NMesh: small internal change (added pointer to parent object)
- Object: function NMesh_FromPyObject has a new arg: pointer to obj
- Docs: added docs for implemented functions, plus some more info
2003-09-18 00:54:43 +00:00
a09e5a7f2f Exppython:
- Window: added .GetCursorPos()
- Lamp: updated for NoDiffuse and NoSpecular modes
- Registry: new module to handle persistent data
- vector: made it correctly print only 3 values when vec->size==3:
    Fixes nmvert coords printed with a 4th 0.0 coordinate
- Text: fixed crash on startup (Python 2.3, linux):
    added definition of the Text pyobject earlier, in Types.c
2003-09-03 04:13:08 +00:00
828347f698 * removed some debugging prints. Accidentally committed them last time.
* nicely format the matrix object when printing.
2003-07-06 20:34:59 +00:00
aa820ec420 Exppython:
- Continued getting rid of print methods and updating repr ones:
    Needed to fix crashes on Windows >= 98 systems.
- Found and fixed a few small memory leaks in EXPP_interface, related to
  execution of script links.
2003-07-05 01:18:41 +00:00
61e41f6817 * Added matrix module
* Moved the function EXPP_tuple_repr from vector.c to gen_utils.[ch]
* Matrix functionality should work now in Object module.
* Fixed compilation warning about implicit declaration of M_World_Init.
  Added the declaration to modules.h
2003-06-22 20:14:11 +00:00
6cc45538ef * Small changes in many files:
-  Trying to fix linking problems in OSX;
-  Making module .Get functions behave like the ones in Blender 2.25 - 2.27
   (Guignot pointed the incompatibility);
-  Included more types to Blender.Types;
-  Found by luck and corrected two bugs that were making Blender crash;
-  Added/updated some simple functions.
2003-06-12 04:51:50 +00:00
a127b38760 * Fix compilation errors on Windows hopefully. Implemented the suggestion done
by Aphex - thanks.
* Added the doc strings to the Object module.
* Added more functionality to the Object module.
2003-06-02 20:15:50 +00:00
b7bf9bf1b7 * Added submodule Blender.Material
* Added submodule Blender.Types:
    Blender Type definitions can't be static anymore.
* Some cleanup of now unused defines in Camera.h and Lamp.h
2003-05-28 04:36:18 +00:00
ed78dcc96c * Added submodule NMesh:
Partially implemented.  Most of it comes from opy_nmesh.c, plus needed
    changes to integrate in into exppython.
* Added helper submodule vector, needed by NMesh.
* Minor changes in other files.
2003-05-17 04:29:49 +00:00