FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Programatically applying a texture

3 posters

Go down

Programatically applying a texture Empty Programatically applying a texture

Post  pushkin Thu Mar 12, 2009 10:50 am

Hi,

maybe this is an easy one, and maybe I should get it from some other thread here, however I need to apply a texture to a SIOobject at runtime. I have tried to scrape together code from different sections here in to forum and come up with something, which does not work... =) even in the debugger everything seems to be correctly populated etc. but I sure am missing something:

Code:

        SIO2object * plane = sio2ResourceGetObject( sio2->_SIO2resource, "object/Plane");

   if(plane)
   {
      char name[ SIO2_MAX_CHAR ];
      
      // Create a name for our new object
      sprintf( name, "%s_%u_%u", plane->name, x, y);
      
      // Get the raw image
      CFDataRef rawImage = CGDataProviderCopyData(CGImageGetDataProvider(image.image.CGImage));
      const UInt8 * rawImagePtr = CFDataGetBytePtr(rawImage);
      int length = CFDataGetLength(rawImage);
      
      // Create a sio image
      SIO2image * mapImage = sio2ImageInit(name);
      mapImage->tex = (unsigned char *) malloc (length);
      memcpy(mapImage->tex, rawImagePtr, length);
      
      // Set the position
      plane->_SIO2transform->loc->x = image.screenLocation.origin.x;
      plane->_SIO2transform->loc->y = image.screenLocation.origin.y;
      
      plane = sio2ObjectDuplicate( plane, plane->_SIO2transform, name, 0 );
            
      // N_VGROUP
      plane->n_vgroup = 1;
      if( plane->n_vgroup )
      { plane->_SIO2vertexgroup = ( SIO2vertexgroup ** ) malloc( plane->n_vgroup * sizeof( SIO2vertexgroup ) ); }
      
      // VGROUP
      plane->_SIO2vertexgroup[0] = sio2VertexGroupInit(name);
      
      SIO2vertexgroup * vert = plane->_SIO2vertexgroup[0];
      vert->_SIO2material = sio2MaterialInit(name);
      vert->_SIO2material->_SIO2image[SIO2_MATERIAL_CHANNEL0] = mapImage;

      sio2VertexGroupGenId(vert);
      sio2ResourceBindMaterial(sio2->_SIO2resource, plane);
      sio2ObjectReset();
      sio2ResourceResetState();
   }

I have also tried with just loading a texture from a sio resource e.g.:

Code:

vert->_SIO2material->_SIO2image[SIO2_MATERIAL_CHANNEL0] = sio2ResourceGetImage(sio2->_SIO2resource, "smoke" );

And I get no image. There probably is something fundamental that I am missing...

pushkin

Posts : 2
Join date : 2009-03-05

Back to top Go down

Programatically applying a texture Empty Re: Programatically applying a texture

Post  sio2interactive Thu Mar 12, 2009 5:13 pm

sio2ImageGenId?
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Programatically applying a texture Empty Re: Programatically applying a texture

Post  kzv Thu Jul 23, 2009 11:24 pm

Hi,

I have been trying to assign an image to 1 side of a 3D cube programatically through code.

and I have read almost all the posts in the forum relating to assigning textures, but some of them are 2D, and some are talking about other things (i believe).. so I couldn't really find a clear answer..

1. Can anyone please tell me how to assign an image to 1 side of a cube..?

2. and when assigning the image, you obviously need to choose which of the 6 sides you want to put on, so how do you choose the side? (i only want to choose 1 of the 6 sides of a cube to apply the image)

3. does the code in this post does the "picking of the side"..? if so, which lines...? i'm a bit confused of this code.

Thanks in advance for any help!
KE

kzv

Posts : 8
Join date : 2009-06-11

Back to top Go down

Programatically applying a texture Empty Re: Programatically applying a texture

Post  sio2interactive Fri Jul 24, 2009 12:45 am

1. Can anyone please tell me how to assign an image to 1 side of a cube..?

>> Multimaterial, assign multiple vertex group and assign a different material to each of them, check my channel on youtube, I create a quick tutorial on that.

2. and when assigning the image, you obviously need to choose which of the 6 sides you want to put on, so how do you choose the side? (i only want to choose 1 of the 6 sides of a cube to apply the image)

>> You simply have to check the vertexgroup name, simply loop through the vertex group of your object then assign the image to the material.

3. does the code in this post does the "picking of the side"..? if so, which lines...? i'm a bit confused of this code.

>> There's no mechanism to check which "face" that you pick, you can either go with 6 objects or do a physic ray pick and depending on the normal picked you basically know which face. You can create your own color picking method that create a unique color for each faces of the object.
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Programatically applying a texture Empty Re: Programatically applying a texture

Post  kzv Fri Jul 24, 2009 1:15 am

Hi SIO2,

Thanks for your answer, that makes alot easier for me to understand it..

so I have came up with the follwing code:

Code:

// Init all images
SIO2image * img1 = sio2ImageInit(name1);
SIO2image * img2 = sio2ImageInit(name2);
SIO2image * img3 = sio2ImageInit(name3);
SIO2image * img4 = sio2ImageInit(name4);
SIO2image * img5 = sio2ImageInit(name5);
SIO2image * img6 = sio2ImageInit(name6);


// Get all the vertex
SIO2vertexgroup * vert1 = cube001->_SIO2vertexgroup[0];
SIO2vertexgroup * vert2 = cube001->_SIO2vertexgroup[1];
SIO2vertexgroup * vert3 = cube001->_SIO2vertexgroup[2];
SIO2vertexgroup * vert4 = cube001->_SIO2vertexgroup[3];
SIO2vertexgroup * vert5 = cube001->_SIO2vertexgroup[4];
SIO2vertexgroup * vert6 = cube001->_SIO2vertexgroup[5];

// Apply all the images
vert1->_SIO2material->_SIO2image[SIO2_MATERIAL_CHANNEL0] = img1;
vert2->_SIO2material->_SIO2image[SIO2_MATERIAL_CHANNEL0] = img2;
vert3->_SIO2material->_SIO2image[SIO2_MATERIAL_CHANNEL0] = img3;
vert4->_SIO2material->_SIO2image[SIO2_MATERIAL_CHANNEL0] = img4;
vert5->_SIO2material->_SIO2image[SIO2_MATERIAL_CHANNEL0] = img5;
vert6->_SIO2material->_SIO2image[SIO2_MATERIAL_CHANNEL0] = img6;

So this assigns all 6 sides with a image, but i just don't know which side it goes to. Is my thinking correct..? Please let me know.. cos i don't have my OSX with me.. i'll have to try it out tomorrow...

so just wondering if i'm missing anything in between..?

for example, do I need the following line for each of the vertex? (total 6 of them)
Code:

sio2VertexGroupGenId(vert1);

also, do I need any of those 3 lines?
Code:

sio2ResourceBindMaterial(sio2->_SIO2resource, cube001);
sio2ObjectReset();
sio2ResourceResetState();

Thanks alot for your help!!

kzv

Posts : 8
Join date : 2009-06-11

Back to top Go down

Programatically applying a texture Empty Re: Programatically applying a texture

Post  sio2interactive Fri Jul 24, 2009 2:42 am

SIO2vertexgroup->name

where name is whatever you set in Blender...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Programatically applying a texture Empty Re: Programatically applying a texture

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum