Importer base for Chingiz.
This commit is contained in:
@@ -170,6 +170,9 @@ BF_OPENCOLLADA_LIBPATH = '/usr/lib'
|
||||
BF_PCRE = ''
|
||||
BF_PCRE_LIB = 'pcre'
|
||||
BF_PCRE_LIBPATH = '/usr/lib'
|
||||
BF_EXPAT = '/usr'
|
||||
BF_EXPAT_LIB = 'expat'
|
||||
BF_EXPAT_LIBPATH = '/usr/lib'
|
||||
|
||||
##
|
||||
CC = 'gcc'
|
||||
|
@@ -1,3 +1,4 @@
|
||||
struct Scene;
|
||||
|
||||
class DocumentExporter
|
||||
{
|
||||
|
238
source/blender/collada/DocumentImporter.cpp
Normal file
238
source/blender/collada/DocumentImporter.cpp
Normal file
@@ -0,0 +1,238 @@
|
||||
#include "COLLADAFWStableHeaders.h"
|
||||
#include "COLLADAFWIWriter.h"
|
||||
#include "COLLADAFWRoot.h"
|
||||
#include "COLLADAFWNode.h"
|
||||
#include "COLLADAFWVisualScene.h"
|
||||
#include "COLLADAFWInstanceGeometry.h"
|
||||
#include "COLLADAFWFileInfo.h"
|
||||
#include "COLLADAFWRoot.h"
|
||||
#include "COLLADAFWLight.h"
|
||||
#include "COLLADAFWImage.h"
|
||||
#include "COLLADAFWMaterial.h"
|
||||
#include "COLLADAFWGeometry.h"
|
||||
#include "COLLADAFWMesh.h"
|
||||
|
||||
#include "COLLADASaxFWLLoader.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_context.h"
|
||||
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "ED_object.h"
|
||||
|
||||
#include "DocumentImporter.h"
|
||||
}
|
||||
|
||||
|
||||
/** Class that needs to be implemented by a writer.
|
||||
IMPORTANT: The write functions are called in arbitrary order.*/
|
||||
class Writer: public COLLADAFW::IWriter
|
||||
{
|
||||
private:
|
||||
std::string mFilename;
|
||||
|
||||
std::vector<COLLADAFW::VisualScene> mVisualScenes;
|
||||
|
||||
bContext *mContext;
|
||||
|
||||
class UnitConverter
|
||||
{
|
||||
private:
|
||||
COLLADAFW::FileInfo::Unit mUnit;
|
||||
COLLADAFW::FileInfo::UpAxisType mUpAxis;
|
||||
public:
|
||||
UnitConverter(COLLADAFW::FileInfo::UpAxisType upAxis, COLLADAFW::FileInfo::Unit& unit) :
|
||||
mUpAxis(upAxis), mUnit(unit)
|
||||
{
|
||||
}
|
||||
|
||||
// TODO
|
||||
// convert vector vec from COLLADA format to Blender
|
||||
void convertVec3(float *vec)
|
||||
{
|
||||
}
|
||||
|
||||
// TODO need also for angle conversion, time conversion...
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
/** Constructor. */
|
||||
Writer(bContext *C, const char *filename) : mContext(C), mFilename(filename) {};
|
||||
|
||||
/** Destructor. */
|
||||
~Writer() {};
|
||||
|
||||
bool write()
|
||||
{
|
||||
COLLADASaxFWL::Loader loader;
|
||||
COLLADAFW::Root root(&loader, this);
|
||||
|
||||
// XXX report error
|
||||
if (!root.loadDocument(mFilename))
|
||||
return false;
|
||||
}
|
||||
|
||||
/** This method will be called if an error in the loading process occurred and the loader cannot
|
||||
continue to to load. The writer should undo all operations that have been performed.
|
||||
@param errorMessage A message containing informations about the error that occurred.
|
||||
*/
|
||||
virtual void cancel(const COLLADAFW::String& errorMessage)
|
||||
{
|
||||
}
|
||||
|
||||
/** This is the method called. The writer hast to prepare to receive data.*/
|
||||
virtual void start()
|
||||
{
|
||||
}
|
||||
|
||||
/** This method is called after the last write* method. No other methods will be called after this.*/
|
||||
virtual void finish()
|
||||
{
|
||||
// using mVisualScenes, do:
|
||||
// - write <node> data to Objects: materials, transforms, etc.
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the global document asset.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeGlobalAsset ( const COLLADAFW::FileInfo* asset )
|
||||
{
|
||||
// XXX take up_axis, unit into account
|
||||
// COLLADAFW::FileInfo::Unit unit = asset->getUnit();
|
||||
// COLLADAFW::FileInfo::UpAxisType upAxis = asset->getUpAxisType();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the scene.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeScene ( const COLLADAFW::Scene* scene )
|
||||
{
|
||||
// XXX could store the scene id, but do nothing for now
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the entire visual scene.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeVisualScene ( const COLLADAFW::VisualScene* visualScene )
|
||||
{
|
||||
// for the sake of clarity link nodes to geometries at a later stage
|
||||
mVisualScenes.push_back(*visualScene);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must handle all nodes contained in the
|
||||
library nodes.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeLibraryNodes ( const COLLADAFW::LibraryNodes* libraryNodes )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the geometry.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeGeometry ( const COLLADAFW::Geometry* geometry )
|
||||
{
|
||||
// - create a mesh object
|
||||
// - enter editmode getting editmesh
|
||||
// - write geometry
|
||||
// - exit editmode
|
||||
|
||||
// check geometry->getType() first
|
||||
COLLADAFW::Mesh *mesh = (COLLADAFW::Mesh*)geometry;
|
||||
|
||||
// create a mesh object
|
||||
Object *ob = ED_object_add_type(mContext, OB_MESH);
|
||||
Mesh *me = (Mesh*)ob->data;
|
||||
|
||||
// enter editmode
|
||||
ED_object_enter_editmode(mContext, 0);
|
||||
|
||||
EditMesh *em = BKE_mesh_get_editmesh(me);
|
||||
|
||||
// write geometry
|
||||
// currently only support <triangles>
|
||||
|
||||
BKE_mesh_end_editmesh(me, em);
|
||||
|
||||
// exit editmode
|
||||
ED_object_exit_editmode(mContext, EM_FREEDATA);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the material.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeMaterial( const COLLADAFW::Material* material )
|
||||
{
|
||||
// TODO: create and store a material.
|
||||
// Let it have 0 users for now.
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the effect.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeEffect( const COLLADAFW::Effect* effect )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the camera.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeCamera( const COLLADAFW::Camera* camera )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the image.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeImage( const COLLADAFW::Image* image )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the light.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeLight( const COLLADAFW::Light* light )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the Animation.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeAnimation( const COLLADAFW::Animation* animation )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the AnimationList.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeAnimationList( const COLLADAFW::AnimationList* animationList )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the skin controller data.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeSkinControllerData( const COLLADAFW::SkinControllerData* skinControllerData )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** When this method is called, the writer must write the controller.
|
||||
@return The writer should return true, if writing succeeded, false otherwise.*/
|
||||
virtual bool writeController( const COLLADAFW::Controller* Controller )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void DocumentImporter::import(bContext *C, const char *filename)
|
||||
{
|
||||
Writer w(C, filename);
|
||||
w.write();
|
||||
}
|
8
source/blender/collada/DocumentImporter.h
Normal file
8
source/blender/collada/DocumentImporter.h
Normal file
@@ -0,0 +1,8 @@
|
||||
struct Main;
|
||||
struct bContext;
|
||||
|
||||
class DocumentImporter
|
||||
{
|
||||
public:
|
||||
void import(bContext *C, const char *filename);
|
||||
};
|
@@ -4,7 +4,7 @@ Import ('env')
|
||||
sources = env.Glob('*.cpp')
|
||||
|
||||
# relative paths to include dirs, space-separated, string
|
||||
incs = '../blenlib ../blenkernel %s/COLLADAStreamWriter/include %s/COLLADABaseUtils/include' % (env['BF_OPENCOLLADA'], env['BF_OPENCOLLADA']) + ' ../makesdna'
|
||||
incs = '../blenlib ../blenkernel ../makesdna ../makesrna ../editors/include [OPENCOLLADA]/COLLADAStreamWriter/include [OPENCOLLADA]/COLLADABaseUtils/include [OPENCOLLADA]/COLLADAFramework/include [OPENCOLLADA]/COLLADASaxFrameworkLoader/include '.replace('[OPENCOLLADA]', env['BF_OPENCOLLADA'])
|
||||
|
||||
env.BlenderLib ('bf_collada', sources, Split(incs), [], libtype='core', priority=200 )
|
||||
|
||||
|
@@ -1,11 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_context.h"
|
||||
|
||||
#include "DocumentExporter.h"
|
||||
#include "DocumentImporter.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
int collada_import(Scene *sce, const char *filepath)
|
||||
int collada_import(bContext *C, const char *filepath)
|
||||
{
|
||||
DocumentImporter imp;
|
||||
imp.import(C, filepath);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#ifndef BLENDER_COLLADA_H
|
||||
#define BLENDER_COLLADA_H
|
||||
|
||||
#include "BKE_scene.h"
|
||||
struct bContext;
|
||||
struct Scene;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -9,7 +10,7 @@ extern "C" {
|
||||
/*
|
||||
* both return 1 on success, 0 on error
|
||||
*/
|
||||
int collada_import(Scene *sce, const char *filepath);
|
||||
int collada_import(bContext *C, const char *filepath);
|
||||
int collada_export(Scene *sce, const char *filepath);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -45,6 +45,7 @@ struct ModifierData;
|
||||
/* object_edit.c */
|
||||
void ED_operatortypes_object(void);
|
||||
void ED_keymap_object(struct wmWindowManager *wm);
|
||||
struct Object *ED_object_add_type(struct bContext *C, int type);
|
||||
|
||||
/* send your own notifier for select! */
|
||||
void ED_base_object_select(struct Base *base, short mode);
|
||||
|
@@ -290,6 +290,12 @@ static Object *object_add_type(bContext *C, int type)
|
||||
return ob;
|
||||
}
|
||||
|
||||
/* for COLLADA imp/exp */
|
||||
Object *ED_object_add_type(bContext *C, int type)
|
||||
{
|
||||
return object_add_type(C, type);
|
||||
}
|
||||
|
||||
/* for object add operator */
|
||||
static int object_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
|
@@ -279,6 +279,7 @@ static void info_filemenu(bContext *C, uiLayout *layout, void *arg_unused)
|
||||
// XXX: these should move
|
||||
uiItemS(layout);
|
||||
uiLayoutContext(layout, WM_OP_INVOKE_AREA);
|
||||
uiItemO(layout, NULL, 0, "WM_OT_collada_import");
|
||||
uiItemO(layout, NULL, 0, "WM_OT_collada_export");
|
||||
|
||||
#if 0
|
||||
|
@@ -634,9 +634,9 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
|
||||
//WM_write_file(C, filename, op->reports);
|
||||
collada_export(CTX_data_scene(C), filename);
|
||||
|
||||
WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL);
|
||||
/* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
|
||||
|
||||
return 0;
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static void WM_OT_collada_export(wmOperatorType *ot)
|
||||
@@ -653,6 +653,50 @@ static void WM_OT_collada_export(wmOperatorType *ot)
|
||||
RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
|
||||
}
|
||||
|
||||
static int wm_collada_import_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
{
|
||||
// XXX: temporary
|
||||
RNA_string_set(op->ptr, "filename", "/tmp/test.dae");
|
||||
|
||||
WM_event_add_fileselect(C, op);
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
|
||||
/* function used for WM_OT_save_mainfile too */
|
||||
static int wm_collada_import_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
char filename[FILE_MAX];
|
||||
|
||||
if(RNA_property_is_set(op->ptr, "filename"))
|
||||
RNA_string_get(op->ptr, "filename", filename);
|
||||
else {
|
||||
BLI_strncpy(filename, G.sce, FILE_MAX);
|
||||
untitled(filename);
|
||||
}
|
||||
|
||||
//WM_write_file(C, filename, op->reports);
|
||||
collada_import(CTX_data_scene(C), filename);
|
||||
|
||||
/* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static void WM_OT_collada_import(wmOperatorType *ot)
|
||||
{
|
||||
ot->name= "Collada Import";
|
||||
ot->idname= "WM_OT_collada_import";
|
||||
|
||||
ot->invoke= wm_collada_import_invoke;
|
||||
ot->exec= wm_collada_import_exec;
|
||||
ot->poll= WM_operator_winactive;
|
||||
|
||||
ot->flag= 0;
|
||||
|
||||
RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1498,6 +1542,7 @@ void wm_operatortype_init(void)
|
||||
|
||||
/* XXX: move these */
|
||||
WM_operatortype_append(WM_OT_collada_export);
|
||||
WM_operatortype_append(WM_OT_collada_import);
|
||||
}
|
||||
|
||||
/* default keymap for windows and screens, only call once per WM */
|
||||
|
@@ -150,6 +150,7 @@ def setup_staticlibs(lenv):
|
||||
if lenv['WITH_BF_COLLADA']:
|
||||
libincs += Split(lenv['BF_OPENCOLLADA_LIBPATH'])
|
||||
libincs += Split(lenv['BF_PCRE_LIBPATH'])
|
||||
libincs += Split(lenv['BF_EXPAT_LIBPATH'])
|
||||
|
||||
|
||||
return statlibs, libincs
|
||||
@@ -198,6 +199,7 @@ def setup_syslibs(lenv):
|
||||
if lenv['WITH_BF_COLLADA']:
|
||||
syslibs.append(lenv['BF_OPENCOLLADA_LIB'])
|
||||
syslibs.append(lenv['BF_PCRE_LIB'])
|
||||
syslibs.append(lenv['BF_EXPAT_LIB'])
|
||||
|
||||
|
||||
syslibs += lenv['LLIBS']
|
||||
|
@@ -49,7 +49,7 @@ def validate_arguments(args, bc):
|
||||
'WITH_BF_FREETYPE', 'BF_FREETYPE', 'BF_FREETYPE_INC', 'BF_FREETYPE_LIB', 'BF_FREETYPE_LIBPATH',
|
||||
'WITH_BF_QUICKTIME', 'BF_QUICKTIME', 'BF_QUICKTIME_INC', 'BF_QUICKTIME_LIB', 'BF_QUICKTIME_LIBPATH',
|
||||
'WITH_BF_STATICOPENGL', 'BF_OPENGL', 'BF_OPENGL_INC', 'BF_OPENGL_LIB', 'BF_OPENGL_LIBPATH', 'BF_OPENGL_LIB_STATIC',
|
||||
'WITH_BF_COLLADA', 'BF_COLLADA', 'BF_COLLADA_INC', 'BF_COLLADA_LIB', 'BF_OPENCOLLADA', 'BF_OPENCOLLADA_LIB', 'BF_OPENCOLLADA_LIBPATH', 'BF_PCRE', 'BF_PCRE_LIB', 'BF_PCRE_LIBPATH',
|
||||
'WITH_BF_COLLADA', 'BF_COLLADA', 'BF_COLLADA_INC', 'BF_COLLADA_LIB', 'BF_OPENCOLLADA', 'BF_OPENCOLLADA_LIB', 'BF_OPENCOLLADA_LIBPATH', 'BF_PCRE', 'BF_PCRE_LIB', 'BF_PCRE_LIBPATH', 'BF_EXPAT', 'BF_EXPAT_LIB', 'BF_EXPAT_LIBPATH',
|
||||
'WITH_BF_PLAYER',
|
||||
'WITH_BF_NOBLENDER',
|
||||
'WITH_BF_BINRELOC',
|
||||
@@ -319,6 +319,9 @@ def read_opts(cfg, args):
|
||||
('BF_PCRE', 'PCRE base path', ''),
|
||||
('BF_PCRE_LIB', 'PCRE library', ''),
|
||||
('BF_PCRE_LIBPATH', 'PCRE library path', ''),
|
||||
('BF_EXPAT', 'Expat base path', ''),
|
||||
('BF_EXPAT_LIB', 'Expat library', ''),
|
||||
('BF_EXPAT_LIBPATH', 'Expat library path', ''),
|
||||
|
||||
(BoolVariable('WITH_BF_PLAYER', 'Build blenderplayer if true', False)),
|
||||
(BoolVariable('WITH_BF_NOBLENDER', 'Do not build blender if true', False)),
|
||||
|
Reference in New Issue
Block a user