1
0

feat: finish fixing for pybmap

This commit is contained in:
2026-02-09 16:38:53 +08:00
parent a30a0a41d7
commit 9917db0399
9 changed files with 2304 additions and 1018 deletions

View File

@@ -10,7 +10,7 @@
<Authors>yyc12345</Authors> <Authors>yyc12345</Authors>
<Description>The C# binding to BMap.</Description> <Description>The C# binding to BMap.</Description>
<Company>BearKidsTeam</Company> <Company>BearKidsTeam</Company>
<PackageLicenseFile>SPDX:MIT</PackageLicenseFile> <PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="$([System.OperatingSystem]::IsWindows())"> <PropertyGroup Condition="$([System.OperatingSystem]::IsWindows())">

View File

@@ -0,0 +1,7 @@
# BMap Bindings
## Test
* `BMAP_FILE_NAME`: The path to the map for loading.
* `BMAP_BALLANCE_DIR`:The path to the Ballance directory for finding textures
* `BMAP_ENCODINGS`: The name of encodings used by BMap for loading map. Multiple encodings is supported by separating them with commas, for example: `cp1252,gbk`.

View File

@@ -3,7 +3,7 @@ name = "pybmap"
version = "0.4.0" version = "0.4.0"
description = "The Python binding to BMap." description = "The Python binding to BMap."
readme = "README.md" readme = "README.md"
license = "SPDX:MIT" license = "MIT"
authors = [{ name = "yyc12345" }] authors = [{ name = "yyc12345" }]
classifiers = ["Private :: Do Not Upload"] classifiers = ["Private :: Do Not Upload"]
requires-python = ">=3.11" requires-python = ">=3.11"

File diff suppressed because it is too large Load Diff

View File

