Skip to content

Commit

Permalink
py
Browse files Browse the repository at this point in the history
  • Loading branch information
archibate committed Sep 5, 2022
1 parent 5e762ae commit f340195
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ endmacro()
## --- begin cihou wxl cuda
if (ZENO_WITH_CUDA) # must move enable_language ahead to here
message(STATUS "CUDA_PATH: "$ENV{CUDA_PATH})
if (NOT DEFINED CUDAToolkit_ROOT AND NOT DEFINED ENV{CUDAToolkit_ROOT})
if (NOT DEFINED CUDAToolkit_ROOT AND NOT DEFINED ENV{CUDAToolkit_ROOT} AND DEFINED ENV{CUDA_PATH})
set(CUDAToolkit_ROOT ${CUDA_PATH})
endif()
message(STATUS "CUDAToolkit_ROOT: "${CUDAToolkit_ROOT})
Expand All @@ -116,6 +116,9 @@ if (ZENO_WITH_CUDA) # must move enable_language ahead to here
message(STATUS "CUDAToolkit_INCLUDE_DIRS: "${CUDAToolkit_INCLUDE_DIRS})
message(STATUS "CUDAToolkit_LIBRARY_DIR: "${CUDAToolkit_LIBRARY_DIR})
message(STATUS "CUDAToolkit_NVCC_EXECUTABLE: "${CUDAToolkit_NVCC_EXECUTABLE})
if (NOT DEFINED CMAKE_CUDA_COMPILER AND DEFINED CUDAToolkit_NVCC_EXECUTABLE)
set(CMAKE_CUDA_COMPILER ${CUDAToolkit_NVCC_EXECUTABLE})
endif()
enable_language(CUDA) # otherwise projects/CUDA will fail to compile
endif()
## --- end cihou wxl cuda
Expand Down
20 changes: 20 additions & 0 deletions projects/Python/Lib/ze/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def define(rettype, funcname, *argtypes, do_checks=True):
define(ctypes.c_uint32, 'Zeno_GetObjectFloat', ctypes.c_uint64, ctypes.POINTER(ctypes.c_float), ctypes.c_size_t)
define(ctypes.c_uint32, 'Zeno_GetObjectString', ctypes.c_uint64, ctypes.POINTER(ctypes.c_char), ctypes.POINTER(ctypes.c_size_t))
define(ctypes.c_uint32, 'Zeno_GetObjectPrimData', ctypes.c_uint64, ctypes.c_int, ctypes.c_char_p, ctypes.POINTER(ctypes.c_void_p), ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_int))
# ZENO_CAPI Zeno_Error Zeno_AddObjectPrimAttr(Zeno_Object object_, Zeno_PrimMembType primArrType_, const char *attrName_, Zeno_PrimDataType dataType_) ZENO_CAPI_NOEXCEPT;
define(ctypes.c_uint32, 'Zeno_AddObjectPrimAttr', ctypes.c_uint64, ctypes.c_int, ctypes.c_char_p, ctypes.c_int)
define(ctypes.c_uint32, 'Zeno_GetObjectPrimDataKeys', ctypes.c_uint64, ctypes.c_int, ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_char_p))
define(ctypes.c_uint32, 'Zeno_ResizeObjectPrimData', ctypes.c_uint64, ctypes.c_int, ctypes.c_size_t)
define(ctypes.c_uint32, 'Zeno_InvokeObjectFactory', ctypes.POINTER(ctypes.c_uint64), ctypes.c_char_p, ctypes.c_void_p)
Expand Down Expand Up @@ -341,6 +343,9 @@ def from_list(self, lst: list[Numeric]):
def raw_data(self) -> tuple[int, int, Any, int]:
return (self._ptr, self._len, self._type, self._dim)

def dtype(self) -> tuple[type, int]:
return (type(self._type()), self._dim)

def __len__(self) -> int:
return self._len

Expand All @@ -365,11 +370,26 @@ class _AttrVectorWrapper:
_dimLut = [
3, 1, 3, 1, 2, 2, 4, 4,
]
_typeUnlut: dict[tuple[type, int], int] = {
(float, 3): 0,
(float, 1): 1,
(int, 3): 2,
(int, 1): 3,
(float, 2): 4,
(int, 2): 5,
(float, 4): 6,
(int, 4): 7,
}

def __init__(self, handle: int, kind: int):
self._handle = handle
self._kind = kind

