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