bergermon Posted April 25, 2020 Share Posted April 25, 2020 (edited) Hi I cannot figure out how to pass an array of vector3 (or array of quaternions or matrices) to my inlinecpp. I know there is something like "geo.setPointFloatAttribValuesFromString("P", positions)" but i dont have Points yet in my Operator. I do know how to pass a single Vector or an Array of Integers. If anyone has an example on how to do this, thank you this one is using numpy and is not working: import inlinecpp import numpy as np import ctypes Cpp_lib = inlinecpp.createLibrary("Arrayexample", includes=""" #include <hboost\iostreams\detail\iostream.hpp> #include <SYS/SYS_Types.h> #include <UT/UT_Vector3.h> #include <UT/UT_Storage.h> """, function_sources=[""" void vecArray(UT_Vector3D * vec, int l) { for(int i=0; i < l ; ++i) std::cout << (*vec)[i] << std::endl; } """]) v0 = hou.Vector3(0.5, 0.2, 0.3) v1 = hou.Vector3(1.5, 2.2, 3.3) v2 = hou.Vector3(2.5, 3.2, 4.4) myVectorArray = np.array([v0, v1, v2]) Cpp_lib.vecArray( myVectorArray.ctypes.data , len(myVectorArray)) this is working: import inlinecpp cpp_lib = inlinecpp.createLibrary("example", includes=""" #include <hboost\iostreams\detail\iostream.hpp> #include <SYS/SYS_Types.h> #include <UT/UT_Vector3.h> #include <UT/UT_Storage.h> """, function_sources=[""" void saysomething2(UT_Vector3D * vec) { for(int i=0; i < 3 ; ++i) std::cout << (*vec)[i] << std::endl; } """]) v = hou.Vector3(0.5, 0.2, 0.3) cpp_lib.saysomething2(v) this one is using the array module and is working, but how could I define a custom type (hou.Vector3) in the array module? import array import inlinecpp example_lib = inlinecpp.createLibrary("example_lib", function_sources=[""" inlinecpp::BinaryString build_int_array() { std::vector<int> values(10); for (int i=0; i<10; ++i) values[i] = i; return inlinecpp::as_binary_string(values); } """]) data = example_lib.build_int_array() int_array = array.array("i", data) for value in int_array: print value Edited May 1, 2020 by bergermon Quote Link to comment Share on other sites More sharing options...
bergermon Posted May 1, 2020 Author Share Posted May 1, 2020 (edited) sorry, did not want to bump this thread, here is my answer to my own question, to pass hou.vector3 to an inlinecpp operator: I can use a struct import inlinecpp import numpy as np Cpp_lib = inlinecpp.createLibrary("Arrayexample", includes=""" #include <iostream> """, structs=[("Pos3D", ( ("x", "d"), ("y", "d"), ("z", "d"), ))], function_sources=[""" void vecArray(Pos3D * Pos3DArray, int length) { for ( int i = 0; i < length; i++) { std::cout << (Pos3DArray+i)->x << " " << (Pos3DArray + i)->y << " " << (Pos3DArray + i)->z << std::endl; } } """]) v0 = hou.Vector3(0.5, 0.2, 0.3) v1 = hou.Vector3(1.5, 2.2, 3.3) v2 = hou.Vector3(2.5, 3.2, 4.4) VectorArray = np.array([v0, v1, v2], dtype='double') Cpp_lib.vecArray( VectorArray.ctypes.data , len(VectorArray)) Edited May 1, 2020 by bergermon wrong code Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.