def add_attr(self, attrName: str, dataType: tuple[type, int]):
dataTypeInd = self._typeUnlut[dataType]
api.Zeno_AddObjectPrimAttr(ctypes.c_uint64(self._handle), ctypes.c_int(self._kind), ctypes.c_char_p(attrName.encode()), ctypes.c_int(dataTypeInd))
return self.attr(attrName)

def attr(self, attrName: str):
ptrRet_ = ctypes.c_void_p()
lenRet_ = ctypes.c_size_t()
Expand Down
1 change: 1 addition & 0 deletions zeno/include/zeno/extra/CAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ZENO_CAPI Zeno_Error Zeno_GetObjectInt(Zeno_Object object_, int *value_, size_t
ZENO_CAPI Zeno_Error Zeno_GetObjectFloat(Zeno_Object object_, float *value_, size_t dim_) ZENO_CAPI_NOEXCEPT;
ZENO_CAPI Zeno_Error Zeno_GetObjectString(Zeno_Object object_, char *strBuf_, size_t *strLenRet_) ZENO_CAPI_NOEXCEPT;
ZENO_CAPI Zeno_Error Zeno_GetObjectPrimData(Zeno_Object object_, Zeno_PrimMembType primArrType_, const char *attrName_, void **ptrRet_, size_t *lenRet_, Zeno_PrimDataType *typeRet_) ZENO_CAPI_NOEXCEPT;
ZENO_CAPI Zeno_Error Zeno_AddObjectPrimAttr(Zeno_Object object_, Zeno_PrimMembType primArrType_, const char *attrName_, Zeno_PrimDataType dataType_) ZENO_CAPI_NOEXCEPT;
ZENO_CAPI Zeno_Error Zeno_GetObjectPrimDataKeys(Zeno_Object object_, Zeno_PrimMembType primArrType_, size_t *lenRet_, const char **keysRet_) ZENO_CAPI_NOEXCEPT;
ZENO_CAPI Zeno_Error Zeno_ResizeObjectPrimData(Zeno_Object object_, Zeno_PrimMembType primArrType_, size_t newSize_) ZENO_CAPI_NOEXCEPT;
ZENO_CAPI Zeno_Error Zeno_InvokeObjectFactory(Zeno_Object *objectRet_, const char *typeName_, void *ffiObj_) ZENO_CAPI_NOEXCEPT;
Expand Down
26 changes: 26 additions & 0 deletions zeno/src/extra/CAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,32 @@ ZENO_CAPI Zeno_Error Zeno_GetObjectPrimData(Zeno_Object object_, Zeno_PrimMembTy
});
}

ZENO_CAPI Zeno_Error Zeno_AddObjectPrimAttr(Zeno_Object object_, Zeno_PrimMembType primArrType_, const char *attrName_, Zeno_PrimDataType dataType_) ZENO_CAPI_NOEXCEPT {
return lastError.catched([=] {
auto optr = lutObject.access(object_).get();
auto prim = dynamic_cast<PrimitiveObject *>(optr);
if (ZENO_UNLIKELY(prim == nullptr))
throw makeError<TypeError>(typeid(PrimitiveObject), typeid(*optr), "get object as primitive");
auto memb = invoker_variant(static_cast<size_t>(primArrType_),
&PrimitiveObject::verts,
&PrimitiveObject::points,
&PrimitiveObject::lines,
&PrimitiveObject::tris,
&PrimitiveObject::quads,
&PrimitiveObject::loops,
&PrimitiveObject::polys,
&PrimitiveObject::uvs,
&PrimitiveObject::loop_uvs);
std::string attrName = attrName_;
std::visit([&] (auto const &memb) {
index_switch<std::variant_size_v<AttrAcceptAll>>(static_cast<size_t>(dataType_), [&] (auto dataType) {
using T = std::variant_alternative_t<dataType.value, AttrAcceptAll>;
memb(*prim).template add_attr<T>(attrName);
});
}, memb);
});
}

ZENO_CAPI Zeno_Error Zeno_GetObjectPrimDataKeys(Zeno_Object object_, Zeno_PrimMembType primArrType_, size_t *lenRet_, const char **keysRet_) ZENO_CAPI_NOEXCEPT {
return lastError.catched([=] {
auto optr = lutObject.access(object_).get();
Expand Down

0 comments on commit f340195

Please sign in to comment.