0

我正在尝试为搅拌机(免费 3d 程序)做一个插件,该插件是一个 python 插件,我会将数据传递给 c++ 以对其进行大量计算

在python中,方法是这样的:

data.as_pointer()
#.. method:: as_pointer()
#Returns the memory address which holds a pointer to blenders internal data
#:return: int (memory address).
#:rtype: int
#.. note:: This is intended only for advanced script writers who need to
#pass blender data to their own C/Python modules.

我读的数据是一个列表

>>>>data[0].as_pointer()
152884792
>>>>data[1].as_pointer()
152884992
>>>>data[2].as_pointer()
152885192

依此类推,项目大小为 200 字节,结构未知

如何在 C++ 中读取这些数据

4

2 回答 2

1

你必须知道格式。一旦你这样做了,你可能可以创建一个struct并将这个指针类型转换为struct类型并读取它。

编辑:我确信搅拌机有一个 API。

于 2013-03-02T07:50:02.183 回答
0

到目前为止我做了什么,以及它如何很好地确定哪些数据是哪个,+ 将数据与 python 内部数据进行比较

C++代码:

unsigned int p = imported_data; /*mypointer address*/

float* value_float;
unsigned int* value_int;
double* value_double;
char* value_char;
bool* value_bool;

for (int looper = 0;looper <200;looper +=4)
{
    value_float = reinterpret_cast<float *>(p + looper);
    if(*value_float != 0.0f){
        printf("%i value_float = %f\n", looper, *value_float);
        continue;
    }
    value_int = reinterpret_cast<unsigned int *>(p + looper);
    if(*value_int != 0){
        printf("%i value_int = %u\n", looper, *value_int);
        continue;
    }
    value_double = reinterpret_cast<double *>(p + looper);
    if(*value_double != 0.0){
        printf("%i value_double = %f\n", looper, *value_double);
        continue;
    }
    value_char = reinterpret_cast<char *>(p + looper);
    if(*value_char != NULL){
        printf("%i value_char = %c\n", looper, *value_char);
        continue;
    }
    value_bool = reinterpret_cast<bool *>(p + looper);
    if(*value_bool != 0){
        printf("%i value_char = %i\n", looper, *value_bool);
        continue;
    }
}

结果如下:

0 value_float = 2.784583
4 value_float = 2.088116
8 value_float = -3.057968
16 value_double = -15656.531250
20 value_float = -6.455599
24 value_float = 1.000000
48 value_double = 134217728.000000
52 value_float = 20.000000
56 value_float = 2.784583
60 value_float = 2.088116
64 value_float = -2.807592
72 value_double = -9227.453125
76 value_float = -6.063199
80 value_float = 1.000000
104 value_double = 100663296.000000
108 value_float = 19.000000
136 value_double = 0.007813
140 value_float = 1.000000
144 value_float = 50.000000
148 value_float = 51.000000
152 value_float = 0.000000
156 value_float = -1.#QNAN0
160 value_float = 0.713105
164 value_float = 0.023383
168 value_float = 0.014281
172 value_float = 0.249231
176 value_double = 0.000000
180 value_float = 0.050000
192 value_double = 0.000000
196 value_float = 0.000000
于 2013-03-02T13:39:09.570 回答