[Bf-python] getMatrix('worldspace') patch for bf-blender

Campbell Barton cbarton at metavr.com
Sat Jun 26 09:26:41 CEST 2004


Hi, the spelling is probable best english-
blender spells colour, and look at the bone documents for the selling 
locale (a function that getMatrix closly resembles)
Your implimentation is good, could you commit it to the cvs?

- Cam



Joseph Gilbert wrote:

>This will work with a single getMatrix() function:
>
>if (StringEqual (name, "mat") || StringEqual (name, "matrix"))
>   return (Object_getMatrix (obj, Py_BuildValue("(s)","localspace")));
>if (StringEqual (name, "matrixWorld"))
>   return (Object_getMatrix (obj, Py_BuildValue("(s)","worldspace")));
>if (StringEqual (name, "matrixLocal"))
>   return (Object_getMatrix (obj, Py_BuildValue("(s)","localspace")));
>
>The cvars mat/matrix do the same as now and the new cvars matrixWorld and
>matrixLocal return world/local matrix.
>
>static PyObject *Object_getMatrix (BPy_Object *self, PyObject *args)
>{
>	PyObject  *matrix;
>	char *space = "localespace";	 /* default to locale */
>
>	if (!PyArg_ParseTuple(args, "|s", &space)){
>		return (EXPP_ReturnPyObjError (PyExc_AttributeError,
>			"expected a string or nothing"));
>	}
>	//new matrix
>	matrix = newMatrixObject(NULL, 4, 4);
>
>	if (BLI_streq(space, "worldspace")){  	/* Worldspace matrix */
>		where_is_object(self->object);
>		Mat4CpyMat4(*((MatrixObject*)matrix)->matrix, self->object->obmat);
>	} else if (BLI_streq(space, "localespace")) { /* Localespace matrix*/
>		object_to_mat4(self->object, *((MatrixObject*)matrix)->matrix);
>	} else {
>		return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
>			"correct  	spaces are 'worldspace' and 'localespace', none defaults to
>localespace"));
>	}
>	return matrix;
>}
>
>Oh, by the way locale is the english spelling!!! :) In my neck of the wood
>we call it localspace. *_*
>
>-----Original Message-----
>From: bf-python-admin at blender.org [mailto:bf-python-admin at blender.org]On
>Behalf Of Campbell Barton
>Sent: Friday, June 25, 2004 10:02 PM
>To: bf-python at blender.org
>Subject: Re: [Bf-python] getMatrix('worldspace') patch for bf-blender
>
>
>How about this?
>
>
>
>/* This is only used by the wrapper function Object_getMatrix  */
>static PyObject *Object_getMatrixLocalespace (BPy_Object *self)
>{
>    PyObject  *matrix;
>
>    matrix = newMatrixObject(NULL, 4, 4);
>    object_to_mat4(self->object, *((MatrixObject*)matrix)->matrix);
>
>    return matrix;
>}
>
>
>/* This is only used by the wrapper function Object_getMatrix  */
>static PyObject *Object_getMatrixWorldspace (BPy_Object *self)
>{
>    PyObject  *matrix;
>
>    where_is_object(self->object);
>    matrix = newMatrixObject(NULL, 4, 4);
>    Mat4CpyMat4(*((MatrixObject*)matrix)->matrix,
>self->object->obmat);
>
>    return matrix;
>}
>
>
>
>static PyObject *Object_getMatrix (BPy_Object *self, PyObject *args)
>{
>    char            *space = "localespace";     /* default to locale */
>
>  if (!PyArg_ParseTuple(args, "|s", &space))
>  {
>        return (EXPP_ReturnPyObjError (PyExc_AttributeError,
>          "expected a string or nothing"));
>  }
>
>    if (BLI_streq(space, "worldspace")) {    /* Worldspace matrix */
>        return (Object_getMatrixWorldspace (self));
>    } else if (BLI_streq(space, "localespace")) { /* Localespace matrix */
>        return (Object_getMatrixLocalespace (self));
>    } else {
>    return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
>            "correct spaces are 'worldspace' and 'localespace', none
>defaults to localespace"));
>    }
>}
>
>
>
>
>
>
>
>
>
>Campbell Barton wrote:
>
>  
>
>>Hi Yall
>>This is a bigger issue then I expected.
>>
>>getLocation(), getMatrix, getScale, getRot all can have the
>>'worldspace' option BUT.
>>
>>what happens to the class variables?
>>
>>they need to sent an arg to the functions above.
>>
>>I made it so they sent a null python object and made getMatrix account
>>for this but its a messy solution.
>>
>>Another solution could be to use a wrapper function, this would work
>>cleanly for all functions above.
>>
>>
>>getMatrix(ob, arg)
>>{
>> if (arg == worldspace) {
>>   return getMatrixWorldSpace(ob);
>> } elif (arg == localespace) {
>>   return getMatrixLocaleSpace(ob);
>> }
>>}
>>
>>
>>getMatrixWorldSpace(ob)
>>{
>>... do the real stuff here
>>}
>>
>>
>>getMatrixLocaleSpace(ob)
>>{
>>... do the real stuff here
>>}
>>
>>
>>
>>
>>Campbell Barton wrote:
>>
>>    
>>
>>>Hi, have you compiled this?
>>>
>>>if (StringEqual (name, "mat"))
>>>   return (Object_getMatrix (obj));
>>>if (StringEqual (name, "matrix"))
>>>   return (Object_getMatrix (obj));
>>>
>>>This wont work since the new Object_getMatrix wants 2 args.
>>>Object_getMatrix (obj, PyArgs)
>>>
>>>Even if the arg is an empty python object it needs to be there.
>>>As I sead b4, I dobnt know how to do this.
>>>
>>>I need to create an empty Python arg and the problem will be solved.
>>>
>>>- Cam
>>>
>>>
>>>
>>>
>>>Gilbert, Joseph wrote:
>>>
>>>      
>>>
>>>>Hi, :)
>>>> Looks good but I don't think it's necessary to have an internal
>>>>function because the getMatrix() will be backwards compatible anyway
>>>>(when no arg is used). The extra stringcompare functions in getattr
>>>>will
>>>>never get called. Everything minus the internal function is perfect :)
>>>>Oh, I was thinking that this also needs to be done on the bone module
>>>>for rot/loc/size I think. Not sure where else this is applicable.
>>>>
>>>>static PyObject *Object_getMatrix (BPy_Object *self, PyObject *args);
>>>>....
>>>>{"getMatrix", (PyCFunction)Object_getMatrix, METH_VARARGS,"Returns the
>>>>object matrix"},
>>>>.....
>>>>static PyObject *Object_getMatrix (BPy_Object *self, PyObject *args)
>>>>{
>>>>   PyObject  *matrix;
>>>>   char *space = "localespace";     /* default to locale */
>>>>       if (!PyArg_ParseTuple(args, "|s", &space))
>>>>   {
>>>>       return (EXPP_ReturnPyObjError (PyExc_AttributeError,
>>>>         "expected a string or nothing"));
>>>>   }
>>>>       matrix = newMatrixObject(NULL, 4, 4);
>>>>       if (BLI_streq(space, "worldspace"))        /* Worldspace
>>>>matrix */
>>>>   {
>>>>       where_is_object(self->object);
>>>>       Mat4CpyMat4(*((MatrixObject*)matrix)->matrix,
>>>>self->object->obmat);
>>>>   } else if (BLI_streq(space, "localespace")) { /* Localespace matrix
>>>>*/
>>>>       object_to_mat4(self->object, *((MatrixObject*)matrix)->matrix);
>>>>   } else {
>>>>       return (EXPP_ReturnPyObjError (PyExc_RuntimeError, "correct
>>>>spaces          are 'worldspace' and 'localespace', none defaults to
>>>>         localespace"));
>>>>   }
>>>>   return matrix;
>>>>}
>>>>....
>>>>if (StringEqual (name, "mat"))
>>>>   return (Object_getMatrix (obj));
>>>>if (StringEqual (name, "matrix"))
>>>>   return (Object_getMatrix (obj));
>>>>....
>>>>
>>>>_______________________________________________
>>>>Bf-python mailing list
>>>>Bf-python at blender.org
>>>>http://www.blender.org/mailman/listinfo/bf-python
>>>>
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>_______________________________________________
>>>Bf-python mailing list
>>>Bf-python at blender.org
>>>http://www.blender.org/mailman/listinfo/bf-python
>>>
>>>
>>>      
>>>
>>    
>>
>
>
>--
>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
>
>_______________________________________________
>Bf-python mailing list
>Bf-python at blender.org
>http://www.blender.org/mailman/listinfo/bf-python
>
>
>_______________________________________________
>Bf-python mailing list
>Bf-python at blender.org
>http://www.blender.org/mailman/listinfo/bf-python
>
>
>  
>


-- 
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