2011-02-23 10:52:22 +00:00
/*
2010-10-06 16:23:52 +00:00
* * * * * * BEGIN GPL LICENSE BLOCK * * * * *
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
* Contributor ( s ) : Chingiz Dyussenov , Arystanbek Dyussenov , Jan Diederich , Tod Liverseed ,
* Nathan Letwory
*
* * * * * * END GPL LICENSE BLOCK * * * * *
*/
2011-02-27 20:30:35 +00:00
/** \file blender/collada/ImageExporter.cpp
* \ ingroup collada
*/
2010-10-06 16:23:52 +00:00
# include "COLLADABUURI.h"
# include "COLLADASWImage.h"
2012-06-22 16:16:58 +00:00
extern " C " {
2010-10-06 16:23:52 +00:00
# include "DNA_texture_types.h"
2012-06-22 16:16:58 +00:00
# include "DNA_image_types.h"
# include "DNA_meshdata_types.h"
2010-10-06 16:23:52 +00:00
2018-06-08 08:07:48 +02:00
# include "BKE_customdata.h"
2010-10-06 16:23:52 +00:00
# include "BKE_global.h"
2012-06-22 16:16:58 +00:00
# include "BKE_image.h"
2010-10-18 06:41:16 +00:00
# include "BKE_main.h"
2012-06-22 16:16:58 +00:00
# include "BKE_mesh.h"
2010-10-06 16:23:52 +00:00
# include "BLI_fileops.h"
# include "BLI_path_util.h"
# include "BLI_string.h"
2012-06-22 16:16:58 +00:00
# include "IMB_imbuf_types.h"
}
# include "ImageExporter.h"
# include "MaterialExporter.h"
2010-10-06 16:23:52 +00:00
2011-09-07 18:23:30 +00:00
ImagesExporter : : ImagesExporter ( COLLADASW : : StreamWriter * sw , const ExportSettings * export_settings ) : COLLADASW : : LibraryImages ( sw ) , export_settings ( export_settings )
2012-06-12 22:05:33 +00:00
{
}
2010-10-06 16:23:52 +00:00
2018-06-08 08:07:48 +02:00
void ImagesExporter : : export_UV_Image ( Image * image , bool use_copies )
2012-06-22 16:16:58 +00:00
{
std : : string name ( id_name ( image ) ) ;
std : : string translated_name ( translate_id ( name ) ) ;
bool not_yet_exported = find ( mImages . begin ( ) , mImages . end ( ) , translated_name ) = = mImages . end ( ) ;
if ( not_yet_exported ) {
2012-11-15 15:59:58 +00:00
ImBuf * imbuf = BKE_image_acquire_ibuf ( image , NULL , NULL ) ;
2012-10-21 07:58:38 +00:00
if ( ! imbuf ) {
2012-07-09 22:41:44 +00:00
fprintf ( stderr , " Collada export: image does not exist: \n %s \n " , image - > name ) ;
return ;
}
2015-01-07 11:41:45 +11:00
bool is_dirty = ( imbuf - > userflags & IB_BITMAPDIRTY ) ! = 0 ;
2012-06-22 16:16:58 +00:00
ImageFormatData imageFormat ;
BKE_imbuf_to_image_format ( & imageFormat , imbuf ) ;
short image_source = image - > source ;
bool is_generated = image_source = = IMA_SRC_GENERATED ;
2015-04-06 10:40:12 -03:00
bool is_packed = BKE_image_has_packedfile ( image ) ;
2012-06-22 16:16:58 +00:00
char export_path [ FILE_MAX ] ;
char source_path [ FILE_MAX ] ;
char export_dir [ FILE_MAX ] ;
char export_file [ FILE_MAX ] ;
// Destination folder for exported assets
BLI_split_dir_part ( this - > export_settings - > filepath , export_dir , sizeof ( export_dir ) ) ;
2012-09-14 22:31:26 +00:00
if ( is_generated | | is_dirty | | use_copies | | is_packed ) {
2012-06-22 16:16:58 +00:00
// make absolute destination path
BLI_strncpy ( export_file , name . c_str ( ) , sizeof ( export_file ) ) ;
2015-01-24 16:48:23 +11:00
BKE_image_path_ensure_ext_from_imformat ( export_file , & imageFormat ) ;
2012-06-22 16:16:58 +00:00
BLI_join_dirfile ( export_path , sizeof ( export_path ) , export_dir , export_file ) ;
// make dest directory if it doesn't exist
BLI_make_existing_file ( export_path ) ;
}
2012-09-14 22:31:26 +00:00
if ( is_generated | | is_dirty | | is_packed ) {
2012-06-22 16:16:58 +00:00
// This image in its current state only exists in Blender memory.
// So we have to export it. The export will keep the image state intact,
// so the exported file will not be associated with the image.
2012-09-15 10:11:58 +00:00
if ( BKE_imbuf_write_as ( imbuf , export_path , & imageFormat , true ) = = 0 ) {
2012-06-22 16:16:58 +00:00
fprintf ( stderr , " Collada export: Cannot export image to: \n %s \n " , export_path ) ;
2012-07-09 22:41:44 +00:00
return ;
2012-06-22 16:16:58 +00:00
}
BLI_strncpy ( export_path , export_file , sizeof ( export_path ) ) ;
}
else {
// make absolute source path
BLI_strncpy ( source_path , image - > name , sizeof ( source_path ) ) ;
2018-06-05 15:10:33 +02:00
BLI_path_abs ( source_path , BKE_main_blendfile_path_from_global ( ) ) ;
2012-06-22 16:16:58 +00:00
BLI_cleanup_path ( NULL , source_path ) ;
if ( use_copies ) {
2018-06-08 08:07:48 +02:00
2012-06-22 16:16:58 +00:00
// This image is already located on the file system.
// But we want to create copies here.
2012-09-12 15:41:58 +00:00
// To move images into the same export directory.
2012-09-12 15:48:22 +00:00
// Note: If an image is already located in the export folder,
// then skip the copy (as it would result in a file copy error).
2012-09-12 15:41:58 +00:00
if ( BLI_path_cmp ( source_path , export_path ) ! = 0 ) {
if ( BLI_copy ( source_path , export_path ) ! = 0 ) {
fprintf ( stderr , " Collada export: Cannot copy image: \n source:%s \n dest :%s \n " , source_path , export_path ) ;
return ;
}
2012-06-22 16:16:58 +00:00
}
BLI_strncpy ( export_path , export_file , sizeof ( export_path ) ) ;
}
else {
2012-09-12 15:41:58 +00:00
// Do not make any copies, but use the source path directly as reference
2012-06-22 16:16:58 +00:00
// to the original image
BLI_strncpy ( export_path , source_path , sizeof ( export_path ) ) ;
}
}
COLLADASW : : Image img ( COLLADABU : : URI ( COLLADABU : : URI : : nativePathToUri ( export_path ) ) , translated_name , translated_name ) ; /* set name also to mNameNC. This helps other viewers import files exported from Blender better */
img . add ( mSW ) ;
2012-07-04 20:47:12 +00:00
fprintf ( stdout , " Collada export: Added image: %s \n " , export_file ) ;
2012-06-22 16:16:58 +00:00
mImages . push_back ( translated_name ) ;
2012-11-15 15:59:58 +00:00
BKE_image_release_ibuf ( image , imbuf , NULL ) ;
2012-06-22 16:16:58 +00:00
}
}
2011-03-18 14:06:13 +00:00
bool ImagesExporter : : hasImages ( Scene * sce )
{
2012-06-12 23:19:34 +00:00
LinkNode * node ;
2018-06-08 08:07:48 +02:00
2012-07-04 20:47:12 +00:00
for ( node = this - > export_settings - > export_set ; node ; node = node - > next ) {
2012-06-12 23:19:34 +00:00
Object * ob = ( Object * ) node - > link ;
2018-03-11 20:32:47 +01:00
for ( int a = 0 ; a < ob - > totcol ; a + + ) {
2012-06-12 22:05:33 +00:00
Material * ma = give_current_material ( ob , a + 1 ) ;
2011-03-18 14:06:13 +00:00
// no material, but check all of the slots
if ( ! ma ) continue ;
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
// TODO: find image textures in shader nodes
2011-03-18 14:06:13 +00:00
}
}
return false ;
}
2011-09-07 18:23:30 +00:00
void ImagesExporter : : exportImages ( Scene * sce )
2010-10-06 16:23:52 +00:00
{
2012-06-22 16:16:58 +00:00
openLibrary ( ) ;
2010-10-06 16:23:52 +00:00
2012-06-22 16:16:58 +00:00
MaterialFunctor mf ;
2012-06-23 22:03:31 +00:00
if ( this - > export_settings - > include_material_textures ) {
mf . forEachMaterialInExportSet < ImagesExporter > ( sce , * this , this - > export_settings - > export_set ) ;
}
2012-06-22 16:16:58 +00:00
closeLibrary ( ) ;
2010-10-06 16:23:52 +00:00
}
2012-06-22 16:16:58 +00:00
2010-10-06 16:23:52 +00:00
void ImagesExporter : : operator ( ) ( Material * ma , Object * ob )
{
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
// bool use_texture_copies = this->export_settings->use_texture_copies;
// TODO call export_UV_Image for every image in shader nodes
2010-10-06 16:23:52 +00:00
}