Arnold AtArray API Test

#include <ai.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <assert.h>

using namespace std;

void print_the_type()
{
    printf("AI_TYPE_BYTE   %5d 
",AI_TYPE_BYTE);  //0
    printf("AI_TYPE_INT    %5d 
",AI_TYPE_INT);   //1
    printf("AI_TYPE_FLOAT  %5d 
",AI_TYPE_FLOAT); //4
    printf("AI_TYPE_STRING %5d 
",AI_TYPE_STRING);//10
    printf("AI_TYPE_ARRAY  %5d 
",AI_TYPE_ARRAY); //13
    printf("AI_TYPE_POINT  %5d 
",AI_TYPE_POINT); //8
}


int main()
{
    print_the_type();
    printf("
");
    printf("test AI_TYPE_FLOAT ARRAY
");
    AtArray *array = AiArrayAllocate(3,2,AI_TYPE_FLOAT);
    // basic method
    /*
    for(int i=0;i<array->nelements*2;i++)
    {
        AiArraySetFlt(array,i,i);
    }
    */
    float *test = static_cast <float *> (array->data);
    test[0]=1;
    test[1]=2;
    test[5]=6;

    for(int i=0;i<array->nelements*2;i++) // MUTIPLY *2 ,because have two float[3],so it's have the 3*2=6 
    {
        cout << AiArrayGetFlt(array,i) <<endl;
    }
    AiArrayDestroy(array);

    printf("
");
    // test the array point
    printf("test AI_TYPE_POINT ARRAY
");
    // create 2 point and have two motion keys 
    // so the data have 4 point ,every point have 3 elements ... the count is 2*3*2 = 12
    AtInt32 keys = 2;
    AtArray *array_type_point = AiArrayAllocate(2,keys,AI_TYPE_POINT);
    assert(array_type_point->nkeys==2);
    assert(array_type_point->nelements==2);
    assert(array_type_point->nelements*2==4);

    float * array_raw_pt= static_cast <float *> (array_type_point->data);
    //pt 1
    array_raw_pt[0]=1.0f;
    array_raw_pt[1]=2.0f;
    array_raw_pt[2]=3.0f;
    // pt 2
    array_raw_pt[3]=4.0f;
    array_raw_pt[4]=5.0f;
    array_raw_pt[5]=6.0f;
    // pt3
    array_raw_pt[6]=7.0f;
    //assert(AiArraySetFlt(array,7,8.0f) == 1 ); //arnold will test array_type is same as rh array 
    // cout << array_raw_pt[0] << endl;
    cout.setf(ios::showpoint);
    for(int i=0;i<array_type_point->nelements*keys;i++)
    {
        cout<< i <<"  x : -> " << AiArrayGetPnt(array_type_point,i).x <<endl;
        cout<< i <<"  y : -> " << AiArrayGetPnt(array_type_point,i).y <<endl;
        cout<< i <<"  z : -> " << AiArrayGetPnt(array_type_point,i).z <<endl;
    }
    AiArrayDestroy(array_type_point);
    
    cin.get();
    return 0;
}

 

原文地址:https://www.cnblogs.com/gearslogy/p/5410360.html