Как приаттачить текстуру к репу?

Программирование для CATIA.

Как приаттачить текстуру к репу?

Сообщение snezhinka » 20 май 2008 13:10

Создается график примитив(CAT3DFaceGP), который добавляется в реп. В примитиве указываются координаты текстуры...но что это за текстура? Пробовала через SetGraphicMaterial, не помогло.
Аватара пользователя
snezhinka
Новичок
Новичок
 
Сообщения: 22
Зарегистрирован: 20 май 2008 11:10
Откуда: Минск

Re: Как приаттачить текстуру к репу?

Сообщение bit » 24 июл 2008 11:56

Попробуйте:

//-------------------------------------------------------------------------
// CreateRep()
//-------------------------------------------------------------------------
CAT3DRep CreateRep(const float * iVertices,
const float * iNormals,
const float * iTexture,
const int iNbVertices)
{
CAT3DCustomRep * triangle = new CAT3DCustomRep();

int verticesArraySize = 9;
//Array containing vertices indices:
int * triangleIndices = new int[3];
//number of strips used to describe the torus:
int nbTriangleStrip = 0;
//Array containing the number of vertices used for each strip:
int * nbVertexPerTriangleStrip = NULL;

triangleIndices[0] = 0;
triangleIndices[1] = 3;
triangleIndices[2] = 6;

// Creation of the CAT3DFaceGP:

int * triangleStripIndices = NULL;
int nbTriangle = 1;
int * triangleFanIndices = NULL;
int nbTriangleFan = 0;
int * nbVertexPerTriangleFan = NULL;
float * TextureCoord = NULL;
int TextureFormat = 2;

CAT3DFaceGP * face = new CAT3DFaceGP(iVertices,
verticesArraySize,
iNormals,
verticesArraySize,
triangleIndices,
nbTriangle,
triangleStripIndices,
nbTriangleStrip,
nbVertexPerTriangleStrip,
triangleFanIndices,
nbTriangleFan,
nbVertexPerTriangleFan,
iTexture,
TextureFormat,
ALLOCATE_VERTICES | ALLOCATE_NORMALS | ALLOCATE_TEXTURES
);

CATGraphicAttributeSet attributs;
attributs.SetType(2);
triangle->AddGP(face, attributs);

//face->ComputeBox();

CATGraphicMaterial* myMaterial = new CATGraphicMaterial();
// light
myMaterial->SetColor(SpecularColor, 1.f,1.f,0.f);
myMaterial->SetCoefficient(SpecularCoef,1.f);
myMaterial->SetCoefficient(Shininess, 0.11f);

// transparency
myMaterial->SetCoefficient(TransparencyCoef, 0.f);

// texture
//CATTexturePixelImage* myTexture = CATTexturePixelImage::GetImage("c:\\tmp\\8988.bmp");
CATTexturePixelImage* myTexture = CATTexturePixelImage::GetImage("c:\\tmp\\8988.jpg");
myMaterial->SetTextureImage(myTexture);

// mapping operator
CATMappingOperator* myMappingOp = new CATMappingOperator();
myMaterial->SetMappingFunction(CATUserMapping);
myMaterial->SetMappingOperator(myMappingOp);

// wrapping
// dans ce cas la texture ne sera posee un peu comme un sticker sur un objet
myMaterial->SetTextureWrapping(CATCompS, CATClampingTexture);
myMaterial->SetTextureWrapping(CATCompT, CATClampingTexture);

// modulation to take into account the light
myMaterial->SetTextureFunction(CATModulateTexture);

// activate the visualization of the material
myMaterial->SetMaterialPropertiesActivation(1);


// put the material on your graphic representation
triangle->SetGraphicMaterial(myMaterial);
triangle->SetMaterialInheritance(MATERIAL_INHERIT);
return triangle;

}

//-------------------------------------------------------------------------
// Main
//-------------------------------------------------------------------------


CATFrmLayout *pCurrentFrmLayout = CATFrmLayout::GetCurrentLayout();

CATFrmWindow *pCurrentWindow = pCurrentFrmLayout->GetCurrentWindow();

CATViewer *pViewer = pCurrentWindow->GetViewer();

float * vertices = new float[9];
vertices[0] = 25; vertices[1] = 0; vertices[2] = 10;
vertices[3] = 50; vertices[4] = 10; vertices[5] = 20;
vertices[6] = 50; vertices[7] = 20; vertices[8] = 5;

float * normals = new float[9];
normals[0] = 0; normals[1] = 0; normals[2] = 1;
normals[3] = 0; normals[4] = 0; normals[5] = 1;
normals[6] = 0; normals[7] = 0; normals[8] = 1;

float * colors = new float[9];

colors[0] = 0; colors[1] = 0;
colors[2] = 1; colors[3] = 0;
colors[4] = 0; colors[5] = 1;

int nNbVert = 3;
CAT3DRep * pRep = CreateRep(vertices, normals, colors, nNbVert);
if(pRep)
{
pViewer->AddRep(pRep);
pViewer->Draw();
}
delete[] vertices;
delete[] normals;
delete[] colors;
bit
Участник
Участник
 
Сообщения: 166
Images: 3
Зарегистрирован: 24 июл 2008 11:45
Откуда: Минск

Re: Как приаттачить текстуру к репу?

Сообщение snezhinka » 24 июл 2008 12:36

Спасибо... Помогло :)
Аватара пользователя
snezhinka
Новичок
Новичок
 
Сообщения: 22
Зарегистрирован: 20 май 2008 11:10
Откуда: Минск


Вернуться в CAA-RADE

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2

cron