fix bmap python binding error

This commit is contained in:
yyc12345 2023-11-10 12:23:03 +08:00
parent 9b447733fb
commit 77bb3ce7d2
5 changed files with 31 additions and 26 deletions

View File

@ -46,6 +46,7 @@ class bm_VxVector3(ctypes.Structure):
('z', bm_CKFLOAT), ('z', bm_CKFLOAT),
] ]
bm_VxVector3_p = ctypes.POINTER(bm_VxVector3) bm_VxVector3_p = ctypes.POINTER(bm_VxVector3)
bm_VxVector3_pp = ctypes.POINTER(bm_VxVector3_p)
class bm_VxColor(ctypes.Structure): class bm_VxColor(ctypes.Structure):
_fields_ = [ _fields_ = [
('r', bm_CKFLOAT), ('r', bm_CKFLOAT),
@ -223,7 +224,7 @@ BMMeshTrans_PrepareVertexCount = _create_bmap_func('BMMeshTrans_PrepareVertexCou
# @param trans[in] Type: BMap::BMMeshTransition*. The pointer to corresponding BMMeshTransition. # @param trans[in] Type: BMap::BMMeshTransition*. The pointer to corresponding BMMeshTransition.
# @param out_mem[out] Type: LibCmo::VxMath::VxVector3*. Use ctypes.byref(data) pass it. # @param out_mem[out] Type: LibCmo::VxMath::VxVector3*. Use ctypes.byref(data) pass it.
# @return True if no error, otherwise False. # @return True if no error, otherwise False.
BMMeshTrans_PrepareVertex = _create_bmap_func('BMMeshTrans_PrepareVertex', [bm_void_p, bm_VxVector2_pp]) BMMeshTrans_PrepareVertex = _create_bmap_func('BMMeshTrans_PrepareVertex', [bm_void_p, bm_VxVector3_pp])
## BMMeshTrans_PrepareNormalCount ## BMMeshTrans_PrepareNormalCount
# @param trans[in] Type: BMap::BMMeshTransition*. The pointer to corresponding BMMeshTransition. # @param trans[in] Type: BMap::BMMeshTransition*. The pointer to corresponding BMMeshTransition.
# @param count[in] Type: LibCmo::CKDWORD. # @param count[in] Type: LibCmo::CKDWORD.
@ -233,7 +234,7 @@ BMMeshTrans_PrepareNormalCount = _create_bmap_func('BMMeshTrans_PrepareNormalCou
# @param trans[in] Type: BMap::BMMeshTransition*. The pointer to corresponding BMMeshTransition. # @param trans[in] Type: BMap::BMMeshTransition*. The pointer to corresponding BMMeshTransition.
# @param out_mem[out] Type: LibCmo::VxMath::VxVector3*. Use ctypes.byref(data) pass it. # @param out_mem[out] Type: LibCmo::VxMath::VxVector3*. Use ctypes.byref(data) pass it.
# @return True if no error, otherwise False. # @return True if no error, otherwise False.
BMMeshTrans_PrepareNormal = _create_bmap_func('BMMeshTrans_PrepareNormal', [bm_void_p, bm_VxVector2_pp]) BMMeshTrans_PrepareNormal = _create_bmap_func('BMMeshTrans_PrepareNormal', [bm_void_p, bm_VxVector3_pp])
## BMMeshTrans_PrepareUVCount ## BMMeshTrans_PrepareUVCount
# @param trans[in] Type: BMap::BMMeshTransition*. The pointer to corresponding BMMeshTransition. # @param trans[in] Type: BMap::BMMeshTransition*. The pointer to corresponding BMMeshTransition.
# @param count[in] Type: LibCmo::CKDWORD. # @param count[in] Type: LibCmo::CKDWORD.
@ -651,13 +652,13 @@ BMMesh_SetVertexCount = _create_bmap_func('BMMesh_SetVertexCount', [bm_void_p, b
# @param objid[in] Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. # @param objid[in] Type: LibCmo::CK2::CK_ID. The CKID of object you accessing.
# @param out_mem[out] Type: LibCmo::VxMath::VxVector3*. Use ctypes.byref(data) pass it. # @param out_mem[out] Type: LibCmo::VxMath::VxVector3*. Use ctypes.byref(data) pass it.
# @return True if no error, otherwise False. # @return True if no error, otherwise False.
BMMesh_GetVertexPositions = _create_bmap_func('BMMesh_GetVertexPositions', [bm_void_p, bm_CKID, bm_VxVector2_pp]) BMMesh_GetVertexPositions = _create_bmap_func('BMMesh_GetVertexPositions', [bm_void_p, bm_CKID, bm_VxVector3_pp])
## BMMesh_GetVertexNormals ## BMMesh_GetVertexNormals
# @param bmfile[in] Type: BMap::BMFile*. The pointer to corresponding BMFile. # @param bmfile[in] Type: BMap::BMFile*. The pointer to corresponding BMFile.
# @param objid[in] Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. # @param objid[in] Type: LibCmo::CK2::CK_ID. The CKID of object you accessing.
# @param out_mem[out] Type: LibCmo::VxMath::VxVector3*. Use ctypes.byref(data) pass it. # @param out_mem[out] Type: LibCmo::VxMath::VxVector3*. Use ctypes.byref(data) pass it.
# @return True if no error, otherwise False. # @return True if no error, otherwise False.
BMMesh_GetVertexNormals = _create_bmap_func('BMMesh_GetVertexNormals', [bm_void_p, bm_CKID, bm_VxVector2_pp]) BMMesh_GetVertexNormals = _create_bmap_func('BMMesh_GetVertexNormals', [bm_void_p, bm_CKID, bm_VxVector3_pp])
## BMMesh_GetVertexUVs ## BMMesh_GetVertexUVs
# @param bmfile[in] Type: BMap::BMFile*. The pointer to corresponding BMFile. # @param bmfile[in] Type: BMap::BMFile*. The pointer to corresponding BMFile.
# @param objid[in] Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. # @param objid[in] Type: LibCmo::CK2::CK_ID. The CKID of object you accessing.

View File

@ -48,13 +48,15 @@ class _AbstractCKObject(_AbstractPointer):
return bmap.bm_CKID(self.__mCKID) return bmap.bm_CKID(self.__mCKID)
def __eq__(self, obj: object) -> bool: def __eq__(self, obj: object) -> bool:
if not _AbstractPointer.__eq__(self, obj): return False
if isinstance(obj, self.__class__): if isinstance(obj, self.__class__):
return obj.__mRawPointer == self.__mRawPointer and obj.__mCKID == self.__mCKID return obj.__mCKID == self.__mCKID
else: else:
return False return False
def __hash__(self) -> int: def __hash__(self) -> int:
return hash((self.__mRawPointer, self.__mCKID)) return hash((_AbstractPointer.__hash__(self), self.__mCKID))
#endregion #endregion
@ -119,6 +121,7 @@ def _ckfaceindices_iterator(pindices: bmap.bm_CKDWORD_p, count: int) -> typing.I
ret.i2 = pindices[idx + 1] ret.i2 = pindices[idx + 1]
ret.i3 = pindices[idx + 2] ret.i3 = pindices[idx + 2]
idx += 3 idx += 3
yield ret
#endregion #endregion
@ -429,7 +432,7 @@ class BMMesh(BMObject):
def get_vertex_uvs(self) -> typing.Iterator[virtools_types.VxVector2]: def get_vertex_uvs(self) -> typing.Iterator[virtools_types.VxVector2]:
raw_vector: bmap.bm_VxVector2_p = bmap.bm_VxVector2_p() raw_vector: bmap.bm_VxVector2_p = bmap.bm_VxVector2_p()
bmap.BMMesh_GetVertexUVs(self._get_pointer(), self._get_ckid(), ctypes.byref(raw_vector)) bmap.BMMesh_GetVertexUVs(self._get_pointer(), self._get_ckid(), ctypes.byref(raw_vector))
_vxvector2_iterator(raw_vector, self.get_vertex_count()) return _vxvector2_iterator(raw_vector, self.get_vertex_count())
def set_vertex_uvs(self, itor: typing.Iterator[virtools_types.VxVector2]) -> None: def set_vertex_uvs(self, itor: typing.Iterator[virtools_types.VxVector2]) -> None:
raw_vector: bmap.bm_VxVector2_p = bmap.bm_VxVector2_p() raw_vector: bmap.bm_VxVector2_p = bmap.bm_VxVector2_p()
@ -457,13 +460,13 @@ class BMMesh(BMObject):
def get_face_material_slot_indexs(self) -> typing.Iterator[int]: def get_face_material_slot_indexs(self) -> typing.Iterator[int]:
raw_idx: bmap.bm_CKWORD_p = bmap.bm_CKWORD_p() raw_idx: bmap.bm_CKWORD_p = bmap.bm_CKWORD_p()
bmap.BMMesh_GetFaceIndices(self._get_pointer(), self._get_ckid(), ctypes.byref(raw_idx)) bmap.BMMesh_GetFaceMaterialSlotIndexs(self._get_pointer(), self._get_ckid(), ctypes.byref(raw_idx))
for i in range(self.get_face_count()): for i in range(self.get_face_count()):
yield raw_idx[i] yield raw_idx[i]
def set_face_material_slot_indexs(self, itor: typing.Iterator[int]) -> None: def set_face_material_slot_indexs(self, itor: typing.Iterator[int]) -> None:
raw_idx: bmap.bm_CKWORD_p = bmap.bm_CKWORD_p() raw_idx: bmap.bm_CKWORD_p = bmap.bm_CKWORD_p()
bmap.BMMesh_GetFaceIndices(self._get_pointer(), self._get_ckid(), ctypes.byref(raw_idx)) bmap.BMMesh_GetFaceMaterialSlotIndexs(self._get_pointer(), self._get_ckid(), ctypes.byref(raw_idx))
for i in range(self.get_face_count()): for i in range(self.get_face_count()):
raw_idx[i] = next(itor) raw_idx[i] = next(itor)

View File

@ -136,42 +136,42 @@ class VxMatrix():
The Matrix representation. The Matrix representation.
The bracket statement exactly equal with Virtools. The bracket statement exactly equal with Virtools.
""" """
__mData: list[list[float]] data: list[list[float]]
def __init__(self): def __init__(self):
# init array # init array
self.__mData = [[0] * 4 for i in range(4)] self.data = [[0] * 4 for i in range(4)]
# set to identy # set to identy
self.reset() self.reset()
def _get_raw(self) -> list[list[float]]: def _get_raw(self) -> list[list[float]]:
return self.__mData return self.data
def reset(self) -> None: def reset(self) -> None:
# reset to identy # reset to identy
for i in range(4): for i in range(4):
for j in range(4): for j in range(4):
self.__mData[i][j] = 0.0 self.data[i][j] = 0.0
self.__mData[0][0] = 1.0 self.data[0][0] = 1.0
self.__mData[1][1] = 1.0 self.data[1][1] = 1.0
self.__mData[2][2] = 1.0 self.data[2][2] = 1.0
self.__mData[3][3] = 1.0 self.data[3][3] = 1.0
def from_const(self, cm: ConstVxMatrix) -> None: def from_const(self, cm: ConstVxMatrix) -> None:
( (
self.__mData[0][0], self.__mData[0][1], self.__mData[0][2], self.__mData[0][3], self.data[0][0], self.data[0][1], self.data[0][2], self.data[0][3],
self.__mData[1][0], self.__mData[1][1], self.__mData[1][2], self.__mData[1][3], self.data[1][0], self.data[1][1], self.data[1][2], self.data[1][3],
self.__mData[2][0], self.__mData[2][1], self.__mData[2][2], self.__mData[2][3], self.data[2][0], self.data[2][1], self.data[2][2], self.data[2][3],
self.__mData[3][0], self.__mData[3][1], self.__mData[3][2], self.__mData[3][3] self.data[3][0], self.data[3][1], self.data[3][2], self.data[3][3]
) = cm ) = cm
def to_const(self) -> ConstVxMatrix: def to_const(self) -> ConstVxMatrix:
return ( return (
self.__mData[0][0], self.__mData[0][1], self.__mData[0][2], self.__mData[0][3], self.data[0][0], self.data[0][1], self.data[0][2], self.data[0][3],
self.__mData[1][0], self.__mData[1][1], self.__mData[1][2], self.__mData[1][3], self.data[1][0], self.data[1][1], self.data[1][2], self.data[1][3],
self.__mData[2][0], self.__mData[2][1], self.__mData[2][2], self.__mData[2][3], self.data[2][0], self.data[2][1], self.data[2][2], self.data[2][3],
self.__mData[3][0], self.__mData[3][1], self.__mData[3][2], self.__mData[3][3] self.data[3][0], self.data[3][1], self.data[3][2], self.data[3][3]
) )
class CK_TEXTURE_SAVEOPTIONS(enum.IntEnum): class CK_TEXTURE_SAVEOPTIONS(enum.IntEnum):

View File

@ -21,7 +21,7 @@ public class PythonWriter {
cache.put("CK_ID", "CKID"); cache.put("CK_ID", "CKID");
cache.put("BMFile", "void"); cache.put("BMFile", "void");
cache.put("BMMeshTransition", "void"); cache.put("BMMeshTransition", "void");
cache.put("VxVector3", "VxVector2"); cache.put("VxVector3", "VxVector3");
cache.put("VxVector2", "VxVector2"); cache.put("VxVector2", "VxVector2");
cache.put("VxColor", "VxColor"); cache.put("VxColor", "VxColor");
cache.put("VxMatrix", "VxMatrix"); cache.put("VxMatrix", "VxMatrix");

View File

@ -46,6 +46,7 @@ class bm_VxVector3(ctypes.Structure):
('z', bm_CKFLOAT), ('z', bm_CKFLOAT),
] ]
bm_VxVector3_p = ctypes.POINTER(bm_VxVector3) bm_VxVector3_p = ctypes.POINTER(bm_VxVector3)
bm_VxVector3_pp = ctypes.POINTER(bm_VxVector3_p)
class bm_VxColor(ctypes.Structure): class bm_VxColor(ctypes.Structure):
_fields_ = [ _fields_ = [
('r', bm_CKFLOAT), ('r', bm_CKFLOAT),