@ -214,7 +214,7 @@ namespace MaterialEditor
CRenderPassProxy CNelMaterialProxy : : getPass ( unsigned long i )
CRenderPassProxy CNelMaterialProxy : : getPass ( unsigned long i )
{
{
if ( material- > count ( ) > = i )
if ( i > = material- > count ( ) )
return CRenderPassProxy ( NULL ) ;
return CRenderPassProxy ( NULL ) ;
else
else
return CRenderPassProxy ( material - > getPass ( i ) ) ;
return CRenderPassProxy ( material - > getPass ( i ) ) ;
@ -228,11 +228,11 @@ namespace MaterialEditor
CNel3DInterface : : CNel3DInterface ( )
CNel3DInterface : : CNel3DInterface ( )
{
{
mat = new NL3D : : CDynMaterial ( ) ;
shaderManager = new NL3D : : CShaderManager ( ) ;
shaderManager = new NL3D : : CShaderManager ( ) ;
driver = NULL ;
driver = NULL ;
scene = NULL ;
scene = NULL ;
mouseListener = NULL ;
mouseListener = NULL ;
subMatId = 0 ;
}
}
CNel3DInterface : : ~ CNel3DInterface ( )
CNel3DInterface : : ~ CNel3DInterface ( )
@ -244,6 +244,9 @@ namespace MaterialEditor
bool CNel3DInterface : : loadMaterial ( const char * fname )
bool CNel3DInterface : : loadMaterial ( const char * fname )
{
{
if ( currentShape . empty ( ) )
return false ;
NLMISC : : CIFile file ;
NLMISC : : CIFile file ;
if ( ! file . open ( fname , true ) )
if ( ! file . open ( fname , true ) )
return false ;
return false ;
@ -253,6 +256,7 @@ namespace MaterialEditor
return false ;
return false ;
newMaterial ( ) ;
newMaterial ( ) ;
NL3D : : CDynMaterial * mat = currentShape . getMaterial ( subMatId ) . getObjectPtr ( ) - > getDynMat ( ) ;
mat - > clear ( ) ;
mat - > clear ( ) ;
mat - > serial ( xml ) ;
mat - > serial ( xml ) ;
file . close ( ) ;
file . close ( ) ;
@ -262,6 +266,9 @@ namespace MaterialEditor
bool CNel3DInterface : : saveMaterial ( const char * fname )
bool CNel3DInterface : : saveMaterial ( const char * fname )
{
{
if ( currentShape . empty ( ) )
return false ;
NLMISC : : COFile file ;
NLMISC : : COFile file ;
if ( ! file . open ( fname , false , true ) )
if ( ! file . open ( fname , false , true ) )
return false ;
return false ;
@ -270,7 +277,8 @@ namespace MaterialEditor
if ( ! xml . init ( & file ) )
if ( ! xml . init ( & file ) )
return false ;
return false ;
mat - > serial ( xml ) ;
currentShape . getMaterial ( subMatId ) . getObjectPtr ( ) - > getDynMat ( ) - > serial ( xml ) ;
xml . flush ( ) ;
xml . flush ( ) ;
file . close ( ) ;
file . close ( ) ;
@ -279,13 +287,30 @@ namespace MaterialEditor
void CNel3DInterface : : newMaterial ( )
void CNel3DInterface : : newMaterial ( )
{
{
delete mat ;
if ( currentShape . empty ( ) )
mat = new NL3D : : CDynMaterial ( ) ;
return ;
currentShape . getMaterial ( 0 ) . getObjectPtr ( ) - > getDynMat ( ) - > clear ( ) ;
}
bool CNel3DInterface : : selectSubMaterial ( int id )
{
if ( currentShape . empty ( ) )
return false ;
if ( currentShape . getNumMaterials ( ) < id )
return false ;
subMatId = id ;
return true ;
}
}
CNelMaterialProxy CNel3DInterface : : getMaterial ( )
CNelMaterialProxy CNel3DInterface : : getMaterial ( )
{
{
NL3D : : CDynMaterial * mat = NULL ;
if ( ! currentShape . empty ( ) )
mat = currentShape . getMaterial ( subMatId ) . getObjectPtr ( ) - > getDynMat ( ) ;
return CNelMaterialProxy ( mat ) ;
return CNelMaterialProxy ( mat ) ;
}
}
@ -429,6 +454,12 @@ namespace MaterialEditor
clearScene ( ) ;
clearScene ( ) ;
currentShape = instance ;
currentShape = instance ;
int c = currentShape . getNumMaterials ( ) ;
for ( int i = 0 ; i < c ; i + + )
currentShape . getMaterial ( i ) . getObjectPtr ( ) - > createDynMat ( ) ;
subMatId = 0 ;
setupCamera ( ) ;
setupCamera ( ) ;
return true ;
return true ;
@ -442,6 +473,7 @@ namespace MaterialEditor
return ;
return ;
scene - > deleteInstance ( currentShape ) ;
scene - > deleteInstance ( currentShape ) ;
currentShape = NL3D : : UInstance ( ) ;
currentShape = NL3D : : UInstance ( ) ;
subMatId = 0 ;
}
}
if ( driver = = NULL )
if ( driver = = NULL )