@@ -1,30 +1,36 @@
import ctypes, typing, atexit, enum import ctypes
from . import bmap, virtools_types import typing
import atexit
import enum
from . import bmap
from . import virtools_types
#region Basic Class & Constant Defines #region Basic Class & Constant Defines
g_InvalidPtr: bmap.bm_void_p = bmap.bm_void_p(0) INVALID_PTR: bmap.bm_void_p = bmap.bm_void_p(0)
g_InvalidCKID: int = 0 INVALID_CKID: int = 0
g_BMapEncoding: str = "utf-8" BMAP_ENCODING: str = "utf-8"
def _python_callback(strl: bytes): def _python_callback(strl: bytes):
""" """
The Python type callback for BMFile. The Python type callback for BMFile.
Simply add a prefix when output.
Need a convertion before passing to BMFile. This function simply add a prefix when output.
Extra convertion is required before passing to BMFile FFI function.
""" """
# YYC Remarks: # YYC MARK:
# The passing value to this function is bytes, not bmap.bm_CKSTRING. # The passing value to this function is bytes, not bmap.bm_CKSTRING.
# I think Python do an auto convertion in there. # I think Python do an auto convertion in there.
if strl is not None: if strl is not None:
print(f'[PyBMap] {strl.decode(g_BMapEncoding)}') print(f'[pybmap] {strl.decode(BMAP_ENCODING)}')
_g_RawCallback: bmap.bm_callback = bmap.bm_callback(_python_callback)
RAW_CALLBACK = bmap.bm_callback(_python_callback)
#endregion #endregion
#region Help Functions #region Help Functions
class _Utils: class _utils:
@staticmethod @staticmethod
def raise_out_of_length_exception() -> None: def raise_out_of_length_exception() -> None:
raise bmap.BMapException("The length of given data is too short when assigning struct array.") raise bmap.BMapException("The length of given data is too short when assigning struct array.")
@@ -39,7 +45,7 @@ class _Utils:
pdata[idx] = user_vector[_j] pdata[idx] = user_vector[_j]
idx += 1 idx += 1
except StopIteration: except StopIteration:
_Utils.raise_out_of_length_exception() _utils.raise_out_of_length_exception()
@staticmethod @staticmethod
def _vector_iterator(pdata: typing.Any, item_count: int, factor_count: int) -> typing.Iterator[tuple[typing.Any, ...]]: def _vector_iterator(pdata: typing.Any, item_count: int, factor_count: int) -> typing.Iterator[tuple[typing.Any, ...]]:
@@ -53,39 +59,37 @@ class _Utils:
@staticmethod @staticmethod
def vxvector3_assigner(pvector: bmap.bm_VxVector3_p, count: int, itor: typing.Iterator[virtools_types.VxVector3]) -> None: def vxvector3_assigner(pvector: bmap.bm_VxVector3_p, count: int, itor: typing.Iterator[virtools_types.VxVector3]) -> None:
_Utils._vector_assigner(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 3, map(lambda v: (v.x, v.y, v.z), itor)) _utils._vector_assigner(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 3, map(lambda v: (v.x, v.y, v.z), itor))
@staticmethod @staticmethod
def vxvector3_iterator(pvector: bmap.bm_VxVector3_p, count: int) -> typing.Iterator[virtools_types.VxVector3]: def vxvector3_iterator(pvector: bmap.bm_VxVector3_p, count: int) -> typing.Iterator[virtools_types.VxVector3]:
return map( return map(
lambda v: virtools_types.VxVector3(*v), lambda v: virtools_types.VxVector3(*v),
_Utils._vector_iterator(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 3) _utils._vector_iterator(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 3)
) )
@staticmethod @staticmethod
def vxvector2_assigner(pvector: bmap.bm_VxVector2_p, count: int, itor: typing.Iterator[virtools_types.VxVector2]) -> None: def vxvector2_assigner(pvector: bmap.bm_VxVector2_p, count: int, itor: typing.Iterator[virtools_types.VxVector2]) -> None:
_Utils._vector_assigner(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 2, map(lambda v: (v.x, v.y), itor)) _utils._vector_assigner(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 2, map(lambda v: (v.x, v.y), itor))
@staticmethod @staticmethod
def vxvector2_iterator(pvector: bmap.bm_VxVector2_p, count: int) -> typing.Iterator[virtools_types.VxVector2]: def vxvector2_iterator(pvector: bmap.bm_VxVector2_p, count: int) -> typing.Iterator[virtools_types.VxVector2]:
return map( return map(
lambda v: virtools_types.VxVector2(*v), lambda v: virtools_types.VxVector2(*v),
_Utils._vector_iterator(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 2) _utils._vector_iterator(ctypes.cast(pvector, bmap.bm_CKFLOAT_p), count, 2)
) )
"""! # YYC MARK:
@remarks # bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p is just a type hint.
bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p is just a type hint. # We actually do not need distinguish them in code.
We actually do not need distinguish them in code. # Because the stride when increasing them is decided by their runtime type.
Because the stride when increasing them is decided by their runtime type.
"""
@staticmethod @staticmethod
def ckfaceindices_assigner(pindices: bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p, count: int, itor: typing.Iterator[virtools_types.CKFaceIndices]) -> None: def ckfaceindices_assigner(pindices: bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p, count: int, itor: typing.Iterator[virtools_types.CKFaceIndices]) -> None:
_Utils._vector_assigner(pindices, count, 3, map(lambda v: (v.i1, v.i2, v.i3), itor)) _utils._vector_assigner(pindices, count, 3, map(lambda v: (v.i1, v.i2, v.i3), itor))
@staticmethod @staticmethod
def ckfaceindices_iterator(pindices: bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p, count: int) -> typing.Iterator[virtools_types.CKFaceIndices]: def ckfaceindices_iterator(pindices: bmap.bm_CKWORD_p | bmap.bm_CKDWORD_p, count: int) -> typing.Iterator[virtools_types.CKFaceIndices]:
return map( return map(
lambda v: virtools_types.CKFaceIndices(*v), lambda v: virtools_types.CKFaceIndices(*v),
_Utils._vector_iterator(pindices, count, 3) _utils._vector_iterator(pindices, count, 3)
) )
#endregion #endregion
@@ -122,7 +126,7 @@ class _AbstractPointer():
TEnumType = typing.TypeVar('TEnumType', bound = enum.IntEnum) TEnumType = typing.TypeVar('TEnumType', bound = enum.IntEnum)
TIntegralType = bmap.bm_CKDWORD | bmap.bm_CKWORD | bmap.bm_CKINT | bmap.bm_CKBYTE | bmap.bm_CKID TIntegralType = bmap.bm_CKDWORD | bmap.bm_CKWORD | bmap.bm_CKINT | bmap.bm_CKBYTE | bmap.bm_CKID
TFloatPointType = bmap.bm_CKFLOAT TFloatPointType = bmap.bm_CKFLOAT
TPointerType = typing.TypeVar('TPointerType') TPointerType = typing.TypeVar('TPointerType', bound=ctypes._Pointer)
class _AbstractCKObject(_AbstractPointer): class _AbstractCKObject(_AbstractPointer):
__mCKID: int __mCKID: int
@@ -148,6 +152,7 @@ class _AbstractCKObject(_AbstractPointer):
def __hash__(self) -> int: def __hash__(self) -> int:
return hash((_AbstractPointer.__hash__(self), self.__mCKID)) return hash((_AbstractPointer.__hash__(self), self.__mCKID))
# YYC MARK:
# Convenient Value Getter Setter # Convenient Value Getter Setter
# Focusing on those which widely called types. # Focusing on those which widely called types.
@@ -183,11 +188,11 @@ class _AbstractCKObject(_AbstractPointer):
data: bmap.bm_CKSTRING = bmap.bm_CKSTRING() data: bmap.bm_CKSTRING = bmap.bm_CKSTRING()
getter_(self._get_pointer(), self._get_ckid(), ctypes.byref(data)) getter_(self._get_pointer(), self._get_ckid(), ctypes.byref(data))
if data.value is None: return None if data.value is None: return None
else: return data.value.decode(g_BMapEncoding) else: return data.value.decode(BMAP_ENCODING)
def _set_str_value(self, setter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, bmap.bm_CKSTRING], bmap.bm_bool], data_: str | None) -> None: def _set_str_value(self, setter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, bmap.bm_CKSTRING], bmap.bm_bool], data_: str | None) -> None:
data: bmap.bm_CKSTRING data: bmap.bm_CKSTRING
if data_ is None: data = bmap.bm_CKSTRING(0) if data_ is None: data = bmap.bm_CKSTRING(0)
else: data = bmap.bm_CKSTRING(data_.encode(g_BMapEncoding)) else: data = bmap.bm_CKSTRING(data_.encode(BMAP_ENCODING))
setter_(self._get_pointer(), self._get_ckid(), data) setter_(self._get_pointer(), self._get_ckid(), data)
def _set_vxcolor_value(self, def _set_vxcolor_value(self,
@@ -209,7 +214,7 @@ class _AbstractCKObject(_AbstractPointer):
return ret return ret
def _get_pointer_value(self, ptr_type_: type[TPointerType], getter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, typing.Any], bmap.bm_bool]) -> TPointerType: def _get_pointer_value(self, ptr_type_: type[TPointerType], getter_: typing.Callable[[bmap.bm_void_p, bmap.bm_CKID, typing.Any], bmap.bm_bool]) -> TPointerType:
data = ptr_type_() data: TPointerType = ptr_type_()
getter_(self._get_pointer(), self._get_ckid(), ctypes.byref(data)) getter_(self._get_pointer(), self._get_ckid(), ctypes.byref(data))
return data return data
@@ -234,18 +239,16 @@ if is_bmap_available():
#region Real Type Defines #region Real Type Defines
"""! # YYC MARK:
@remarks # BMFileReader, BMFileWriter, and BMMeshTrans can be create by given constructor.
BMFileReader, BMFileWriter, and BMMeshTrans can be create by given constructor. # But they must be destroyed by calling dispose(). Otherwise it may cause memory leak.
But they must be destroyed by calling dispose(). Otherwise it may cause memory leak. # You also can use python `with` statement to achieve this automatically.
You also can use python `with` statement to achieve this automatically. #
# BMObject, BMTexture, BMMaterial, BMMesh, and BM3dObject should NOT be constructed from given constructor.
BMObject, BMTexture, BMMaterial, BMMesh, and BM3dObject should NOT be constructed from given constructor. # They must be obtained from BMFileReader, BMFileWriter, and BMMeshTrans.
They must be obtained from BMFileReader, BMFileWriter, and BMMeshTrans. # Thus BMObject, BMTexture, BMMaterial, BMMesh, and BM3dObject also do not need to free
Thus BMObject, BMTexture, BMMaterial, BMMesh, and BM3dObject also do not need to free # because these resources are sotred in BMFileReader, BMFileWriter, and BMMeshTrans.
because these resources are sotred in BMFileReader, BMFileWriter, and BMMeshTrans. # We just provide them as a visitor.
We just provide them as a visitor.
"""
class BMObject(_AbstractCKObject): class BMObject(_AbstractCKObject):
def get_name(self) -> str | None: def get_name(self) -> str | None:
@@ -258,10 +261,10 @@ class BMTexture(BMObject):
return self._get_str_value(bmap.BMTexture_GetFileName) return self._get_str_value(bmap.BMTexture_GetFileName)
def load_image(self, filepath: str) -> None: def load_image(self, filepath: str) -> None:
filename: bmap.bm_CKSTRING = bmap.bm_CKSTRING(filepath.encode(g_BMapEncoding)) filename: bmap.bm_CKSTRING = bmap.bm_CKSTRING(filepath.encode(BMAP_ENCODING))
bmap.BMTexture_LoadImage(self._get_pointer(), self._get_ckid(), filename) bmap.BMTexture_LoadImage(self._get_pointer(), self._get_ckid(), filename)
def save_image(self, filepath: str) -> None: def save_image(self, filepath: str) -> None:
filename: bmap.bm_CKSTRING = bmap.bm_CKSTRING(filepath.encode(g_BMapEncoding)) filename: bmap.bm_CKSTRING = bmap.bm_CKSTRING(filepath.encode(BMAP_ENCODING))
bmap.BMTexture_SaveImage(self._get_pointer(), self._get_ckid(), filename) bmap.BMTexture_SaveImage(self._get_pointer(), self._get_ckid(), filename)
def get_save_options(self) -> virtools_types.CK_TEXTURE_SAVEOPTIONS: def get_save_options(self) -> virtools_types.CK_TEXTURE_SAVEOPTIONS:
@@ -299,11 +302,11 @@ class BMMaterial(BMObject):
def get_texture(self) -> BMTexture | None: def get_texture(self) -> BMTexture | None:
objid: bmap.bm_CKID = bmap.bm_CKID() objid: bmap.bm_CKID = bmap.bm_CKID()
bmap.BMMaterial_GetTexture(self._get_pointer(), self._get_ckid(), ctypes.byref(objid)) bmap.BMMaterial_GetTexture(self._get_pointer(), self._get_ckid(), ctypes.byref(objid))
if objid.value == g_InvalidCKID: return None if objid.value == INVALID_CKID: return None
else: return BMTexture(self._get_pointer(), objid) else: return BMTexture(self._get_pointer(), objid)
def set_texture(self, tex_: BMTexture | None) -> None: def set_texture(self, tex_: BMTexture | None) -> None:
objid: bmap.bm_CKID = bmap.bm_CKID(g_InvalidCKID) objid: bmap.bm_CKID = bmap.bm_CKID(INVALID_CKID)
if tex_ is not None: objid = tex_._get_ckid() if tex_ is not None: objid = tex_._get_ckid()
bmap.BMMaterial_SetTexture(self._get_pointer(), self._get_ckid(), objid) bmap.BMMaterial_SetTexture(self._get_pointer(), self._get_ckid(), objid)
@@ -398,25 +401,25 @@ class BMMesh(BMObject):
def get_vertex_positions(self) -> typing.Iterator[virtools_types.VxVector3]: def get_vertex_positions(self) -> typing.Iterator[virtools_types.VxVector3]:
# get raw pointer and return # get raw pointer and return
raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexPositions) raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexPositions)
return _Utils.vxvector3_iterator(raw_vector, self.get_vertex_count()) return _utils.vxvector3_iterator(raw_vector, self.get_vertex_count())
def set_vertex_positions(self, itor: typing.Iterator[virtools_types.VxVector3]) -> None: def set_vertex_positions(self, itor: typing.Iterator[virtools_types.VxVector3]) -> None:
# get raw float pointer and assign # get raw float pointer and assign
raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexPositions) raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexPositions)
_Utils.vxvector3_assigner(raw_vector, self.get_vertex_count(), itor) _utils.vxvector3_assigner(raw_vector, self.get_vertex_count(), itor)
def get_vertex_normals(self) -> typing.Iterator[virtools_types.VxVector3]: def get_vertex_normals(self) -> typing.Iterator[virtools_types.VxVector3]:
raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexNormals) raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexNormals)
return _Utils.vxvector3_iterator(raw_vector, self.get_vertex_count()) return _utils.vxvector3_iterator(raw_vector, self.get_vertex_count())
def set_vertex_normals(self, itor: typing.Iterator[virtools_types.VxVector3]) -> None: def set_vertex_normals(self, itor: typing.Iterator[virtools_types.VxVector3]) -> None:
raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexNormals) raw_vector = self._get_pointer_value(bmap.bm_VxVector3_p, bmap.BMMesh_GetVertexNormals)
_Utils.vxvector3_assigner(raw_vector, self.get_vertex_count(), itor) _utils.vxvector3_assigner(raw_vector, self.get_vertex_count(), itor)
def get_vertex_uvs(self) -> typing.Iterator[virtools_types.VxVector2]: def get_vertex_uvs(self) -> typing.Iterator[virtools_types.VxVector2]:
raw_vector = self._get_pointer_value(bmap.bm_VxVector2_p, bmap.BMMesh_GetVertexUVs) raw_vector = self._get_pointer_value(bmap.bm_VxVector2_p, bmap.BMMesh_GetVertexUVs)
return _Utils.vxvector2_iterator(raw_vector, self.get_vertex_count()) return _utils.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 = self._get_pointer_value(bmap.bm_VxVector2_p, bmap.BMMesh_GetVertexUVs) raw_vector = self._get_pointer_value(bmap.bm_VxVector2_p, bmap.BMMesh_GetVertexUVs)
_Utils.vxvector2_assigner(raw_vector, self.get_vertex_count(), itor) _utils.vxvector2_assigner(raw_vector, self.get_vertex_count(), itor)
def get_face_count(self) -> int: def get_face_count(self) -> int:
return self._get_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_GetFaceCount) return self._get_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_GetFaceCount)
@@ -425,10 +428,10 @@ class BMMesh(BMObject):
def get_face_indices(self) -> typing.Iterator[virtools_types.CKFaceIndices]: def get_face_indices(self) -> typing.Iterator[virtools_types.CKFaceIndices]:
raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceIndices) raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceIndices)
return _Utils.ckfaceindices_iterator(raw_idx, self.get_face_count()) return _utils.ckfaceindices_iterator(raw_idx, self.get_face_count())
def set_face_indices(self, itor: typing.Iterator[virtools_types.CKFaceIndices]) -> None: def set_face_indices(self, itor: typing.Iterator[virtools_types.CKFaceIndices]) -> None:
raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceIndices) raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceIndices)
_Utils.ckfaceindices_assigner(raw_idx, self.get_face_count(), itor) _utils.ckfaceindices_assigner(raw_idx, self.get_face_count(), itor)
def get_face_material_slot_indexs(self) -> typing.Iterator[int]: def get_face_material_slot_indexs(self) -> typing.Iterator[int]:
raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceMaterialSlotIndexs) raw_idx = self._get_pointer_value(bmap.bm_CKWORD_p, bmap.BMMesh_GetFaceMaterialSlotIndexs)
@@ -441,7 +444,7 @@ class BMMesh(BMObject):
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)
except StopIteration: except StopIteration:
_Utils.raise_out_of_length_exception() _utils.raise_out_of_length_exception()
def get_material_slot_count(self) -> int: def get_material_slot_count(self) -> int:
return self._get_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_GetMaterialSlotCount) return self._get_integral_value(bmap.bm_CKDWORD, bmap.BMMesh_GetMaterialSlotCount)
@@ -454,7 +457,7 @@ class BMMesh(BMObject):
for i in range(self.get_material_slot_count()): for i in range(self.get_material_slot_count()):
idx.value = i idx.value = i
bmap.BMMesh_GetMaterialSlot(self._get_pointer(), self._get_ckid(), idx, ctypes.byref(mtlid)) bmap.BMMesh_GetMaterialSlot(self._get_pointer(), self._get_ckid(), idx, ctypes.byref(mtlid))
if mtlid.value == g_InvalidCKID: if mtlid.value == INVALID_CKID:
yield None yield None
else: else:
yield BMMaterial(self._get_pointer(), mtlid) yield BMMaterial(self._get_pointer(), mtlid)
@@ -468,13 +471,13 @@ class BMMesh(BMObject):
# analyze mtl item # analyze mtl item
mtlobj: BMMaterial | None = next(itor) mtlobj: BMMaterial | None = next(itor)
if mtlobj is None: if mtlobj is None:
mtlid.value = g_InvalidCKID mtlid.value = INVALID_CKID
else: else:
mtlid = mtlobj._get_ckid() mtlid = mtlobj._get_ckid()
# set # set
bmap.BMMesh_SetMaterialSlot(self._get_pointer(), self._get_ckid(), idx, mtlid) bmap.BMMesh_SetMaterialSlot(self._get_pointer(), self._get_ckid(), idx, mtlid)
except StopIteration: except StopIteration:
_Utils.raise_out_of_length_exception() _utils.raise_out_of_length_exception()
class BM3dEntity(BMObject): class BM3dEntity(BMObject):
def get_world_matrix(self) -> virtools_types.VxMatrix: def get_world_matrix(self) -> virtools_types.VxMatrix:
@@ -494,13 +497,13 @@ class BM3dEntity(BMObject):
def get_current_mesh(self) -> BMMesh | None: def get_current_mesh(self) -> BMMesh | None:
ckid: bmap.bm_CKID = bmap.bm_CKID() ckid: bmap.bm_CKID = bmap.bm_CKID()
bmap.BM3dEntity_GetCurrentMesh(self._get_pointer(), self._get_ckid(), ctypes.byref(ckid)) bmap.BM3dEntity_GetCurrentMesh(self._get_pointer(), self._get_ckid(), ctypes.byref(ckid))
if ckid.value == g_InvalidCKID: if ckid.value == INVALID_CKID:
return None return None
else: else:
return BMMesh(self._get_pointer(), ckid) return BMMesh(self._get_pointer(), ckid)
def set_current_mesh(self, mesh: BMMesh | None) -> None: def set_current_mesh(self, mesh: BMMesh | None) -> None:
ckid: bmap.bm_CKID = bmap.bm_CKID(g_InvalidCKID) ckid: bmap.bm_CKID = bmap.bm_CKID(INVALID_CKID)
if mesh is not None: if mesh is not None:
ckid = mesh._get_ckid() ckid = mesh._get_ckid()
bmap.BM3dEntity_SetCurrentMesh(self._get_pointer(), self._get_ckid(), ckid) bmap.BM3dEntity_SetCurrentMesh(self._get_pointer(), self._get_ckid(), ckid)
@@ -558,6 +561,43 @@ class BMLight(BM3dEntity):
class BMTargetLight(BMLight): class BMTargetLight(BMLight):
pass pass
class BMCamera(BM3dEntity):
def get_projection_type(self) -> virtools_types.CK_CAMERA_PROJECTION:
return self._get_enum_value(virtools_types.CK_CAMERA_PROJECTION, bmap.BMCamera_GetProjectionType)
def set_type(self, data_: virtools_types.CK_CAMERA_PROJECTION) -> None:
self._set_enum_value(bmap.BMCamera_SetProjectionType, data_)
def get_orthographic_zoom(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_GetOrthographicZoom)
def set_orthographic_zoom(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_SetOrthographicZoom, val_)
def get_front_plane(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_GetFrontPlane)
def set_front_plane(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_SetFrontPlane, val_)
def get_back_plane(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_GetBackPlane)
def set_back_plane(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_SetBackPlane, val_)
def get_fov(self) -> float:
return self._get_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_GetFov)
def set_fov(self, val_: float) -> None:
self._set_float_point_value(bmap.bm_CKFLOAT, bmap.BMCamera_SetFov, val_)
def get_aspect_ratio(self) -> tuple[int, int]:
width = bmap.bm_CKDWORD()
height = bmap.bm_CKDWORD()
bmap.BMCamera_GetAspectRatio(self._get_pointer(), self._get_ckid(), ctypes.byref(width), ctypes.byref(height))
return (width.value, height.value)
def set_aspect_ratio(self, width_: int, height_: int) -> None:
width = bmap.bm_CKDWORD(width_)
height = bmap.bm_CKDWORD(height_)
bmap.BMCamera_SetAspectRatio(self._get_pointer(), self._get_ckid(), width, height)
class BMTargetCamera(BMCamera):
pass
class BMGroup(BMObject): class BMGroup(BMObject):
def add_object(self, member: BM3dObject) -> None: def add_object(self, member: BM3dObject) -> None:
bmap.BMGroup_AddObject(self._get_pointer(), self._get_ckid(), member._get_ckid()) bmap.BMGroup_AddObject(self._get_pointer(), self._get_ckid(), member._get_ckid())
@@ -578,19 +618,19 @@ class BMGroup(BMObject):
yield BM3dObject(self._get_pointer(), retid) yield BM3dObject(self._get_pointer(), retid)
class BMFileReader(_AbstractPointer): class BMFileReader(_AbstractPointer):
def __init__(self, file_name_: str, temp_folder_: str, texture_folder_: str, encodings_: tuple[str]): def __init__(self, file_name_: str, temp_folder_: str, texture_folder_: str, encodings_: tuple[str, ...]):
# create param # create param
file_name: bmap.bm_CKSTRING = bmap.bm_CKSTRING(file_name_.encode(g_BMapEncoding)) file_name: bmap.bm_CKSTRING = bmap.bm_CKSTRING(file_name_.encode(BMAP_ENCODING))
temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.encode(g_BMapEncoding)) temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.encode(BMAP_ENCODING))
texture_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(texture_folder_.encode(g_BMapEncoding)) texture_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(texture_folder_.encode(BMAP_ENCODING))
encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_)) encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_))
encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))( encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))(
*(strl.encode(g_BMapEncoding) for strl in encodings_) *(strl.encode(BMAP_ENCODING) for strl in encodings_)
) )
out_file: bmap.bm_void_p = bmap.bm_void_p() out_file: bmap.bm_void_p = bmap.bm_void_p()
# exec # exec
bmap.BMFile_Load( bmap.BMFile_Load(
file_name, temp_folder, texture_folder, _g_RawCallback, file_name, temp_folder, texture_folder, RAW_CALLBACK,
encoding_count, encodings, encoding_count, encodings,
ctypes.byref(out_file) ctypes.byref(out_file)
) )
@@ -606,7 +646,7 @@ class BMFileReader(_AbstractPointer):
def dispose(self) -> None: def dispose(self) -> None:
if self._is_valid(): if self._is_valid():
bmap.BMFile_Free(self._get_pointer()) bmap.BMFile_Free(self._get_pointer())
self._set_pointer(g_InvalidPtr) self._set_pointer(INVALID_PTR)
def __get_ckobject_count(self, def __get_ckobject_count(self,
count_getter: typing.Callable[[bmap.bm_void_p, bmap.bm_CKDWORD_p], bmap.bm_bool]) -> int: count_getter: typing.Callable[[bmap.bm_void_p, bmap.bm_CKDWORD_p], bmap.bm_bool]) -> int:
@@ -655,20 +695,25 @@ class BMFileReader(_AbstractPointer):
return self.__get_ckobject_count(bmap.BMFile_GetTargetLightCount) return self.__get_ckobject_count(bmap.BMFile_GetTargetLightCount)
def get_target_lights(self) -> typing.Iterator[BMTargetLight]: def get_target_lights(self) -> typing.Iterator[BMTargetLight]:
return self.__get_ckobjects(BMTargetLight, bmap.BMFile_GetTargetLightCount, bmap.BMFile_GetTargetLight) return self.__get_ckobjects(BMTargetLight, bmap.BMFile_GetTargetLightCount, bmap.BMFile_GetTargetLight)
def get_target_camera_count(self) -> int:
return self.__get_ckobject_count(bmap.BMFile_GetTargetCameraCount)
def get_target_cameras(self) -> typing.Iterator[BMTargetCamera]:
return self.__get_ckobjects(BMTargetCamera, bmap.BMFile_GetTargetCameraCount, bmap.BMFile_GetTargetCamera)
class BMFileWriter(_AbstractPointer): class BMFileWriter(_AbstractPointer):
def __init__(self, temp_folder_: str, texture_folder_: str, encodings_: tuple[str]): def __init__(self, temp_folder_: str, texture_folder_: str, encodings_: tuple[str, ...]):
# create param # create param
temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.encode(g_BMapEncoding)) temp_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(temp_folder_.encode(BMAP_ENCODING))
texture_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(texture_folder_.encode(g_BMapEncoding)) texture_folder: bmap.bm_CKSTRING = bmap.bm_CKSTRING(texture_folder_.encode(BMAP_ENCODING))
encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_)) encoding_count: bmap.bm_CKDWORD = bmap.bm_CKDWORD(len(encodings_))
encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))( encodings: ctypes.Array = (bmap.bm_CKSTRING * len(encodings_))(
*(strl.encode(g_BMapEncoding) for strl in encodings_) *(strl.encode(BMAP_ENCODING) for strl in encodings_)
) )
out_file: bmap.bm_void_p = bmap.bm_void_p() out_file: bmap.bm_void_p = bmap.bm_void_p()
# exec # exec
bmap.BMFile_Create( bmap.BMFile_Create(
temp_folder, texture_folder, _g_RawCallback, temp_folder, texture_folder, RAW_CALLBACK,
encoding_count, encodings, encoding_count, encodings,
ctypes.byref(out_file) ctypes.byref(out_file)
) )
@@ -683,7 +728,7 @@ class BMFileWriter(_AbstractPointer):
def save(self, file_name_: str, texture_save_opt_: virtools_types.CK_TEXTURE_SAVEOPTIONS, use_compress_: bool, compress_level_: int) -> None: def save(self, file_name_: str, texture_save_opt_: virtools_types.CK_TEXTURE_SAVEOPTIONS, use_compress_: bool, compress_level_: int) -> None:
# create param # create param
file_name: bmap.bm_CKSTRING = bmap.bm_CKSTRING(file_name_.encode(g_BMapEncoding)) file_name: bmap.bm_CKSTRING = bmap.bm_CKSTRING(file_name_.encode(BMAP_ENCODING))
texture_save_opt: bmap.bm_enum = bmap.bm_enum(texture_save_opt_.value) texture_save_opt: bmap.bm_enum = bmap.bm_enum(texture_save_opt_.value)
use_compress: bmap.bm_bool = bmap.bm_bool(use_compress_) use_compress: bmap.bm_bool = bmap.bm_bool(use_compress_)
compress_level: bmap.bm_CKINT = bmap.bm_CKINT(compress_level_) compress_level: bmap.bm_CKINT = bmap.bm_CKINT(compress_level_)
@@ -693,7 +738,7 @@ class BMFileWriter(_AbstractPointer):
def dispose(self) -> None: def dispose(self) -> None:
if self._is_valid(): if self._is_valid():
bmap.BMFile_Free(self._get_pointer()) bmap.BMFile_Free(self._get_pointer())
self._set_pointer(g_InvalidPtr) self._set_pointer(INVALID_PTR)
def __create_ckobject(self, def __create_ckobject(self,
class_type: type[TCKObject], class_type: type[TCKObject],
@@ -717,6 +762,8 @@ class BMFileWriter(_AbstractPointer):
return self.__create_ckobject(BMGroup, bmap.BMFile_CreateGroup) return self.__create_ckobject(BMGroup, bmap.BMFile_CreateGroup)
def create_target_light(self) -> BMTargetLight: def create_target_light(self) -> BMTargetLight:
return self.__create_ckobject(BMTargetLight, bmap.BMFile_CreateTargetLight) return self.__create_ckobject(BMTargetLight, bmap.BMFile_CreateTargetLight)
def create_target_camera(self) -> BMTargetCamera:
return self.__create_ckobject(BMTargetCamera, bmap.BMFile_CreateTargetCamera)
class BMMeshTrans(_AbstractPointer): class BMMeshTrans(_AbstractPointer):
def __init__(self): def __init__(self):
@@ -733,7 +780,7 @@ class BMMeshTrans(_AbstractPointer):
def dispose(self) -> None: def dispose(self) -> None:
if self._is_valid(): if self._is_valid():
bmap.BMMeshTrans_Delete(self._get_pointer()) bmap.BMMeshTrans_Delete(self._get_pointer())
self._set_pointer(g_InvalidPtr) self._set_pointer(INVALID_PTR)
def parse(self, objmesh: BMMesh) -> None: def parse(self, objmesh: BMMesh) -> None:
bmap.BMMeshTrans_Parse(self._get_pointer(), objmesh._get_pointer(), objmesh._get_ckid()) bmap.BMMeshTrans_Parse(self._get_pointer(), objmesh._get_pointer(), objmesh._get_ckid())
@@ -746,7 +793,7 @@ class BMMeshTrans(_AbstractPointer):
raw_vector: bmap.bm_VxVector3_p = bmap.bm_VxVector3_p() raw_vector: bmap.bm_VxVector3_p = bmap.bm_VxVector3_p()
bmap.BMMeshTrans_PrepareVertex(self._get_pointer(), ctypes.byref(raw_vector)) bmap.BMMeshTrans_PrepareVertex(self._get_pointer(), ctypes.byref(raw_vector))
# set by pointer # set by pointer
_Utils.vxvector3_assigner(raw_vector, count, itor) _utils.vxvector3_assigner(raw_vector, count, itor)
def prepare_normal(self, count: int, itor: typing.Iterator[virtools_types.VxVector3]) -> None: def prepare_normal(self, count: int, itor: typing.Iterator[virtools_types.VxVector3]) -> None:
csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count) csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count)
@@ -755,7 +802,7 @@ class BMMeshTrans(_AbstractPointer):
raw_vector: bmap.bm_VxVector3_p = bmap.bm_VxVector3_p() raw_vector: bmap.bm_VxVector3_p = bmap.bm_VxVector3_p()
bmap.BMMeshTrans_PrepareNormal(self._get_pointer(), ctypes.byref(raw_vector)) bmap.BMMeshTrans_PrepareNormal(self._get_pointer(), ctypes.byref(raw_vector))
_Utils.vxvector3_assigner(raw_vector, count, itor) _utils.vxvector3_assigner(raw_vector, count, itor)
def prepare_uv(self, count: int, itor: typing.Iterator[virtools_types.VxVector2]) -> None: def prepare_uv(self, count: int, itor: typing.Iterator[virtools_types.VxVector2]) -> None:
csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count) csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count)
@@ -764,7 +811,7 @@ class BMMeshTrans(_AbstractPointer):
raw_vector: bmap.bm_VxVector2_p = bmap.bm_VxVector2_p() raw_vector: bmap.bm_VxVector2_p = bmap.bm_VxVector2_p()
bmap.BMMeshTrans_PrepareUV(self._get_pointer(), ctypes.byref(raw_vector)) bmap.BMMeshTrans_PrepareUV(self._get_pointer(), ctypes.byref(raw_vector))
_Utils.vxvector2_assigner(raw_vector, count, itor) _utils.vxvector2_assigner(raw_vector, count, itor)
def prepare_mtl_slot(self, count: int, itor: typing.Iterator[BMMaterial | None]) -> None: def prepare_mtl_slot(self, count: int, itor: typing.Iterator[BMMaterial | None]) -> None:
csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count) csize: bmap.bm_CKDWORD = bmap.bm_CKDWORD(count)
@@ -777,12 +824,12 @@ class BMMeshTrans(_AbstractPointer):
for _ in range(count): for _ in range(count):
usermtl: BMMaterial | None = next(itor) usermtl: BMMaterial | None = next(itor)
if usermtl is None: if usermtl is None:
raw_ckid[idx] = g_InvalidCKID raw_ckid[idx] = INVALID_CKID
else: else:
raw_ckid[idx] = usermtl._get_ckid().value raw_ckid[idx] = usermtl._get_ckid().value
idx += 1 idx += 1
except StopIteration: except StopIteration:
_Utils.raise_out_of_length_exception() _utils.raise_out_of_length_exception()
def prepare_face(self, def prepare_face(self,
count: int, count: int,
@@ -806,9 +853,9 @@ class BMMeshTrans(_AbstractPointer):
# iterate and assign # iterate and assign
# assigne triple indices # assigne triple indices
_Utils.ckfaceindices_assigner(raw_vec_idx, count, vec_idx) _utils.ckfaceindices_assigner(raw_vec_idx, count, vec_idx)
_Utils.ckfaceindices_assigner(raw_nml_idx, count, nml_idx) _utils.ckfaceindices_assigner(raw_nml_idx, count, nml_idx)
_Utils.ckfaceindices_assigner(raw_uv_idx, count, uv_idx) _utils.ckfaceindices_assigner(raw_uv_idx, count, uv_idx)
# assign mtl index # assign mtl index
try: try:
idx: int = 0 idx: int = 0
@@ -816,6 +863,6 @@ class BMMeshTrans(_AbstractPointer):
raw_mtl_idx[idx] = next(mtl_idx) raw_mtl_idx[idx] = next(mtl_idx)
idx += 1 idx += 1
except StopIteration: except StopIteration:
_Utils.raise_out_of_length_exception() _utils.raise_out_of_length_exception()
#endregion #endregion

View File

@@ -1,4 +1,4 @@
import typing, enum import enum
ConstVxVector2 = tuple[float, float] ConstVxVector2 = tuple[float, float]
ConstVxVector3 = tuple[float, float, float] ConstVxVector3 = tuple[float, float, float]
@@ -175,153 +175,250 @@ class VxMatrix():
) )
class CK_TEXTURE_SAVEOPTIONS(enum.IntEnum): class CK_TEXTURE_SAVEOPTIONS(enum.IntEnum):
"""! """
Specify the way textures or sprites will be saved Specify the way textures or sprites will be saved
""" """
CKTEXTURE_RAWDATA = 0 ##< Save raw data inside file. The bitmap is saved in a raw 32 bit per pixel format. CKTEXTURE_RAWDATA = 0
CKTEXTURE_EXTERNAL = 1 ##< Store only the file name for the texture. The bitmap file must be present in the bitmap paths when loading the composition. """Save raw data inside file. The bitmap is saved in a raw 32 bit per pixel format."""
CKTEXTURE_IMAGEFORMAT = 2 ##< Save using format specified. The bitmap data will be converted to the specified format by the correspondant bitmap plugin and saved inside file. CKTEXTURE_EXTERNAL = 1
CKTEXTURE_USEGLOBAL = 3 ##< Use Global settings, that is the settings given with CKContext::SetGlobalImagesSaveOptions. (Not valid when using CKContext::SetImagesSaveOptions). """Store only the file name for the texture. The bitmap file must be present in the bitmap pathswhen loading the composition."""
CKTEXTURE_INCLUDEORIGINALFILE = 4 ##< Insert original image file inside CMO file. The bitmap file that was used originally for the texture or sprite will be append to the composition file and extracted when the file is loaded. CKTEXTURE_IMAGEFORMAT = 2
"""Save using format specified. The bitmap data will be converted to thespecified format by the correspondant bitmap plugin and saved inside file."""
CKTEXTURE_USEGLOBAL = 3
"""Use Global settings, that is the settings given with CKContext::SetGlobalImagesSaveOptions. (Not valid when using CKContext::SetImagesSaveOptions)."""
CKTEXTURE_INCLUDEORIGINALFILE = 4
"""Insert original image file inside CMO file. The bitmap file thatwas used originally for the texture or sprite will be append tothe composition file and extracted when the file is loaded."""
class VX_PIXELFORMAT(enum.IntEnum): class VX_PIXELFORMAT(enum.IntEnum):
"""! """
Pixel format types. Pixel format types.
""" """
#UNKNOWN_PF = 0 ##< Unknown pixel format # UNKNOWN_PF = 0
_32_ARGB8888 = 1 ##< 32-bit ARGB pixel format with alpha # """Unknown pixel format"""
_32_RGB888 = 2 ##< 32-bit RGB pixel format without alpha _32_ARGB8888 = 1
_24_RGB888 = 3 ##< 24-bit RGB pixel format """32-bit ARGB pixel format with alpha"""
_16_RGB565 = 4 ##< 16-bit RGB pixel format _32_RGB888 = 2
_16_RGB555 = 5 ##< 16-bit RGB pixel format (5 bits per color) """32-bit RGB pixel format without alpha"""
_16_ARGB1555 = 6 ##< 16-bit ARGB pixel format (5 bits per color + 1 bit for alpha) _24_RGB888 = 3
_16_ARGB4444 = 7 ##< 16-bit ARGB pixel format (4 bits per color) """24-bit RGB pixel format"""
_8_RGB332 = 8 ##< 8-bit RGB pixel format _16_RGB565 = 4
_8_ARGB2222 = 9 ##< 8-bit ARGB pixel format """16-bit RGB pixel format"""
_32_ABGR8888 = 10 ##< 32-bit ABGR pixel format _16_RGB555 = 5
_32_RGBA8888 = 11 ##< 32-bit RGBA pixel format """16-bit RGB pixel format (5 bits per color)"""
_32_BGRA8888 = 12 ##< 32-bit BGRA pixel format _16_ARGB1555 = 6
_32_BGR888 = 13 ##< 32-bit BGR pixel format """16-bit ARGB pixel format (5 bits per color + 1 bit for alpha)"""
_24_BGR888 = 14 ##< 24-bit BGR pixel format _16_ARGB4444 = 7
_16_BGR565 = 15 ##< 16-bit BGR pixel format """16-bit ARGB pixel format (4 bits per color)"""
_16_BGR555 = 16 ##< 16-bit BGR pixel format (5 bits per color) _8_RGB332 = 8
_16_ABGR1555 = 17 ##< 16-bit ABGR pixel format (5 bits per color + 1 bit for alpha) """8-bit RGB pixel format"""
_16_ABGR4444 = 18 ##< 16-bit ABGR pixel format (4 bits per color) _8_ARGB2222 = 9
_DXT1 = 19 ##< S3/DirectX Texture Compression 1 """8-bit ARGB pixel format"""
_DXT2 = 20 ##< S3/DirectX Texture Compression 2 _32_ABGR8888 = 10
_DXT3 = 21 ##< S3/DirectX Texture Compression 3 """32-bit ABGR pixel format"""
_DXT4 = 22 ##< S3/DirectX Texture Compression 4 _32_RGBA8888 = 11
_DXT5 = 23 ##< S3/DirectX Texture Compression 5 """32-bit RGBA pixel format"""
_16_V8U8 = 24 ##< 16-bit Bump Map format format (8 bits per color) _32_BGRA8888 = 12
_32_V16U16 = 25 ##< 32-bit Bump Map format format (16 bits per color) """32-bit BGRA pixel format"""
_16_L6V5U5 = 26 ##< 16-bit Bump Map format format with luminance _32_BGR888 = 13
_32_X8L8V8U8 = 27 ##< 32-bit Bump Map format format with luminance """32-bit BGR pixel format"""
_8_ABGR8888_CLUT = 28 ##< 8 bits indexed CLUT (ABGR) _24_BGR888 = 14
_8_ARGB8888_CLUT = 29 ##< 8 bits indexed CLUT (ARGB) """24-bit BGR pixel format"""
_4_ABGR8888_CLUT = 30 ##< 4 bits indexed CLUT (ABGR) _16_BGR565 = 15
_4_ARGB8888_CLUT = 31 ##< 4 bits indexed CLUT (ARGB) """16-bit BGR pixel format"""
_16_BGR555 = 16
"""16-bit BGR pixel format (5 bits per color)"""
_16_ABGR1555 = 17
"""16-bit ABGR pixel format (5 bits per color + 1 bit for alpha)"""
_16_ABGR4444 = 18
"""16-bit ABGR pixel format (4 bits per color)"""
_DXT1 = 19
"""S3/DirectX Texture Compression 1"""
_DXT2 = 20
"""S3/DirectX Texture Compression 2"""
_DXT3 = 21
"""S3/DirectX Texture Compression 3"""
_DXT4 = 22
"""S3/DirectX Texture Compression 4"""
_DXT5 = 23
"""S3/DirectX Texture Compression 5"""
_16_V8U8 = 24
"""16-bit Bump Map format format (8 bits per color)"""
_32_V16U16 = 25
"""32-bit Bump Map format format (16 bits per color)"""
_16_L6V5U5 = 26
"""16-bit Bump Map format format with luminance"""
_32_X8L8V8U8 = 27
"""32-bit Bump Map format format with luminance"""
_8_ABGR8888_CLUT = 28
"""8 bits indexed CLUT (ABGR)"""
_8_ARGB8888_CLUT = 29
"""8 bits indexed CLUT (ARGB)"""
_4_ABGR8888_CLUT = 30
"""4 bits indexed CLUT (ABGR)"""
_4_ARGB8888_CLUT = 31
"""4 bits indexed CLUT (ARGB)"""
class VXLIGHT_TYPE(enum.IntEnum): class VXLIGHT_TYPE(enum.IntEnum):
"""!
Light type
""" """
VX_LIGHTPOINT = 1 ##< The Light is a point of light Light type.
VX_LIGHTSPOT = 2 ##< The light is a spotlight """
VX_LIGHTDIREC = 3 ##< The light is directional light : Lights comes from an infinite point so only direction of light can be given VX_LIGHTPOINT = 1
#VX_LIGHTPARA = 4 ##< Obsolete, do not use """The Light is a point of light"""
VX_LIGHTSPOT = 2
"""The light is a spotlight"""
VX_LIGHTDIREC = 3
"""The light is directional light : Lights comes from an infinite point so only direction of light can be given"""
# VX_LIGHTPARA = 4
# """Obsolete, do not use"""
class VXTEXTURE_BLENDMODE(enum.IntEnum): class VXTEXTURE_BLENDMODE(enum.IntEnum):
"""! """
Blend Mode Flags Blend Mode Flags
""" """
VXTEXTUREBLEND_DECAL = 1 ##< Texture replace any material information VXTEXTUREBLEND_DECAL = 1
VXTEXTUREBLEND_MODULATE = 2 ##< Texture and material are combine. Alpha information of the texture replace material alpha component. """Texture replace any material information"""
VXTEXTUREBLEND_DECALALPHA = 3 ##< Alpha information in the texture specify how material and texture are combined. Alpha information of the texture replace material alpha component. VXTEXTUREBLEND_MODULATE = 2
VXTEXTUREBLEND_MODULATEALPHA = 4 ##< Alpha information in the texture specify how material and texture are combined """Texture and material are combine. Alpha information of the texture replace material alpha component."""
VXTEXTUREBLEND_DECALALPHA = 3
"""Alpha information in the texture specify how material and texture are combined. Alpha information of the texture replace material alpha component."""
VXTEXTUREBLEND_MODULATEALPHA = 4
"""Alpha information in the texture specify how material and texture are combined"""
VXTEXTUREBLEND_DECALMASK = 5 VXTEXTUREBLEND_DECALMASK = 5
VXTEXTUREBLEND_MODULATEMASK = 6 VXTEXTUREBLEND_MODULATEMASK = 6
VXTEXTUREBLEND_COPY = 7 ##< Equivalent to DECAL VXTEXTUREBLEND_COPY = 7
"""Equivalent to DECAL"""
VXTEXTUREBLEND_ADD = 8 VXTEXTUREBLEND_ADD = 8
VXTEXTUREBLEND_DOTPRODUCT3 = 9 ##< Perform a Dot Product 3 between texture (normal map) and a referential vector given in VXRENDERSTATE_TEXTUREFACTOR. VXTEXTUREBLEND_DOTPRODUCT3 = 9
"""Perform a Dot Product 3 between texture (normal map)and a referential vector given in VXRENDERSTATE_TEXTUREFACTOR."""
VXTEXTUREBLEND_MAX = 10 VXTEXTUREBLEND_MAX = 10
# VXTEXTUREBLEND_MASK = 0xF
class VXTEXTURE_FILTERMODE(enum.IntEnum): class VXTEXTURE_FILTERMODE(enum.IntEnum):
"""! """
Filter Mode Options Filter Mode Options
""" """
VXTEXTUREFILTER_NEAREST = 1 ##< No Filter VXTEXTUREFILTER_NEAREST = 1
VXTEXTUREFILTER_LINEAR = 2 ##< Bilinear Interpolation """No Filter"""
VXTEXTUREFILTER_MIPNEAREST = 3 ##< Mip mapping VXTEXTUREFILTER_LINEAR = 2
VXTEXTUREFILTER_MIPLINEAR = 4 ##< Mip Mapping with Bilinear interpolation """Bilinear Interpolation"""
VXTEXTUREFILTER_LINEARMIPNEAREST = 5 ##< Mip Mapping with Bilinear interpolation between mipmap levels. VXTEXTUREFILTER_MIPNEAREST = 3
VXTEXTUREFILTER_LINEARMIPLINEAR = 6 ##< Trilinear Filtering """Mip mapping"""
VXTEXTUREFILTER_ANISOTROPIC = 7 ##< Anisotropic filtering VXTEXTUREFILTER_MIPLINEAR = 4
"""Mip Mapping with Bilinear interpolation"""
VXTEXTUREFILTER_LINEARMIPNEAREST = 5
"""Mip Mapping with Bilinear interpolation between mipmap levels."""
VXTEXTUREFILTER_LINEARMIPLINEAR = 6
"""Trilinear Filtering"""
VXTEXTUREFILTER_ANISOTROPIC = 7
"""Anisotropic filtering"""
# VXTEXTUREFILTER_MASK = 0xF
class VXTEXTURE_ADDRESSMODE(enum.IntEnum): class VXTEXTURE_ADDRESSMODE(enum.IntEnum):
"""! """
Texture addressing modes. Texture addressing modes.
""" """
VXTEXTURE_ADDRESSWRAP = 1 ##< Default mesh wrap mode is used (see CKMesh::SetWrapMode) VXTEXTURE_ADDRESSWRAP = 1
VXTEXTURE_ADDRESSMIRROR = 2 ##< Texture coordinates outside the range [0..1] are flipped evenly. """Default mesh wrap mode is used (see CKMesh::SetWrapMode)"""
VXTEXTURE_ADDRESSCLAMP = 3 ##< Texture coordinates greater than 1.0 are set to 1.0, and values less than 0.0 are set to 0.0. VXTEXTURE_ADDRESSMIRROR = 2
VXTEXTURE_ADDRESSBORDER = 4 ##< When texture coordinates are greater than 1.0 or less than 0.0 texture is set to a color defined in CKMaterial::SetTextureBorderColor. """Texture coordinates outside the range [0..1] are flipped evenly."""
VXTEXTURE_ADDRESSMIRRORONCE = 5 ##< VXTEXTURE_ADDRESSCLAMP = 3
"""Texture coordinates greater than 1.0 are set to 1.0, and values less than 0.0 are set to 0.0."""
VXTEXTURE_ADDRESSBORDER = 4
"""When texture coordinates are greater than 1.0 or less than 0.0 texture is set to a color defined in CKMaterial::SetTextureBorderColor."""
VXTEXTURE_ADDRESSMIRRORONCE = 5
""""""
# VXTEXTURE_ADDRESSMASK = 0x7
# """mask for all values"""
class VXBLEND_MODE(enum.IntEnum): class VXBLEND_MODE(enum.IntEnum):
"""! """
Blending Mode options Blending Mode options
""" """
VXBLEND_ZERO = 1 ##< Blend factor is (0, 0, 0, 0). VXBLEND_ZERO = 1
VXBLEND_ONE = 2 ##< Blend factor is (1, 1, 1, 1). """Blend factor is (0, 0, 0, 0)."""
VXBLEND_SRCCOLOR = 3 ##< Blend factor is (Rs, Gs, Bs, As). VXBLEND_ONE = 2
VXBLEND_INVSRCCOLOR = 4 ##< Blend factor is (1-Rs, 1-Gs, 1-Bs, 1-As). """Blend factor is (1, 1, 1, 1)."""
VXBLEND_SRCALPHA = 5 ##< Blend factor is (As, As, As, As). VXBLEND_SRCCOLOR = 3
VXBLEND_INVSRCALPHA = 6 ##< Blend factor is (1-As, 1-As, 1-As, 1-As). """Blend factor is (Rs, Gs, Bs, As)."""
VXBLEND_DESTALPHA = 7 ##< Blend factor is (Ad, Ad, Ad, Ad). VXBLEND_INVSRCCOLOR = 4
VXBLEND_INVDESTALPHA = 8 ##< Blend factor is (1-Ad, 1-Ad, 1-Ad, 1-Ad). """Blend factor is (1-Rs, 1-Gs, 1-Bs, 1-As)."""
VXBLEND_DESTCOLOR = 9 ##< Blend factor is (Rd, Gd, Bd, Ad). VXBLEND_SRCALPHA = 5
VXBLEND_INVDESTCOLOR = 10 ##< Blend factor is (1-Rd, 1-Gd, 1-Bd, 1-Ad). """Blend factor is (As, As, As, As)."""
VXBLEND_SRCALPHASAT = 11 ##< Blend factor is (f, f, f, 1); f = min(As, 1-Ad). VXBLEND_INVSRCALPHA = 6
#VXBLEND_BOTHSRCALPHA = 12 ##< Source blend factor is (As, As, As, As) and destination blend factor is (1-As, 1-As, 1-As, 1-As) """Blend factor is (1-As, 1-As, 1-As, 1-As)."""
#VXBLEND_BOTHINVSRCALPHA = 13 ##< Source blend factor is (1-As, 1-As, 1-As, 1-As) and destination blend factor is (As, As, As, As) VXBLEND_DESTALPHA = 7
"""Blend factor is (Ad, Ad, Ad, Ad)."""
VXBLEND_INVDESTALPHA = 8
"""Blend factor is (1-Ad, 1-Ad, 1-Ad, 1-Ad)."""
VXBLEND_DESTCOLOR = 9
"""Blend factor is (Rd, Gd, Bd, Ad)."""
VXBLEND_INVDESTCOLOR = 10
"""Blend factor is (1-Rd, 1-Gd, 1-Bd, 1-Ad)."""
VXBLEND_SRCALPHASAT = 11
"""Blend factor is (f, f, f, 1); f = min(As, 1-Ad)."""
# VXBLEND_BOTHSRCALPHA = 12
# """Source blend factor is (As, As, As, As) and destination blend factor is (1-As, 1-As, 1-As, 1-As)"""
# VXBLEND_BOTHINVSRCALPHA = 13
# """Source blend factor is (1-As, 1-As, 1-As, 1-As) and destination blend factor is (As, As, As, As)"""
# VXBLEND_MASK = 0xF
# """Source blend factor is (1-As, 1-As, 1-As, 1-As) and destination blend factor is (As, As, As, As)"""
class VXFILL_MODE(enum.IntEnum): class VXFILL_MODE(enum.IntEnum):
"""! """
Fill Mode Options Fill Mode Options
""" """
VXFILL_POINT = 1 ##< Vertices rendering VXFILL_POINT = 1
VXFILL_WIREFRAME = 2 ##< Edges rendering """Vertices rendering"""
VXFILL_SOLID = 3 ##< Face rendering VXFILL_WIREFRAME = 2
"""Edges rendering"""
VXFILL_SOLID = 3
"""Face rendering"""
# VXFILL_MASK = 3
class VXSHADE_MODE(enum.IntEnum): class VXSHADE_MODE(enum.IntEnum):
"""! """
Shade Mode Options Shade Mode Options
""" """
VXSHADE_FLAT = 1 ##< Flat Shading VXSHADE_FLAT = 1
VXSHADE_GOURAUD = 2 ##< Gouraud Shading """Flat Shading"""
VXSHADE_PHONG = 3 ##< Phong Shading (Not yet supported by most implementation) VXSHADE_GOURAUD = 2
"""Gouraud Shading"""
VXSHADE_PHONG = 3
"""Phong Shading (Not yet supported by most implementation)"""
# VXSHADE_MASK = 3
class VXCMPFUNC(enum.IntEnum): class VXCMPFUNC(enum.IntEnum):
"""! """
Comparison Function Comparison Function
""" """
VXCMP_NEVER = 1 ##< Always fail the test. VXCMP_NEVER = 1
VXCMP_LESS = 2 ##< Accept if value if less than current value. """Always fail the test."""
VXCMP_EQUAL = 3 ##< Accept if value if equal than current value. VXCMP_LESS = 2
VXCMP_LESSEQUAL = 4 ##< Accept if value if less or equal than current value. """Accept if value if less than current value."""
VXCMP_GREATER = 5 ##< Accept if value if greater than current value. VXCMP_EQUAL = 3
VXCMP_NOTEQUAL = 6 ##< Accept if value if different than current value. """Accept if value if equal than current value."""
VXCMP_GREATEREQUAL = 7 ##< Accept if value if greater or equal current value. VXCMP_LESSEQUAL = 4
VXCMP_ALWAYS = 8 ##< Always accept the test. """Accept if value if less or equal than current value."""
VXCMP_GREATER = 5
"""Accept if value if greater than current value."""
VXCMP_NOTEQUAL = 6
"""Accept if value if different than current value."""
VXCMP_GREATEREQUAL = 7
"""Accept if value if greater or equal current value."""
VXCMP_ALWAYS = 8
"""Always accept the test."""
# VXCMP_MASK = 0xF
# """Mask for all possible values."""
class VXMESH_LITMODE(enum.IntEnum): class VXMESH_LITMODE(enum.IntEnum):
"""!
{filename:VXMESH_LITMODE}
Summary: Mesh lighting options
Remarks:
+ The VXMESH_LITMODE is used by CKMesh::SetLitMode to specify how lighting is done.
See Also: CKMaterial,CKMesh
""" """
VX_PRELITMESH = 0 ##< Lighting use color information store with vertices Mesh lighting options
VX_LITMESH = 1 ##< Lighting is done by renderer using normals and face material information. """
VX_PRELITMESH = 0
"""Lighting use color information store with vertices"""
VX_LITMESH = 1
"""Lighting is done by renderer using normals and face material information."""
class CK_CAMERA_PROJECTION(enum.IntEnum):
CK_PERSPECTIVEPROJECTION = 1
CK_ORTHOGRAPHICPROJECTION = 2

