Hi All,
I’d like to do something that seems like it should be pretty simple; have tried a few variations from other topics; but nothing seems to work. I have an un-textured 3D plane that I’ve exported from blender as a wavefront obj; and I want to (based off of user interaction) dynamically add a 2D texture to this plane using code rather than texturing it in blender (so that I can switch other textures in later based off of user interaction). Its a square plane 1x1 gl units; and the texture I’m trying is 512x512 px png.
spr = Sprite3D::create("plane.obj");
Some of the variations I’ve tried; all run without error; the plane shows with the default blender grey texture; but never shows my programmatically added texture image:
A)
cocos2d::Image *im = new Image();
im->initWithImageFile("cubetext.png");
Texture2D *t2 = new Texture2D();
t2->initWithImage(im);
t2->retain();
spr->setTexture(t2);
B)
spr->getMesh()->setTexture("cubetext.png");
C)
spr->setTexture(Sprite::create("cubetext.png")->getTexture());
D)
//deprecated but worth a shot right?
spr->setTexture(CCTextureCache::sharedTextureCache()->addImage("cubetext.png"));
E)
auto c = new Texture2D();
auto i = new Image();
i->Image::initWithImageFile("cubetext.png");
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB888);
c->initWithImage(i,Texture2D::PixelFormat::RGB888);
spr->setTexture(c);
Any help would be greatly appreciated - thanks!