Mohamed Sakr
Mohamed Sakr

Reputation: 459

reading data(structure) from specific memory location from blender

I'm trying to do a plugin for blender (free 3d program) the plugin is a python plugin,i will pass the data to c++ to do heavy calculations on it

in python the method is like this:

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.

the data that i read is a list

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

and so on so the item size is 200 bytes,with an unknown structure

how to read this data inside c++

Upvotes: 0

Views: 571

Answers (2)

Mohamed Sakr
Mohamed Sakr

Reputation: 459

what I have done so far and some how it worked well to determine which data is which,+ comparing data with python internal data

c++ code:

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;
    }
}

and here is the result:

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

Upvotes: 0

SNce
SNce

Reputation: 2553

You must know the format. Once you do you can probably create a struct and type cast this pointer into the struct type and read it.

EDIT: I'm sure blender has an API for this.

Upvotes: 1

Related Questions