5 #include <OpenGL/glu.h> 23 void setShapeSetInfo(ShapeSetInfo_ptr i_ssinfo);
27 const OpenHRP::TransformedShapeIndex &i_tsi);
28 void loadCamera(
GLcamera *camera,
const OpenHRP::SensorInfo &i_si);
29 ShapeInfoSequence_var
sis;
30 AppearanceInfoSequence_var
ais;
31 MaterialInfoSequence_var
mis;
32 TextureInfoSequence_var
txs;
37 sis = i_ssinfo->shapes();
38 ais = i_ssinfo->appearances();
39 mis = i_ssinfo->materials();
40 txs = i_ssinfo->textures();
46 LinkInfoSequence_var lis = i_binfo->links();
47 for (
unsigned int i=0;
i<lis->length();
i++){
52 std::cout <<
"can't find a link named " << lis[
i].name
58 void mulTrans(
const double i_m1[16],
const double i_m2[16],
double o_m[16])
60 for (
int i=0;
i<4;
i++){
61 for (
int j=0; j<4;j++){
63 for (
int k=0; k<4; k++){
64 v += i_m1[
i*4+k]*i_m2[j+k*4];
73 if (ti.image.length() == 0){
74 std::cerr <<
"texture image is not loaded(" << ti.url <<
")" << std::endl;
76 }
else if (ti.numComponents != 3 && ti.numComponents != 4){
77 std::cerr <<
"texture image which has " 79 <<
" components is not supported(" << ti.url <<
")" 86 texture->
url = ti.url;
87 texture->
width = ti.width;
88 texture->
height = ti.height;
89 texture->
image.resize(ti.image.length());
90 memcpy(&texture->
image[0], ti.image.get_buffer(), ti.image.length());
95 const OpenHRP::TransformedShapeIndex &i_tsi)
98 ShapeInfo& si = sis[i_tsi.shapeIndex];
99 shape->
setVertices(si.vertices.length()/3, si.vertices.get_buffer());
101 (
int *)si.triangles.get_buffer());
102 const AppearanceInfo& ai = ais[si.appearanceIndex];
103 shape->
setNormals(ai.normals.length()/3, ai.normals.get_buffer());
105 (
int *)ai.normalIndices.get_buffer());
107 ai.textureCoordinate.get_buffer());
109 (
int *)ai.textureCoordIndices.get_buffer());
110 shape->
setColors(ai.colors.length()/3, ai.colors.get_buffer());
111 if (ai.textureIndex >=0){
112 if (txs->length() <= (
unsigned int)ai.textureIndex){
113 std::cerr <<
"invalid texture index(" << ai.textureIndex <<
")" 116 TextureInfo &ti = txs[ai.textureIndex];
125 if (ai.colors.length()){
127 }
else if (ai.materialIndex >= 0){
128 const MaterialInfo& mi = mis[ai.materialIndex];
129 shape->
setDiffuseColor(mi.diffuseColor[0], mi.diffuseColor[1], mi.diffuseColor[2], 1.0-mi.transparency);
131 shape->
setSpecularColor(mi.specularColor[0], mi.specularColor[1], mi.specularColor[2]);
136 shape->
solid(ai.solid);
143 double hx = x/2, hy = y/2, hz = z/2;
144 float vertices[] = {hx,hy,hz,
152 int triangles[] = {0,2,3,
164 float normals[] = {1,0,0,
170 int normalIndices[] = {2,2,0,0,1,1,3,3,4,4,5,5};
194 TransformedShapeIndexSequence_var tsis = i_sinfo->shapeIndices();
195 for (
size_t i = 0;
i<tsis->length();
i++){
203 const OpenHRP::LinkInfo &i_li,
204 OpenHRP::ShapeSetInfo_ptr i_ssinfo,
216 for (
int i=0;
i<3;
i++) axis[
i] = i_li.rotation[
i];
220 trans[ 0]=
R(0,0);trans[ 1]=
R(0,1);trans[ 2]=
R(0,2);trans[3]=i_li.translation[0];
221 trans[ 4]=
R(1,0);trans[ 5]=
R(1,1);trans[ 6]=
R(1,2);trans[7]=i_li.translation[1];
222 trans[ 8]=
R(2,0);trans[ 9]=
R(2,1);trans[10]=
R(2,2);trans[11]=i_li.translation[2];
227 for (
size_t i = 0;
i<i_li.shapeIndices.length();
i++){
229 loadShape(shape, i_li.shapeIndices[
i]);
233 const SensorInfoSequence& sensors = i_li.sensors;
234 for (
unsigned int i=0;
i<sensors.length();
i++){
235 const SensorInfo& si = sensors[
i];
236 std::string
type(si.type);
237 if (type ==
"Vision"){
240 si.specValues[0], si.specValues[1],
243 loadCamera(camera, si);
247 p[0] = si.translation[0];
248 p[1] = si.translation[1];
249 p[2] = si.translation[2];
252 axis[0] = si.rotation[0];
253 axis[1] = si.rotation[1];
254 axis[2] = si.rotation[2];
257 for (
size_t i=0;
i<si.shapeIndices.length();
i++){
259 loadShape(shape, si.shapeIndices[
i]);
272 i_camera->
name(std::string(i_si.name));
273 i_camera->
setPosition(i_si.translation[0], i_si.translation[1],
274 i_si.translation[2]);
275 i_camera->
setRotation(i_si.rotation[0], i_si.rotation[1],
276 i_si.rotation[2], i_si.rotation[3]);
278 for (
size_t i=0;
i<i_si.shapeIndices.length();
i++){
280 loadShape(shape, i_si.shapeIndices[
i]);
void loadCamera(GLcamera *camera, const OpenHRP::SensorInfo &i_si)
TextureInfoSequence_var txs
png_infop png_charp png_int_32 png_int_32 int * type
void setNormals(unsigned int nnormal, const float *normals)
MaterialInfoSequence_var mis
void setTexture(GLtexture *texture)
void setTextureCoordinates(unsigned int len, const float *coordinates)
void addShape(GLshape *i_shape)
png_infop png_charpp name
void setTextureCoordIndices(unsigned int len, const int *coordinates)
void setShapeSetInfo(ShapeSetInfo_ptr i_ssinfo)
void setSpecularColor(float r, float g, float b)
const std::string & name() const
Link * link(int index) const
void setVertices(unsigned int nvertices, const float *vertices)
void loadShapeFromBodyInfo(GLbody *body, BodyInfo_var i_binfo, GLshape *(*shapeFactory)())
OpenHRP::matrix33 Matrix33
hrp::Matrix33 getRotation()
void setRotation(double r, double p, double y)
png_infop png_bytep * trans
void loadCube(GLshape *shape, double x, double y, double z)
void loadShape(GLshape *shape, const OpenHRP::TransformedShapeIndex &i_tsi)
void setTransform(const double i_trans[12])
hrp::Vector3 getPosition()
void loadShapeFromLinkInfo(GLlink *link, const LinkInfo &i_li, GLshape *(*shapeFactory)())
bool loadTextureFromTextureInfo(GLtexture *texture, TextureInfo &ti)
void setShininess(float s)
void setPosition(double x, double y, double z)
void setColors(unsigned int ncolors, const float *colors)
HRP_UTIL_EXPORT void calcRodrigues(Matrix44 &out_R, const Vector3 &axis, double q)
void loadShapeFromSceneInfo(GLlink *link, SceneInfo_var i_sinfo, GLshape *(*shapeFactory)())
void setTransform(double i_trans[16])
AppearanceInfoSequence_var ais
void setTriangles(unsigned int ntriangles, const int *vertexIndices)
void setDiffuseColor(float r, float g, float b, float a)
void addShape(GLshape *shape)
void mulTrans(const double i_m1[16], const double i_m2[16], double o_m[16])
void loadShapeFromBodyInfo(GLbody *body, BodyInfo_var i_binfo, GLshape *(*shapeFactory)())
void addCamera(GLcamera *camera)
void computeAbsTransform()
void loadShapeFromLinkInfo(GLlink *link, const OpenHRP::LinkInfo &i_li, OpenHRP::ShapeSetInfo_ptr i_ssinfo, GLshape *(*shapeFactory)())
void setNormalIndices(unsigned int len, const int *normalIndices)
std::vector< unsigned char > image
void normalPerVertex(bool flag)
ShapeInfoSequence_var sis