View File

@@ -14,9 +14,9 @@ def main() -> None:
return return
# Check BMap status. # Check BMap status.
# if True: if not bmap.is_bmap_available():
# print('Fail to initialize native BMap.') print('Fail to initialize native BMap.')
# return return
# Waiting debugger # Waiting debugger
input(f'Python PID is {os.getpid()}. Waiting for debugger, press any key to continue...') input(f'Python PID is {os.getpid()}. Waiting for debugger, press any key to continue...')

View File

@@ -4,5 +4,5 @@ requires-python = ">=3.11"
[[package]] [[package]]
name = "pybmap" name = "pybmap"
version = "0.1.0" version = "0.4.0"
source = { editable = "." } source = { editable = "." }

View File

@@ -1,15 +1,10 @@
{%- for fct in payload.fcts %} {%- for fct in payload.fcts %}
{{ fct.fct_name }} = _create_bmap_func('{{ fct.fct_name }}', [ {{ fct.fct_name }} = _create_bmap_func('{{ fct.fct_name }}', ({% for param in fct.fct_params %}{{ utils.get_python_type(param) }}, {% endfor %}))
{%- for param in fct.fct_params %}
{{- utils.get_python_type(param) }}
{%- if not loop.last %}, {% endif %}
{%- endfor -%}
])
""" """
{{ fct.fct_name }} {{ fct.fct_name }}
{% for param in fct.fct_params %} {% for param in fct.fct_params %}
:param {{ param.var_name }}: Direction: {% if param.is_input -%} input {%- else -%} output {%- endif %}. {{ param.var_desc }} :param {{ param.var_name }}: Direction: {% if param.is_input -%} input {%- else -%} output {%- endif %}. {{ param.var_desc }}
:type {{ param.var_name }}: {{ utils.get_python_type(param) }} ({{ param.var_type.to_c_type() }} in C++). {% if param.is_input -%} Use ctypes.byref() pass it. {%- endif %} :type {{ param.var_name }}: {{ utils.get_python_type(param) }} ({{ param.var_type.to_c_type() }} in C++). {% if not param.is_input -%} Use ctypes.byref(data) pass it. {%- endif %}
{%- endfor %} {%- endfor %}
:return: True if no error, otherwise False. :return: True if no error, otherwise False.
:rtype: bool :rtype: bool