Adding Stages to Materials ???

Started by
-1 comments, last by Phillip Schuster 24 years, 7 months ago
Hi !

I am writing a PRO-Editor based on Power Render and it's using MFC. It has a real-time preview and combines 3ds2pro, editmat and setstage and includes a lot of other stuff. I can edit the materials and see the changes immediately in the 3D Object shown in the real time preview window.

I have a problem. I want to add Multitexturing in it. I did it like that:
- When the object gets loaded, I read out of Material->num_stages to find out how many stages there are already in there.
- When the user clicks on "New Stage", the programm adds one to material->num_stages (material->num_stages++) and sets the texture-number of the material to the first texture (The user can then change the texture of the second stage). This is done (material->texture_number[material->numstages-1] = texture_number.
- Then the program adds a new texture_coords-array to the object (like in setstage).

The problem I have:
When I add a new stage all controls (Combo, buttons and so on) do reflect the state of the material and are working fine. But the object does not show any change. (I have changed the render-method to a multitexturing render-method (T_TEX_MODULATE for example) but it does not work).
When I select another material the program takes the material and reads out all information editable in order to fill the combo-boxes, setting the sliders for color and alpha, and it also reads out material->num_stages. So, when I add a new stage to the material, select another one and then select the new-stage-material again, it just has one stage, although I have added a stage ???????


Here is my source:

This is what happens when the user clicks on "New Stage":
m_Materials is the combo-box showing all materials of the object
m_Stage is the combo with all stages (read from material->num_stages)
m_Texture is the combo displaying all loaded textures.

void CTextures::OnNewstage()
{
int mat = m_Materials.GetCurSel();
if (mat == -1) return;
int tex = m_Texture.GetCurSel();
if (tex == -1) return;

PR_MATERIAL *material;
material = &PR_ObjectMaterialList[mat];

material->num_stages++;
material->texture_number[0] = tex;
material->texture_number[material->num_stages-1] = tex;
material->environment_map[material->num_stages-1] = FALSE;
material->environment_axis[material->num_stages-1] = XAXIS;
CMainFrame* pFrame;
pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
CPowerRenderView* pView = (CPowerRenderView*)pFrame->GetActiveView();
if (pView->m_Object != NULL) {
pView->m_Object->InsertNewStage(material->num_stages-1);
}

m_Stage.ResetContent();
int numStages = material->num_stages;
int i;
for (i=0;i CString strNum;
strNum.Format("%d",i);
m_Stage.InsertString(-1,strNum);
}
m_Stage.SetCurSel(0);

}


This function(s) are called from OnNewstage and are allocating new tex-coords:

void C3DObject::InsertNewStage(long NumStages)
{
long numsegs, seg;
long stage;
numsegs = m_PRObject->num_segments;

for (seg=0;seg if (m_PRObject->segment_list[seg].num_tex_coords > 0) {
for (stage = 0; stage < m_PRObject->segment_list[seg].num_tex_coords; stage++) {
PR_free (m_PRObject->segment_list[seg].tex_coords[stage]);
}
}

m_PRObject->segment_list[seg].num_tex_coords = NumStages-1;

if (NumStages > 0)
{
for (stage = 0; stage < m_PRObject->segment_list[seg].num_tex_coords; stage++)
{
m_PRObject->segment_list[seg].tex_coords[stage] = (PR_TEX_COORD*)PR_malloc (m_PRObject->segment_list[seg].num_faces * sizeof (PR_TEX_COORD));
CopyTexCoords (&m_PRObject->segment_list[seg], stage);
}
}
}
}

void C3DObject::CopyTexCoords(PR_SEGMENT *seg, PR_DWORD stage)
{
PR_DWORD facenum;
PR_FACE *face;
PR_TEX_COORD *texcoord;
PR_FACE_DATA_REAL *fd;
PR_DWORD i;

texcoord = seg->tex_coords[stage];

for (facenum = 0; facenum < seg->num_faces; facenum++)
{
face = &seg->face_list[facenum];
fd = (PR_FACE_DATA_REAL *)&face->face_data;
for (i = 0; i < 3; i++)
{
//BUG texscale !
texcoord->u = fd->u * 1.0f;<BR> texcoord->v = fd->v * 1.0f;<BR> }<BR> texcoord++;<BR> }<BR>}<P><BR>I don't see any errors here, can someone please tell me what's wrong.<P>Phillip

Phillip Schuster

This topic is closed to new replies.

Advertisement