Add API to load texture file.
This commit is contained in:
@@ -3006,6 +3006,8 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
|
||||
SharedMemoryStatus& serverCmd = serverStatusOut;
|
||||
serverCmd.m_type = CMD_VISUAL_SHAPE_UPDATE_FAILED;
|
||||
|
||||
const char filename[] = "/Users/yunfeibai/Documents/dev/bullet-change-texture/bullet3/data/checker_huge.gif";
|
||||
m_data->m_visualConverter.loadTextureFile(filename);
|
||||
m_data->m_visualConverter.activateShapeTexture(0, 0);
|
||||
|
||||
serverCmd.m_type = CMD_VISUAL_SHAPE_UPDATE_COMPLETED;
|
||||
|
||||
@@ -70,7 +70,9 @@ struct TinyRendererVisualShapeConverterInternalData
|
||||
int m_swWidth;
|
||||
int m_swHeight;
|
||||
TGAImage m_rgbColorBuffer;
|
||||
TGAImage m_texture;
|
||||
unsigned char* m_texture;
|
||||
int m_textureWidth;
|
||||
int m_textureHeight;
|
||||
b3AlignedObjectArray<float> m_depthBuffer;
|
||||
b3AlignedObjectArray<int> m_segmentationMaskBuffer;
|
||||
|
||||
@@ -80,8 +82,7 @@ struct TinyRendererVisualShapeConverterInternalData
|
||||
:m_upAxis(2),
|
||||
m_swWidth(START_WIDTH),
|
||||
m_swHeight(START_HEIGHT),
|
||||
m_rgbColorBuffer(START_WIDTH,START_HEIGHT,TGAImage::RGB),
|
||||
m_texture(START_WIDTH,START_HEIGHT,TGAImage::RGB)
|
||||
m_rgbColorBuffer(START_WIDTH,START_HEIGHT,TGAImage::RGB)
|
||||
{
|
||||
m_depthBuffer.resize(m_swWidth*m_swHeight);
|
||||
m_segmentationMaskBuffer.resize(m_swWidth*m_swHeight,-1);
|
||||
@@ -834,12 +835,6 @@ void TinyRendererVisualShapeConverter::resetAll()
|
||||
// Get shapeUniqueId from getVisualShapesData?
|
||||
void TinyRendererVisualShapeConverter::activateShapeTexture(int shapeUniqueId, int textureUniqueId)
|
||||
{
|
||||
int width,height,n;
|
||||
const char filename[] = "/Users/yunfeibai/Documents/dev/bullet-change-texture/bullet3/data/checker_huge.gif";
|
||||
unsigned char* image=0;
|
||||
|
||||
image = stbi_load(filename, &width, &height, &n, 3);
|
||||
|
||||
// Use shapeUniqueId?
|
||||
int objectArrayIndex = 8;
|
||||
int objectIndex = 0;
|
||||
@@ -848,29 +843,22 @@ void TinyRendererVisualShapeConverter::activateShapeTexture(int shapeUniqueId, i
|
||||
if (ptrptr && *ptrptr)
|
||||
{
|
||||
TinyRendererObjectArray* ptr = *ptrptr;
|
||||
unsigned char textureImage[3] = {255, 0, 0};
|
||||
int textureWidth = 1;
|
||||
int textureHeight = 1;
|
||||
//ptr->m_renderObjects[objectIndex]->m_model->setDiffuseTextureFromData(textureImage,textureWidth,textureHeight);
|
||||
ptr->m_renderObjects[objectIndex]->m_model->setDiffuseTextureFromData(image,width,height);
|
||||
ptr->m_renderObjects[objectIndex]->m_model->setDiffuseTextureFromData(m_data->m_texture,m_data->m_textureWidth,m_data->m_textureHeight);
|
||||
}
|
||||
}
|
||||
|
||||
int TinyRendererVisualShapeConverter::registerTexture(unsigned char* texels, int width, int height)
|
||||
{
|
||||
m_data->m_texture = texels;
|
||||
m_data->m_textureWidth = width;
|
||||
m_data->m_textureHeight = height;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
int objectArrayIndex = 0;
|
||||
int objectIndex = 0;
|
||||
printf("num m_swRenderInstances = %d\n", m_data->m_swRenderInstances.size());
|
||||
for (int i=0;i<m_data->m_swRenderInstances.size();i++)
|
||||
void TinyRendererVisualShapeConverter::loadTextureFile(const char* filename)
|
||||
{
|
||||
TinyRendererObjectArray** ptrptr = m_data->m_swRenderInstances.getAtIndex(i);
|
||||
if (ptrptr && *ptrptr)
|
||||
{
|
||||
TinyRendererObjectArray* ptr = *ptrptr;
|
||||
unsigned char textureImage[3] = {255, 10, 10};
|
||||
int textureWidth = 1;
|
||||
int textureHeight = 1;
|
||||
ptr->m_renderObjects[objectIndex]->m_model->setDiffuseTextureFromData(textureImage,textureWidth,textureHeight);
|
||||
}
|
||||
}
|
||||
*/
|
||||
int width,height,n;
|
||||
unsigned char* image=0;
|
||||
image = stbi_load(filename, &width, &height, &n, 3);
|
||||
registerTexture(image, width, height);
|
||||
}
|
||||
@@ -38,6 +38,7 @@ struct TinyRendererVisualShapeConverter : public LinkVisualShapesConverter
|
||||
void render();
|
||||
void render(const float viewMat[16], const float projMat[16]);
|
||||
|
||||
void loadTextureFile(const char* filename);
|
||||
int registerTexture(unsigned char* texels, int width, int height);
|
||||
void activateShapeTexture(int shapeUniqueId, int textureUniqueId);
|
||||
void activateShapeTexture(int objectUniqueId, int jointIndex, int shapeIndex, int textureUniqueId);
|
||||
|
||||
Reference in New Issue
Block a user