From Andrew Lorino and Mike Weiblen, COLLADA 1.4.1 ReaderWriter, kindly developed and donated by Sony Computer Entertainment Inc. US R&D.
This commit is contained in:
@@ -12,6 +12,8 @@ COMPILE_EXAMPLES ?= no
|
||||
|
||||
# follows are dependenices on the various plugins.
|
||||
|
||||
COLLADA_INSTALLED ?= no
|
||||
|
||||
GDAL_INSTALLED ?= no
|
||||
JASPER_INSTALLED ?= no
|
||||
|
||||
|
||||
@@ -108,6 +108,10 @@ ifeq ($(GDAL_INSTALLED),yes)
|
||||
PLUGIN_DIRS += gdal
|
||||
endif
|
||||
|
||||
ifeq ($(COLLADA_INSTALLED),yes)
|
||||
PLUGIN_DIRS += gdal
|
||||
endif
|
||||
|
||||
ifeq ($(XINE_INSTALLED),yes)
|
||||
PLUGIN_DIRS += xine
|
||||
endif
|
||||
@@ -222,6 +226,7 @@ ifeq ($(PRODUCER_INSTALLED),yes)
|
||||
osglogicop \
|
||||
osglogo \
|
||||
osgmotionblur \
|
||||
osgmove \
|
||||
osgmovie \
|
||||
osgmultitexture \
|
||||
osgmultiplecameras \
|
||||
|
||||
217
VisualStudio/osgPlugins/dae/dae.dsp
Normal file
217
VisualStudio/osgPlugins/dae/dae.dsp
Normal file
@@ -0,0 +1,217 @@
|
||||
# Microsoft Developer Studio Project File - Name="osgPlugin COLLADA dae" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=osgPlugin COLLADA dae - Win32 Release
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "dot_dae.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "dot_dae.mak" CFG="osgPlugin COLLADA dae - Win32 Release"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "osgPlugin COLLADA dae - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "osgPlugin COLLADA dae - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "osgPlugin COLLADA dae - Win32 Release Static" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "osgPlugin COLLADA dae - Win32 Debug Static" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "osgPlugin COLLADA dae - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "../../../bin/$(PlatformName)"
|
||||
# PROP Intermediate_Dir "$(PlatformName)/$(ConfigurationName)"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
F90=df.exe
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /I "../../../../3rdParty/include/collada-dom" /I "../../../../3rdParty/include/collada-dom/1.4" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "_CRT_SECURE_NO_DEPRECATE" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 libcollada_dom.lib libcollada_dae.lib libcollada_STLDatabase.lib libcollada_LIBXMLPlugin.lib libcollada_stdErrPlugin.lib libxml2_a.lib iconv_a.lib zlib.lib wsock32.lib OpenThreadsWin32.lib /nologo /dll /machine:I386 /nodefaultlib:"LIBC" /out:"$(OutDir)/osgdb_dae.dll" /implib:"../../../lib/$(PlatformName)/osgdb_dae.lib" /libpath:"../../../lib/$(PlatformName)" /libpath:"../../../../OpenThreads/lib/$(PlatformName)" /libpath:"../../../../Producer/lib/$(PlatformName)" /libpath:"../../../../3rdParty/lib/$(PlatformName)" /libpath:"../../../../3rdParty/lib"
|
||||
# SUBTRACT LINK32 /nodefaultlib
|
||||
|
||||
!ELSEIF "$(CFG)" == "osgPlugin COLLADA dae - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "../../../bin/$(PlatformName)"
|
||||
# PROP Intermediate_Dir "$(PlatformName)/$(ConfigurationName)"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
F90=df.exe
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /vmg /GR /GX /Zi /Od /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /I "../../../../3rdParty/include/collada-dom" /I "../../../../3rdParty/include/collada-dom/1.4" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 libcollada_dom.lib libcollada_dae.lib libcollada_STLDatabase.lib libcollada_LIBXMLPlugin.lib libcollada_stdErrPlugin.lib libxml2_a.lib iconv_a.lib zlib.lib wsock32.lib OpenThreadsWin32d.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"LIBC" /out:"$(OutDir)/osgdb_daeD.dll" /pdbtype:sept /implib:"../../../lib/$(PlatformName)/osgdb_daeD.lib" /libpath:"../../../lib/$(PlatformName)" /libpath:"../../../../OpenThreads/lib/$(PlatformName)" /libpath:"../../../../Producer/lib/$(PlatformName)" /libpath:"../../../../3rdParty/lib/$(PlatformName)" /libpath:"../../../../3rdParty/lib"
|
||||
# SUBTRACT LINK32 /nodefaultlib
|
||||
|
||||
!ELSEIF "$(CFG)" == "osgPlugin COLLADA dae - Win32 Release Static"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "../../../lib"
|
||||
# PROP BASE Intermediate_Dir "Release_Static"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "../../../lib/$(PlatformName)"
|
||||
# PROP Intermediate_Dir "$(PlatformName)/$(ConfigurationName)_Static"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
F90=df.exe
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "OSG_LIBRARY_STATIC" /D "OT_LIBRARY_STATIC" /D "PR_LIBRARY_STATIC" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "WIN32" /D "OSG_LIBRARY_STATIC" /D "OT_LIBRARY_STATIC" /D "PR_LIBRARY_STATIC" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_CRT_SECURE_NO_DEPRECATE" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nodefaultlib /nologo /out:"$(OutDir)/osgdb_dae_s.lib"
|
||||
# SUBTRACT LIB32 /nodefaultlib
|
||||
|
||||
!ELSEIF "$(CFG)" == "osgPlugin COLLADA dae - Win32 Debug Static"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "../../../lib"
|
||||
# PROP BASE Intermediate_Dir "Debug_Static"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "../../../lib/$(PlatformName)"
|
||||
# PROP Intermediate_Dir "$(PlatformName)/$(ConfigurationName)_Static"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
F90=df.exe
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "OSG_LIBRARY_STATIC" /D "OT_LIBRARY_STATIC" /D "PR_LIBRARY_STATIC" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /vmg /GR /GX /Z7 /Od /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "_WINDOWS" /D "OSG_LIBRARY_STATIC" /D "OT_LIBRARY_STATIC" /D "PR_LIBRARY_STATIC" /D "_MBCS" /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nodefaultlib /nologo /out:"$(OutDir)/osgdb_daeD_s.lib"
|
||||
# SUBTRACT LIB32 /nodefaultlib
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "osgPlugin COLLADA dae - Win32 Release"
|
||||
# Name "osgPlugin COLLADA dae - Win32 Debug"
|
||||
# Name "osgPlugin COLLADA dae - Win32 Release Static"
|
||||
# Name "osgPlugin COLLADA dae - Win32 Debug Static"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeReader.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeRGeometry.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeRMaterials.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeRSceneObjects.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeRTransforms.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeWGeometry.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeWMaterials.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeWSceneObjects.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeWTransforms.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeWriter.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\domSourceReader.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\ReaderWriterDAE.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
|
||||
# Begin Group "Header Files"
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeConverter.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeUtils.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\daeWriter.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
SOURCE=..\..\..\src\osgPlugins\dae\domSourceReader.h
|
||||
# End Source File
|
||||
# End Group
|
||||
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
37
src/osgPlugins/dae/GNUmakefile
Normal file
37
src/osgPlugins/dae/GNUmakefile
Normal file
@@ -0,0 +1,37 @@
|
||||
TOPDIR = ../../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
domSourceReader.cpp \
|
||||
daeRMaterials.cpp \
|
||||
daeRTransforms.cpp \
|
||||
daeRGeometry.cpp \
|
||||
daeRSceneObjects.cpp \
|
||||
daeReader.cpp \
|
||||
daeWGeometry.cpp \
|
||||
daeWMaterials.cpp \
|
||||
daeWTransforms.cpp \
|
||||
daeWSceneObjects.cpp \
|
||||
daeWriter.cpp \
|
||||
ReaderWriterDAE.cpp
|
||||
|
||||
COLLADA_DAE_HOME ?= ${HOME}/3rdParty/collada/trunk
|
||||
COLLADA_DAE_INCLUDES = -I$(COLLADA_DAE_HOME)/include -I$(COLLADA_DAE_HOME)/include/1.4
|
||||
|
||||
ifeq ($(COLLADA_DEBUG_LIBS),yes)
|
||||
COLLADA_DAE_LIBS = -L$(COLLADA_DAE_HOME)/lib-dbg
|
||||
else
|
||||
COLLADA_DAE_LIBS = -L$(COLLADA_DAE_HOME)/lib
|
||||
endif
|
||||
|
||||
COLLADA_DAE_LIBS += -lcollada_dae -lcollada_dom -lcollada_dae -lcollada_STLDatabase -lcollada_LIBXMLPlugin -lcollada_stdErrPlugin -lxml2
|
||||
|
||||
INC += $(COLLADA_DAE_INCLUDES) -I$(THISDIR)
|
||||
|
||||
LIBS += $(OSG_LIBS) $(OTHER_LIBS) $(COLLADA_DAE_LIBS)
|
||||
|
||||
TARGET_BASENAME = dae
|
||||
include $(TOPDIR)/Make/cygwin_plugin_def
|
||||
PLUGIN = $(PLUGIN_PREFIX)$(TARGET_BASENAME).$(PLUGIN_EXT)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
53
src/osgPlugins/dae/README.txt
Normal file
53
src/osgPlugins/dae/README.txt
Normal file
@@ -0,0 +1,53 @@
|
||||
osgPlugins/dae/README.txt - Mike Weiblen http://mew.cx/
|
||||
|
||||
OSG reader/writer plugin for the COLLADA digital asset exchange (DAE) schema.
|
||||
See http://collada.org/ and http://khronos.org/collada/ for further info.
|
||||
|
||||
|
||||
RUNTIME USAGE EXAMPLES
|
||||
|
||||
osgviewer myFile.dae
|
||||
osgconv myFile.osg myFile.dae
|
||||
|
||||
|
||||
RUNTIME PLUGIN OPTIONS
|
||||
|
||||
Import Options
|
||||
--------------
|
||||
none
|
||||
|
||||
Export Options
|
||||
--------------
|
||||
polygon : export polygons as COLLADA polygons instead of polylists.
|
||||
This option can be used for if polylists are not supported.
|
||||
ex : osgconv -O polygon myFile.osg myFile.dae
|
||||
|
||||
|
||||
BUILD DEPENDENCIESmaterial
|
||||
|
||||
- COLLADA DOM (document object model) v1.4.1
|
||||
see http://sourceforge.net/projects/collada-dom
|
||||
svn export -r 34 https://svn.sourceforge.net/svnroot/collada-dom/trunk
|
||||
|
||||
- libxml2
|
||||
|
||||
- iconv
|
||||
|
||||
UNIX BUILD
|
||||
|
||||
set the env vars:
|
||||
|
||||
COLLDA_INSTEAD = yes
|
||||
COLLADA_DAE_HOME = root directory of COLLADA DOM
|
||||
|
||||
And if you've compiled the debug version of the COLLADA DOM then define:
|
||||
|
||||
COLLADA_DEBUG_LIBS = yes
|
||||
|
||||
Note, Collda svn trunk currently defaults to debug build.
|
||||
|
||||
The above env vars can also be setup in your own custom Make/depdendencies file (copy this and point
|
||||
to the locally modified copy using the env var OSG_DEPENDCIES so the the OSG's build system can find
|
||||
it.
|
||||
|
||||
//EOF
|
||||
124
src/osgPlugins/dae/ReaderWriterDAE.cpp
Normal file
124
src/osgPlugins/dae/ReaderWriterDAE.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This application is open source and may be redistributed and/or modified
|
||||
* freely and without restriction, both in commericial and non commericial
|
||||
* applications, as long as this copyright notice is maintained.
|
||||
*
|
||||
* This application 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/Registry>
|
||||
|
||||
#include "daeReader.h"
|
||||
#include "daeWriter.h"
|
||||
|
||||
#define EXTENSION_NAME "dae"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// OSG reader/writer plugin for the COLLADA 1.4.x ".dae" format.
|
||||
// See http://collada.org/ and http://khronos.org/collada/
|
||||
|
||||
class ReaderWriterDAE : public osgDB::ReaderWriter
|
||||
{
|
||||
public:
|
||||
ReaderWriterDAE() {}
|
||||
|
||||
const char* className() const { return "COLLADA 1.4.x DAE reader/writer"; }
|
||||
|
||||
bool acceptsExtension(const std::string& extension) const
|
||||
{
|
||||
return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME );
|
||||
}
|
||||
|
||||
ReadResult readNode(const std::string&, const Options*) const;
|
||||
|
||||
WriteResult writeNode(const osg::Node&, const std::string&, const Options*) const;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
osgDB::ReaderWriter::ReadResult
|
||||
ReaderWriterDAE::readNode(const std::string& fname,
|
||||
const osgDB::ReaderWriter::Options* options) const
|
||||
{
|
||||
std::string ext( osgDB::getLowerCaseFileExtension(fname) );
|
||||
if( ! acceptsExtension(ext) ) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
std::string fileName( osgDB::findDataFile( fname, options ) );
|
||||
if( fileName.empty() ) return ReadResult::FILE_NOT_FOUND;
|
||||
|
||||
osg::notify(osg::INFO) << "ReaderWriterDAE( \"" << fileName << "\" )" << std::endl;
|
||||
|
||||
osgdae::daeReader daeReader;
|
||||
std::string fileURI( osgDB::convertFileNameToUnixStyle(fileName) );
|
||||
if ( ! daeReader.convert( fileURI ) )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Load failed in COLLADA DOM conversion" << std::endl;
|
||||
return ReadResult::ERROR_IN_READING_FILE;
|
||||
}
|
||||
|
||||
osg::Node* rootNode( daeReader.getRootNode() );
|
||||
return rootNode;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
osgDB::ReaderWriter::WriteResult
|
||||
ReaderWriterDAE::writeNode( const osg::Node& node,
|
||||
const std::string& fname, const osgDB::ReaderWriter::Options* options ) const
|
||||
{
|
||||
std::string ext( osgDB::getLowerCaseFileExtension(fname) );
|
||||
if( ! acceptsExtension(ext) ) return WriteResult::FILE_NOT_HANDLED;
|
||||
|
||||
// Process options
|
||||
bool usePolygon(false);
|
||||
if( options )
|
||||
{
|
||||
std::istringstream iss( options->getOptionString() );
|
||||
std::string opt;
|
||||
|
||||
while( std::getline( iss, opt, ',' ) )
|
||||
{
|
||||
if( opt == "polygon") usePolygon = true;
|
||||
else
|
||||
{
|
||||
osg::notify(osg::WARN)
|
||||
<< "\n" "COLLADA dae plugin: unrecognized option \"" << opt << "\"\n"
|
||||
<< "comma-delimited options:\n"
|
||||
<< "\tpolygon = use polygons instead of polylists for element\n"
|
||||
<< "example: osgviewer -O polygon bar.dae" "\n"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
osgdae::daeWriter daeWriter( fname, usePolygon );
|
||||
daeWriter.setRootNode( node );
|
||||
const_cast<osg::Node*>(&node)->accept( daeWriter );
|
||||
|
||||
osgDB::ReaderWriter::WriteResult retVal( WriteResult::ERROR_IN_WRITING_FILE );
|
||||
if ( daeWriter.isSuccess() )
|
||||
{
|
||||
if ( daeWriter.writeFile() )
|
||||
{
|
||||
retVal = WriteResult::FILE_SAVED;
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Add ourself to the Registry to instantiate the reader/writer.
|
||||
|
||||
osgDB::RegisterReaderWriterProxy<ReaderWriterDAE> g_readerWriter_DAE_Proxy;
|
||||
|
||||
// vim: set sw=4 ts=8 et ic ai:
|
||||
497
src/osgPlugins/dae/daeRGeometry.cpp
Normal file
497
src/osgPlugins/dae/daeRGeometry.cpp
Normal file
@@ -0,0 +1,497 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include "daeReader.h"
|
||||
#include "domSourceReader.h"
|
||||
#include <dae.h>
|
||||
#include <dom/domCOLLADA.h>
|
||||
#include <dom/domInstance_geometry.h>
|
||||
#include <dom/domInstance_controller.h>
|
||||
#include <dom/domController.h>
|
||||
|
||||
#include <osg/Geometry>
|
||||
|
||||
using namespace osgdae;
|
||||
|
||||
osg::Node* daeReader::processInstance_geometry( domInstance_geometry *ig )
|
||||
{
|
||||
//TODO: cache geometries so they don't get processed mulitple times.
|
||||
//TODO: after cached need to check geometries and materials. both have to be the same for it
|
||||
// to be the same instance.
|
||||
|
||||
daeElement *el = getElementFromURI( ig->getUrl() );
|
||||
domGeometry *geom = daeSafeCast< domGeometry >( el );
|
||||
if ( geom == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Failed to locate geometry " << ig->getUrl().getURI() << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
//check cache if geometry already exists
|
||||
osg::Node *geo;
|
||||
|
||||
std::map< domGeometry*, osg::Node* >::iterator iter = geometryMap.find( geom );
|
||||
if ( iter != geometryMap.end() )
|
||||
{
|
||||
geo = iter->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
geo = processGeometry( geom );
|
||||
geometryMap.insert( std::make_pair( geom, geo ) );
|
||||
}
|
||||
if ( geo == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Failed to load geometry " << ig->getUrl().getURI() << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
//process material bindings
|
||||
if ( ig->getBind_material() != NULL )
|
||||
{
|
||||
processBindMaterial( ig->getBind_material(), geo );
|
||||
}
|
||||
|
||||
return geo;
|
||||
}
|
||||
|
||||
osg::Node* daeReader::processInstance_controller( domInstance_controller *ictrl )
|
||||
{
|
||||
//TODO: cache geometries so they don't get processed mulitple times.
|
||||
//TODO: after cached need to check geometries and materials. both have to be the same for it
|
||||
// to be the same instance.
|
||||
//TODO: support skinning
|
||||
|
||||
osg::notify( osg::WARN ) << "Processing <instance_controller>. There is not skinning support but will display the base mesh." << std::endl;
|
||||
daeElement *el = getElementFromURI( ictrl->getUrl() );
|
||||
domController *ctrl = daeSafeCast< domController >( el );
|
||||
if ( ctrl == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Failed to locate controller " << ictrl->getUrl().getURI() << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
el = NULL;
|
||||
//## non init
|
||||
daeURI *src=NULL;
|
||||
if ( ctrl->getSkin() != NULL )
|
||||
{
|
||||
src = &ctrl->getSkin()->getSource();
|
||||
el = getElementFromURI( ctrl->getSkin()->getSource() );
|
||||
}
|
||||
else if ( ctrl->getMorph() != NULL )
|
||||
{
|
||||
src = &ctrl->getSkin()->getSource();
|
||||
el = getElementFromURI( ctrl->getMorph()->getSource() );
|
||||
}
|
||||
//non init case
|
||||
if ( !src )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Failed to locate geometry : URI is NULL" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
domGeometry *geom = daeSafeCast< domGeometry >( el );
|
||||
if ( geom == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Failed to locate geometry " << src->getURI() << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
osg::Node *geo;
|
||||
|
||||
std::map< domGeometry*, osg::Node* >::iterator iter = geometryMap.find( geom );
|
||||
if ( iter != geometryMap.end() )
|
||||
{
|
||||
geo = iter->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
geo = processGeometry( geom );
|
||||
geometryMap.insert( std::make_pair( geom, geo ) );
|
||||
}
|
||||
if ( geo == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Failed to load geometry " << src->getURI() << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
//process material bindings
|
||||
if ( ictrl->getBind_material() != NULL )
|
||||
{
|
||||
processBindMaterial( ictrl->getBind_material(), geo );
|
||||
}
|
||||
|
||||
return geo;
|
||||
}
|
||||
|
||||
osg::Node *daeReader::processGeometry( domGeometry *geo )
|
||||
{
|
||||
domMesh *mesh = geo->getMesh();
|
||||
if ( mesh == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Unsupported Geometry type loading " << geo->getId() << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
osg::Node *node = new osg::Group();
|
||||
|
||||
if ( geo->getId() != NULL )
|
||||
{
|
||||
node->setName( geo->getId() );
|
||||
}
|
||||
|
||||
SourceMap sources;
|
||||
|
||||
size_t count = mesh->getContents().getCount();
|
||||
for ( size_t i = 0; i < count; i++ )
|
||||
{
|
||||
if ( daeSafeCast< domVertices >( mesh->getContents()[i] ) != NULL ) continue;
|
||||
|
||||
domSource *s = daeSafeCast< domSource >( mesh->getContents()[i] );
|
||||
if ( s != NULL )
|
||||
{
|
||||
sources.insert( std::make_pair( (daeElement*)mesh->getContents()[i],
|
||||
domSourceReader( s ) ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
osg::Node *n = NULL;
|
||||
|
||||
domTriangles *t = daeSafeCast< domTriangles >( mesh->getContents()[i] );
|
||||
if ( t != NULL )
|
||||
{
|
||||
n = processSinglePPrimitive( t, sources, GL_TRIANGLES );
|
||||
if ( n != NULL )
|
||||
{
|
||||
node->asGroup()->addChild( n );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domTristrips *ts = daeSafeCast< domTristrips >( mesh->getContents()[i] );
|
||||
if ( ts != NULL )
|
||||
{
|
||||
n = processMultiPPrimitive( ts, sources, GL_TRIANGLE_STRIP );
|
||||
if ( n != NULL )
|
||||
{
|
||||
node->asGroup()->addChild( n );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domTrifans *tf = daeSafeCast< domTrifans >( mesh->getContents()[i] );
|
||||
if ( tf != NULL )
|
||||
{
|
||||
n = processMultiPPrimitive( tf, sources, GL_TRIANGLE_FAN );
|
||||
if ( n != NULL )
|
||||
{
|
||||
node->asGroup()->addChild( n );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domLines *l = daeSafeCast< domLines >( mesh->getContents()[i] );
|
||||
if ( l != NULL )
|
||||
{
|
||||
n = processSinglePPrimitive( l, sources, GL_LINES );
|
||||
if ( n != NULL )
|
||||
{
|
||||
node->asGroup()->addChild( n );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domLinestrips *ls = daeSafeCast< domLinestrips >( mesh->getContents()[i] );
|
||||
if ( ls != NULL )
|
||||
{
|
||||
n = processMultiPPrimitive( ls, sources, GL_LINE_STRIP );
|
||||
if ( n != NULL )
|
||||
{
|
||||
node->asGroup()->addChild( n );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domPolygons *p = daeSafeCast< domPolygons >( mesh->getContents()[i] );
|
||||
if ( p != NULL )
|
||||
{
|
||||
n = processMultiPPrimitive( p, sources, GL_POLYGON );
|
||||
if ( n != NULL )
|
||||
{
|
||||
node->asGroup()->addChild( n );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domPolylist *pl = daeSafeCast< domPolylist >( mesh->getContents()[i] );
|
||||
if ( pl != NULL )
|
||||
{
|
||||
n = processPolylist( pl, sources );
|
||||
if ( n != NULL )
|
||||
{
|
||||
node->asGroup()->addChild( n );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
osg::notify( osg::WARN ) << "Unsupported primitive type " << mesh->getContents()[i]->getTypeName() << " in geometry " << geo->getId() << std::endl;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
osg::Node* daeReader::processSinglePPrimitive( T *group, SourceMap &sources, GLenum mode )
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
osg::Geometry *geometry = new osg::Geometry();
|
||||
|
||||
//Setting the name of the geode to the material symbol for easy binding later
|
||||
if ( group->getMaterial() != NULL )
|
||||
{
|
||||
geode->setName( group->getMaterial() );
|
||||
}
|
||||
|
||||
IndexMap index_map;
|
||||
resolveArrays( group->getInput_array(), geometry, sources, index_map );
|
||||
|
||||
osg::DrawArrayLengths* dal = new osg::DrawArrayLengths( mode );
|
||||
processP( group->getP(), geometry, index_map, dal/*mode*/ );
|
||||
geometry->addPrimitiveSet( dal );
|
||||
|
||||
geode->addDrawable( geometry );
|
||||
return geode;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
osg::Node* daeReader::processMultiPPrimitive( T *group, SourceMap &sources, GLenum mode )
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
osg::Geometry *geometry = new osg::Geometry();
|
||||
|
||||
//Setting the name of the geode to the material symbol for easy binding later
|
||||
if ( group->getMaterial() != NULL )
|
||||
{
|
||||
geode->setName( group->getMaterial() );
|
||||
}
|
||||
|
||||
IndexMap index_map;
|
||||
resolveArrays( group->getInput_array(), geometry, sources, index_map );
|
||||
|
||||
osg::DrawArrayLengths* dal = new osg::DrawArrayLengths( mode );
|
||||
|
||||
for ( size_t i = 0; i < group->getP_array().getCount(); i++ )
|
||||
{
|
||||
processP( group->getP_array()[i], geometry, index_map, dal/*mode*/ );
|
||||
}
|
||||
geometry->addPrimitiveSet( dal );
|
||||
|
||||
geode->addDrawable( geometry );
|
||||
return geode;
|
||||
}
|
||||
|
||||
osg::Node* daeReader::processPolylist( domPolylist *group, SourceMap &sources )
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
osg::Geometry *geometry = new osg::Geometry();
|
||||
|
||||
//Setting the name of the geode to the material symbol for easy binding later
|
||||
if ( group->getMaterial() != NULL )
|
||||
{
|
||||
geode->setName( group->getMaterial() );
|
||||
}
|
||||
|
||||
IndexMap index_map;
|
||||
resolveArrays( group->getInput_array(), geometry, sources, index_map );
|
||||
|
||||
osg::DrawArrayLengths* dal = new osg::DrawArrayLengths( GL_POLYGON );
|
||||
|
||||
domPRef p = (domP*)(daeElement*)domP::_Meta->create(); //I don't condone creating elements like this but I don't care
|
||||
//if it created properly because I never want it as part of the document. Its just a temporary
|
||||
//element to trick the importer into loading polylists easier.
|
||||
unsigned int maxOffset = 0;
|
||||
for ( unsigned int i = 0; i < group->getInput_array().getCount(); i++ )
|
||||
{
|
||||
if ( group->getInput_array()[i]->getOffset() > maxOffset )
|
||||
{
|
||||
maxOffset = group->getInput_array()[i]->getOffset();
|
||||
}
|
||||
}
|
||||
maxOffset++;
|
||||
unsigned int pOffset = 0;
|
||||
for ( unsigned int i = 0; i < group->getCount(); i++ )
|
||||
{
|
||||
p->getValue().clear();
|
||||
for ( unsigned int x = 0; x < group->getVcount()->getValue()[i]; x++ )
|
||||
{
|
||||
for ( unsigned int y = 0; y < maxOffset; y++ )
|
||||
{
|
||||
p->getValue().append( group->getP()->getValue()[ pOffset + x*maxOffset + y ] );
|
||||
}
|
||||
}
|
||||
pOffset += group->getVcount()->getValue()[i] * maxOffset;
|
||||
processP( p, geometry, index_map, dal/*mode*/ );
|
||||
}
|
||||
|
||||
geometry->addPrimitiveSet( dal );
|
||||
|
||||
geode->addDrawable( geometry );
|
||||
return geode;
|
||||
}
|
||||
|
||||
void daeReader::processP( domP *p, osg::Geometry *&/*geom*/, IndexMap &index_map, osg::DrawArrayLengths* dal /*GLenum mode*/ )
|
||||
{
|
||||
//osg::DrawArrayLengths* dal = new osg::DrawArrayLengths( mode );
|
||||
int idxcount = index_map.size();
|
||||
int count = p->getValue().getCount();
|
||||
count = (count/idxcount)*idxcount;
|
||||
dal->push_back(count/idxcount);
|
||||
|
||||
int j = 0;
|
||||
while ( j < count ) {
|
||||
for ( IndexMap::iterator k = index_map.begin(); k != index_map.end(); k++,j++ ) {
|
||||
int tmp = p->getValue()[j];
|
||||
k->second->push_back(tmp);
|
||||
}
|
||||
}
|
||||
//geom->addPrimitiveSet( dal );
|
||||
}
|
||||
|
||||
void daeReader::resolveArrays( domInputLocalOffset_Array &inputs, osg::Geometry *&geom,
|
||||
SourceMap &sources, IndexMap &index_map )
|
||||
{
|
||||
domVertices* vertices = NULL;
|
||||
daeElement* position_source = NULL;
|
||||
daeElement* color_source = NULL;
|
||||
daeElement* normal_source = NULL;
|
||||
daeElement* texcoord_source = NULL;
|
||||
|
||||
int offset;
|
||||
int set;
|
||||
daeElement *tmp_el;
|
||||
domInputLocalOffset *tmp_input;
|
||||
|
||||
if ( findInputSourceBySemantic( inputs, "VERTEX", tmp_el, &tmp_input ) ) {
|
||||
vertices = daeSafeCast< domVertices >( tmp_el );
|
||||
if ( vertices == NULL ) {
|
||||
osg::notify( osg::WARN )<<"Could not get vertices"<<std::endl;
|
||||
return;
|
||||
}
|
||||
offset = tmp_input->getOffset();
|
||||
set = tmp_input->getSet(); //if it wasn't actually set it will initialize to 0 which is
|
||||
//the value we would want anyways.
|
||||
|
||||
domInputLocal *tmp;
|
||||
findInputSourceBySemantic( vertices->getInput_array(), "POSITION", position_source, &tmp );
|
||||
findInputSourceBySemantic( vertices->getInput_array(), "COLOR", color_source, &tmp );
|
||||
findInputSourceBySemantic( vertices->getInput_array(), "NORMAL", normal_source, &tmp );
|
||||
findInputSourceBySemantic( vertices->getInput_array(), "TEXCOORD", texcoord_source, &tmp );
|
||||
|
||||
if ( index_map[offset] == NULL ) {
|
||||
index_map[offset] = new osg::IntArray();
|
||||
}
|
||||
geom->setVertexIndices( index_map[offset] );
|
||||
if ( position_source != NULL )
|
||||
{
|
||||
geom->setVertexArray( sources[position_source].getVec3Array() );
|
||||
}
|
||||
if ( color_source != NULL )
|
||||
{
|
||||
geom->setColorArray( sources[color_source].getVec4Array() );
|
||||
geom->setColorIndices( index_map[offset] );
|
||||
geom->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
|
||||
}
|
||||
if ( normal_source != NULL )
|
||||
{
|
||||
geom->setNormalArray( sources[normal_source].getVec3Array() );
|
||||
geom->setNormalIndices( index_map[offset] );
|
||||
geom->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
|
||||
}
|
||||
if ( texcoord_source != NULL )
|
||||
{
|
||||
domSourceReader *sc = &sources[texcoord_source];
|
||||
switch( sc->getArrayType() ) {
|
||||
case domSourceReader::Vec2:
|
||||
geom->setTexCoordArray( set, sc->getVec2Array() );
|
||||
break;
|
||||
case domSourceReader::Vec3:
|
||||
geom->setTexCoordArray( set, sc->getVec3Array() );
|
||||
break;
|
||||
default:
|
||||
osg::notify( osg::WARN )<<"Unsupported array type: "<< sc->getArrayType() <<std::endl;
|
||||
break;
|
||||
}
|
||||
geom->setTexCoordIndices( set, index_map[offset] );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify( osg::WARN )<<"Vertex data not found"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( findInputSourceBySemantic( inputs, "COLOR", color_source, &tmp_input ) ) {
|
||||
|
||||
offset = tmp_input->getOffset();
|
||||
if ( index_map[offset] == NULL ) {
|
||||
index_map[offset] = new osg::IntArray();
|
||||
}
|
||||
geom->setColorIndices( index_map[offset] );
|
||||
}
|
||||
|
||||
if ( color_source != NULL ) {
|
||||
geom->setColorArray( sources[color_source].getVec4Array() );
|
||||
geom->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
|
||||
}
|
||||
|
||||
if ( findInputSourceBySemantic( inputs, "NORMAL", normal_source, &tmp_input ) ) {
|
||||
|
||||
offset = tmp_input->getOffset();
|
||||
if ( index_map[offset] == NULL ) {
|
||||
index_map[offset] = new osg::IntArray();
|
||||
}
|
||||
geom->setNormalIndices( index_map[offset] );
|
||||
}
|
||||
|
||||
if ( normal_source ) {
|
||||
geom->setNormalArray( sources[normal_source].getVec3Array() );
|
||||
geom->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
|
||||
}
|
||||
|
||||
int unit = 0;
|
||||
while ( findInputSourceBySemantic( inputs, "TEXCOORD", texcoord_source, &tmp_input, unit ) ) {
|
||||
|
||||
offset = tmp_input->getOffset();
|
||||
set = tmp_input->getSet();
|
||||
|
||||
if ( index_map[offset] == NULL ) {
|
||||
index_map[offset] = new osg::IntArray();
|
||||
}
|
||||
//this should really be set. Then when you bind_vertex_input you can adjust accordingly for the
|
||||
//effect which currently only puts textures in texunit 0
|
||||
geom->setTexCoordIndices( unit/*set*/, index_map[offset] );
|
||||
|
||||
if ( texcoord_source != NULL )
|
||||
{
|
||||
domSourceReader &sc = sources[texcoord_source];
|
||||
switch( sc.getArrayType() ) {
|
||||
case domSourceReader::Vec2:
|
||||
geom->setTexCoordArray( unit/*set*/, sc.getVec2Array() );
|
||||
break;
|
||||
case domSourceReader::Vec3:
|
||||
geom->setTexCoordArray( unit/*set*/, sc.getVec3Array() );
|
||||
break;
|
||||
default:
|
||||
osg::notify( osg::WARN )<<"Unsupported array type: "<< sc.getArrayType() <<std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
unit++;
|
||||
}
|
||||
}
|
||||
645
src/osgPlugins/dae/daeRMaterials.cpp
Normal file
645
src/osgPlugins/dae/daeRMaterials.cpp
Normal file
@@ -0,0 +1,645 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include "daeReader.h"
|
||||
|
||||
#include <dae.h>
|
||||
#include <dae/daeSIDResolver.h>
|
||||
#include <dae/domAny.h>
|
||||
#include <dom/domCOLLADA.h>
|
||||
#include <dom/domProfile_COMMON.h>
|
||||
|
||||
#include <osg/BlendColor>
|
||||
#include <osg/BlendFunc>
|
||||
#include <osg/Texture2D>
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
using namespace osgdae;
|
||||
|
||||
void daeReader::processBindMaterial( domBind_material *bm, osg::Node *geo )
|
||||
{
|
||||
if ( bm->getTechnique_common() == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "No COMMON technique for bind_material" << std::endl;
|
||||
return;
|
||||
}
|
||||
osg::Group *group = geo->asGroup();
|
||||
if ( group == NULL )
|
||||
{
|
||||
//this shouldn't happen unless something is terribly wrong
|
||||
return;
|
||||
}
|
||||
domInstance_material_Array &ima = bm->getTechnique_common()->getInstance_material_array();
|
||||
size_t count = ima.getCount();
|
||||
for ( size_t i = 0; i < count; i++ )
|
||||
{
|
||||
std::string symbol = ima[i]->getSymbol();
|
||||
domMaterial *mat = daeSafeCast< domMaterial >( getElementFromURI( ima[i]->getTarget() ) );
|
||||
if ( mat == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Failed to locate material " << ima[i]->getTarget().getURI() << std::endl;
|
||||
continue;
|
||||
}
|
||||
osg::StateSet *ss;
|
||||
//check material cache if this material already exists
|
||||
std::map< domMaterial*, osg::StateSet*>::iterator iter = materialMap.find( mat );
|
||||
if ( iter != materialMap.end() )
|
||||
{
|
||||
ss = iter->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
ss = processMaterial( mat );
|
||||
materialMap.insert( std::make_pair( mat, ss ) );
|
||||
}
|
||||
if ( ss == NULL )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//TODO: process all of the <bind>s and <bind_vertex_input>s that are here in the instance_material.
|
||||
|
||||
for ( unsigned int x = 0; x < group->getNumChildren(); x++ )
|
||||
{
|
||||
//I named the geode with the material symbol so I can do this check for binding
|
||||
if ( group->getChild( x )->getName() == symbol )
|
||||
{
|
||||
/*if ( group->getChild( x )->getStateSet() != NULL )
|
||||
{
|
||||
//already have a stateSet this means I am an instance so clone me.
|
||||
group->replaceChild( group->getChild( x ), (osg::Node*)group->getChild( x )->cloneType() );
|
||||
}*/
|
||||
group->getChild( x )->setStateSet( ss );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
osg::StateSet *daeReader::processMaterial( domMaterial *mat )
|
||||
{
|
||||
domEffect *effect = daeSafeCast< domEffect >( getElementFromURI( mat->getInstance_effect()->getUrl() ) );
|
||||
if ( effect == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Failed to locate effect " << mat->getInstance_effect()->getUrl().getURI() << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
osg::StateSet *ss = processEffect( effect );
|
||||
|
||||
//TODO: process all of the setParams that could happen here in the material. ESP. the textures
|
||||
|
||||
return ss;
|
||||
}
|
||||
|
||||
osg::StateSet *daeReader::processEffect( domEffect *effect )
|
||||
{
|
||||
bool hasCOMMON = false;
|
||||
osg::StateSet *ss = NULL;
|
||||
|
||||
for ( size_t i = 0; i < effect->getFx_profile_abstract_array().getCount(); i++ )
|
||||
{
|
||||
domProfile_COMMON *pc = daeSafeCast< domProfile_COMMON >( effect->getFx_profile_abstract_array()[i] );
|
||||
if ( pc != NULL )
|
||||
{
|
||||
if ( hasCOMMON )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Effect already has a profile_COMMON. Skipping this one" << std::endl;
|
||||
continue;
|
||||
}
|
||||
currentEffect = effect;
|
||||
ss = processProfileCOMMON( pc );
|
||||
hasCOMMON = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
osg::notify( osg::WARN ) << "unsupported effect profile " << effect->getFx_profile_abstract_array()[i]->getTypeName() << std::endl;
|
||||
}
|
||||
|
||||
return ss;
|
||||
}
|
||||
|
||||
osg::StateSet *daeReader::processProfileCOMMON( domProfile_COMMON *pc )
|
||||
{
|
||||
osg::StateSet *ss = new osg::StateSet();
|
||||
|
||||
domProfile_COMMON::domTechnique *teq = pc->getTechnique();
|
||||
|
||||
domProfile_COMMON::domTechnique::domConstant *c = teq->getConstant();
|
||||
domProfile_COMMON::domTechnique::domLambert *l = teq->getLambert();
|
||||
domProfile_COMMON::domTechnique::domPhong *p = teq->getPhong();
|
||||
domProfile_COMMON::domTechnique::domBlinn *b = teq->getBlinn();
|
||||
|
||||
ss->setMode( GL_CULL_FACE, GL_TRUE );
|
||||
//ss->setMode( GL_LIGHTING, GL_FALSE );
|
||||
|
||||
osg::ref_ptr< osg::Material > mat = new osg::Material();
|
||||
bool insertMat = false;
|
||||
if ( b != NULL )
|
||||
{
|
||||
bool tmp;
|
||||
tmp = processColorOrTextureType( b->getEmission(), osg::Material::EMISSION, mat.get() );
|
||||
insertMat = insertMat || tmp;
|
||||
|
||||
tmp = processColorOrTextureType( b->getAmbient(), osg::Material::AMBIENT, mat.get() );
|
||||
insertMat = insertMat || tmp;
|
||||
|
||||
osg::StateAttribute *sa = NULL;
|
||||
tmp = processColorOrTextureType( b->getDiffuse(), osg::Material::DIFFUSE, mat.get(), NULL, &sa );
|
||||
insertMat = insertMat || tmp;
|
||||
if ( sa != NULL )
|
||||
{
|
||||
ss->setTextureMode( 0, GL_TEXTURE_2D, GL_TRUE );
|
||||
ss->setTextureAttribute( 0, sa );
|
||||
}
|
||||
|
||||
tmp = processColorOrTextureType( b->getSpecular(), osg::Material::SPECULAR, mat.get(), b->getShininess() );
|
||||
insertMat = insertMat || tmp;
|
||||
|
||||
osg::StateAttribute *sa2 = NULL;
|
||||
sa2 = processTransparentType( b->getTransparent(), ss );
|
||||
if ( sa2 != NULL )
|
||||
{
|
||||
if ( sa == NULL )
|
||||
{
|
||||
ss->setTextureMode( 0, GL_TEXTURE_2D, GL_TRUE );
|
||||
ss->setTextureAttribute( 0, sa2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Already have a texture in the diffuse channel" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if ( p != NULL )
|
||||
{
|
||||
bool tmp;
|
||||
tmp = processColorOrTextureType( p->getEmission(), osg::Material::EMISSION, mat.get() );
|
||||
insertMat = insertMat || tmp;
|
||||
|
||||
tmp = processColorOrTextureType( p->getAmbient(), osg::Material::AMBIENT, mat.get() );
|
||||
insertMat = insertMat || tmp;
|
||||
|
||||
osg::StateAttribute *sa = NULL;
|
||||
tmp = processColorOrTextureType( p->getDiffuse(), osg::Material::DIFFUSE, mat.get(), NULL, &sa );
|
||||
insertMat = insertMat || tmp;
|
||||
if ( sa != NULL )
|
||||
{
|
||||
ss->setTextureMode( 0, GL_TEXTURE_2D, GL_TRUE );
|
||||
ss->setTextureAttribute( 0, sa );
|
||||
}
|
||||
|
||||
tmp = processColorOrTextureType( p->getSpecular(), osg::Material::SPECULAR, mat.get(), p->getShininess() );
|
||||
insertMat = insertMat || tmp;
|
||||
|
||||
osg::StateAttribute *sa2 = NULL;
|
||||
sa2 = processTransparentType( p->getTransparent(), ss );
|
||||
if ( sa2 != NULL )
|
||||
{
|
||||
if ( sa == NULL )
|
||||
{
|
||||
ss->setTextureMode( 0, GL_TEXTURE_2D, GL_TRUE );
|
||||
ss->setTextureAttribute( 0, sa2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Already have a texture in the diffuse channel" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if ( l != NULL )
|
||||
{
|
||||
bool tmp;
|
||||
tmp = processColorOrTextureType( l->getEmission(), osg::Material::EMISSION, mat.get() );
|
||||
insertMat = insertMat || tmp;
|
||||
|
||||
tmp = processColorOrTextureType( l->getAmbient(), osg::Material::AMBIENT, mat.get() );
|
||||
insertMat = insertMat || tmp;
|
||||
|
||||
osg::StateAttribute *sa = NULL;
|
||||
tmp = processColorOrTextureType( l->getDiffuse(), osg::Material::DIFFUSE, mat.get(), NULL, &sa );
|
||||
insertMat = insertMat || tmp;
|
||||
if ( sa != NULL )
|
||||
{
|
||||
ss->setTextureMode( 0, GL_TEXTURE_2D, GL_TRUE );
|
||||
ss->setTextureAttribute( 0, sa );
|
||||
}
|
||||
|
||||
osg::StateAttribute *sa2 = NULL;
|
||||
sa2 = processTransparentType( l->getTransparent(), ss );
|
||||
if ( sa2 != NULL )
|
||||
{
|
||||
if ( sa == NULL )
|
||||
{
|
||||
ss->setTextureMode( 0, GL_TEXTURE_2D, GL_TRUE );
|
||||
ss->setTextureAttribute( 0, sa2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Already have a texture in the diffuse channel" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if ( c != NULL )
|
||||
{
|
||||
insertMat = processColorOrTextureType( c->getEmission(), osg::Material::EMISSION, mat.get() );
|
||||
|
||||
osg::StateAttribute *sa2 = NULL;
|
||||
sa2 = processTransparentType( c->getTransparent(), ss );
|
||||
if ( sa2 != NULL )
|
||||
{
|
||||
ss->setTextureMode( 0, GL_TEXTURE_2D, GL_TRUE );
|
||||
ss->setTextureAttribute( 0, sa2 );
|
||||
}
|
||||
}
|
||||
if ( insertMat )
|
||||
{
|
||||
ss->setAttribute( mat.get() );
|
||||
}
|
||||
|
||||
return ss;
|
||||
}
|
||||
|
||||
bool daeReader::processColorOrTextureType( domCommon_color_or_texture_type *cot,
|
||||
osg::Material::ColorMode channel,
|
||||
osg::Material *mat,
|
||||
domCommon_float_or_param_type *fop,
|
||||
osg::StateAttribute **sa )
|
||||
{
|
||||
if ( cot == NULL )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool retVal = false;
|
||||
//osg::StateAttribute *sa = NULL;
|
||||
//TODO: Make all channels process <param ref=""> type of value
|
||||
if ( channel == osg::Material::EMISSION )
|
||||
{
|
||||
if ( cot->getColor() != NULL )
|
||||
{
|
||||
domFloat4 &f4 = cot->getColor()->getValue();
|
||||
mat->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) );
|
||||
retVal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Currently no support for <param> or <texture> in Emission channel " << std::endl;
|
||||
}
|
||||
}
|
||||
else if ( channel == osg::Material::AMBIENT )
|
||||
{
|
||||
if ( cot->getColor() != NULL )
|
||||
{
|
||||
domFloat4 &f4 = cot->getColor()->getValue();
|
||||
mat->setAmbient( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) );
|
||||
retVal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Currently no support for <param> or <texture> in Ambient channel " << std::endl;
|
||||
}
|
||||
}
|
||||
else if ( channel == osg::Material::DIFFUSE )
|
||||
{
|
||||
if ( cot->getColor() != NULL )
|
||||
{
|
||||
domFloat4 &f4 = cot->getColor()->getValue();
|
||||
mat->setDiffuse( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) );
|
||||
retVal = true;
|
||||
}
|
||||
else if ( cot->getTexture() != NULL && sa != NULL )
|
||||
{
|
||||
*sa = processTexture( cot->getTexture() );
|
||||
domExtra *extra = cot->getTexture()->getExtra();
|
||||
if ( extra != NULL && extra->getType() != NULL &&
|
||||
strcmp( extra->getType(), "color" ) == 0 )
|
||||
{
|
||||
//the extra data for osg. Diffuse color can happen with a texture.
|
||||
for ( unsigned int i = 0; i < extra->getTechnique_array().getCount(); i++ )
|
||||
{
|
||||
domTechnique *teq = extra->getTechnique_array()[i];
|
||||
if ( strcmp( teq->getProfile(), "SCEI" ) == 0 )
|
||||
{
|
||||
osg::Vec4 col;
|
||||
domAny *dcol = (domAny*)(daeElement*)teq->getContents()[0];
|
||||
char *val = (char *)dcol->getValue();
|
||||
int cnt = 0;
|
||||
while ( cnt < 4 && strlen( val ) != 0 )
|
||||
{
|
||||
char *space = strchr( val, ' ' );
|
||||
if ( space != NULL )
|
||||
{
|
||||
*space = 0;
|
||||
}
|
||||
int tmp = atoi( val );
|
||||
col[cnt] = tmp;
|
||||
cnt++;
|
||||
val = space + 1;
|
||||
}
|
||||
mat->setDiffuse( osg::Material::FRONT_AND_BACK, col );
|
||||
retVal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Currently no support for <param> in Diffuse channel " << std::endl;
|
||||
}
|
||||
}
|
||||
else if ( channel == osg::Material::SPECULAR )
|
||||
{
|
||||
if ( cot->getColor() != NULL )
|
||||
{
|
||||
domFloat4 &f4 = cot->getColor()->getValue();
|
||||
mat->setSpecular( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) );
|
||||
retVal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Currently no support for <param> or <texture> in Specular channel " << std::endl;
|
||||
}
|
||||
if ( fop != NULL && fop->getFloat() != NULL )
|
||||
{
|
||||
mat->setShininess( osg::Material::FRONT_AND_BACK, fop->getFloat()->getValue() );
|
||||
retVal = true;
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
osg::StateAttribute *daeReader::processTexture( domCommon_color_or_texture_type_complexType::domTexture *tex )
|
||||
{
|
||||
//find the newparam for the sampler based on the texture attribute
|
||||
domFx_sampler2D_common *sampler = NULL;
|
||||
domFx_surface_common *surface = NULL;
|
||||
domImage *dImg = NULL;
|
||||
|
||||
std::string target = std::string("./") + std::string(tex->getTexture());
|
||||
osg::notify(osg::NOTICE)<<"processTexture("<<target<<")"<<std::endl;
|
||||
|
||||
daeSIDResolver res1( currentEffect, target.c_str() );
|
||||
daeElement *el = res1.getElement();
|
||||
|
||||
if ( el == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Could not locate newparam for texture sampler2D" << tex->getTexture() << std::endl;
|
||||
osg::notify( osg::WARN ) << "Checking if data does incorrect linking straight to the image" << std::endl;
|
||||
dae->getDatabase()->getElement( (daeElement**)&dImg, 0, tex->getTexture(), "image" );
|
||||
if ( dImg != NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Direct image link found. Data is incorrect but will continue to load texture" << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
domCommon_newparam_type *cnp = daeSafeCast< domCommon_newparam_type >( el );
|
||||
domFx_newparam_common *npc = daeSafeCast< domFx_newparam_common >( el );
|
||||
|
||||
if ( cnp != NULL )
|
||||
{
|
||||
sampler = cnp->getSampler2D();
|
||||
}
|
||||
else if ( npc != NULL )
|
||||
{
|
||||
sampler = npc->getFx_basic_type_common()->getSampler2D();
|
||||
}
|
||||
|
||||
if ( sampler == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Wrong newparam type. Expected sampler2D" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//find the newparam for the surface based on the sampler2D->source value
|
||||
target = std::string("./") + std::string( sampler->getSource()->getValue() );
|
||||
daeSIDResolver res2( currentEffect, target.c_str() );
|
||||
el = res2.getElement();
|
||||
if ( el == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Could not locate newparam for source " << sampler->getSource()->getValue() << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
cnp = daeSafeCast< domCommon_newparam_type >( el );
|
||||
npc = daeSafeCast< domFx_newparam_common >( el );
|
||||
|
||||
if ( cnp != NULL )
|
||||
{
|
||||
surface = cnp->getSurface();
|
||||
}
|
||||
else if ( npc != NULL )
|
||||
{
|
||||
surface = npc->getFx_basic_type_common()->getSurface();
|
||||
}
|
||||
|
||||
if ( surface == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Wrong newparam type. Expected surface" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//look for the domImage based on the surface initialization stuff
|
||||
daeIDRef &ref = surface->getFx_surface_init_common()->getInit_from_array()[0]->getValue();
|
||||
dImg = daeSafeCast< domImage >( getElementFromIDRef( ref ) );
|
||||
}
|
||||
if ( dImg == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Could not locate image for texture" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
//Got a sampler and a surface and an imaged. Time to create the texture stuff for osg
|
||||
dImg->getInit_from()->getValue().validate();
|
||||
|
||||
std::string filename = (dImg->getInit_from()->getValue().getURI()+7);
|
||||
osg::Image *img = osgDB::readImageFile( filename.c_str() );
|
||||
|
||||
osg::notify(osg::INFO)<<" processTexture(..) - readImage("<<filename<<")"<<std::endl;
|
||||
|
||||
osg::Texture2D *t2D = new osg::Texture2D( img );
|
||||
//set texture parameters
|
||||
if ( sampler != NULL )
|
||||
{
|
||||
if ( sampler->getWrap_s() != NULL )
|
||||
{
|
||||
osg::Texture::WrapMode wrap;
|
||||
switch( sampler->getWrap_s()->getValue() )
|
||||
{
|
||||
case FX_SAMPLER_WRAP_COMMON_NONE:
|
||||
case FX_SAMPLER_WRAP_COMMON_WRAP:
|
||||
wrap = osg::Texture::REPEAT;
|
||||
break;
|
||||
case FX_SAMPLER_WRAP_COMMON_MIRROR:
|
||||
wrap = osg::Texture::MIRROR;
|
||||
break;
|
||||
case FX_SAMPLER_WRAP_COMMON_CLAMP:
|
||||
wrap = osg::Texture::CLAMP;
|
||||
break;
|
||||
case FX_SAMPLER_WRAP_COMMON_BORDER:
|
||||
wrap = osg::Texture::CLAMP_TO_BORDER;
|
||||
break;
|
||||
default:
|
||||
wrap = osg::Texture::CLAMP;
|
||||
break;
|
||||
}
|
||||
t2D->setWrap( osg::Texture::WRAP_S, wrap );
|
||||
}
|
||||
else
|
||||
{
|
||||
t2D->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
|
||||
}
|
||||
if ( sampler->getWrap_t() != NULL )
|
||||
{
|
||||
osg::Texture::WrapMode wrap;
|
||||
switch( sampler->getWrap_t()->getValue() )
|
||||
{
|
||||
case FX_SAMPLER_WRAP_COMMON_NONE:
|
||||
case FX_SAMPLER_WRAP_COMMON_WRAP:
|
||||
wrap = osg::Texture::REPEAT;
|
||||
break;
|
||||
case FX_SAMPLER_WRAP_COMMON_MIRROR:
|
||||
wrap = osg::Texture::MIRROR;
|
||||
break;
|
||||
case FX_SAMPLER_WRAP_COMMON_CLAMP:
|
||||
wrap = osg::Texture::CLAMP;
|
||||
break;
|
||||
case FX_SAMPLER_WRAP_COMMON_BORDER:
|
||||
wrap = osg::Texture::CLAMP_TO_BORDER;
|
||||
break;
|
||||
default:
|
||||
wrap = osg::Texture::CLAMP;
|
||||
break;
|
||||
}
|
||||
t2D->setWrap( osg::Texture::WRAP_T, wrap );
|
||||
}
|
||||
else
|
||||
{
|
||||
t2D->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
|
||||
}
|
||||
if ( sampler->getMinfilter() != NULL )
|
||||
{
|
||||
osg::Texture::FilterMode mode;
|
||||
switch( sampler->getMinfilter()->getValue() )
|
||||
{
|
||||
case FX_SAMPLER_FILTER_COMMON_NEAREST:
|
||||
mode = osg::Texture::NEAREST;
|
||||
break;
|
||||
case FX_SAMPLER_FILTER_COMMON_LINEAR:
|
||||
mode = osg::Texture::LINEAR;
|
||||
break;
|
||||
case FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_NEAREST:
|
||||
mode = osg::Texture::NEAREST_MIPMAP_NEAREST;
|
||||
break;
|
||||
case FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_NEAREST:
|
||||
mode = osg::Texture::LINEAR_MIPMAP_NEAREST;
|
||||
break;
|
||||
case FX_SAMPLER_FILTER_COMMON_NONE:
|
||||
case FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_LINEAR:
|
||||
mode = osg::Texture::NEAREST_MIPMAP_LINEAR;
|
||||
break;
|
||||
case FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_LINEAR:
|
||||
mode = osg::Texture::LINEAR_MIPMAP_LINEAR;
|
||||
break;
|
||||
default:
|
||||
mode = osg::Texture::LINEAR;
|
||||
break;
|
||||
}
|
||||
t2D->setFilter( osg::Texture::MIN_FILTER, mode );
|
||||
}
|
||||
else
|
||||
{
|
||||
t2D->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST_MIPMAP_LINEAR );
|
||||
}
|
||||
if ( sampler->getMagfilter() != NULL )
|
||||
{
|
||||
osg::Texture::FilterMode mode;
|
||||
switch( sampler->getMagfilter()->getValue() )
|
||||
{
|
||||
case FX_SAMPLER_FILTER_COMMON_NEAREST:
|
||||
mode = osg::Texture::NEAREST;
|
||||
break;
|
||||
case FX_SAMPLER_FILTER_COMMON_NONE:
|
||||
case FX_SAMPLER_FILTER_COMMON_LINEAR:
|
||||
mode = osg::Texture::LINEAR;
|
||||
break;
|
||||
case FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_NEAREST:
|
||||
mode = osg::Texture::NEAREST_MIPMAP_NEAREST;
|
||||
break;
|
||||
case FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_NEAREST:
|
||||
mode = osg::Texture::LINEAR_MIPMAP_NEAREST;
|
||||
break;
|
||||
case FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_LINEAR:
|
||||
mode = osg::Texture::NEAREST_MIPMAP_LINEAR;
|
||||
break;
|
||||
case FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_LINEAR:
|
||||
mode = osg::Texture::LINEAR_MIPMAP_LINEAR;
|
||||
break;
|
||||
default:
|
||||
mode = osg::Texture::LINEAR;
|
||||
break;
|
||||
}
|
||||
t2D->setFilter( osg::Texture::MAG_FILTER, mode );
|
||||
}
|
||||
else
|
||||
{
|
||||
t2D->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
|
||||
}
|
||||
if ( sampler->getBorder_color() != NULL )
|
||||
{
|
||||
const domFloat4 &col = sampler->getBorder_color()->getValue();
|
||||
t2D->setBorderColor( osg::Vec4( col[0], col[1], col[2], col[3] ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
t2D->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
|
||||
t2D->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
|
||||
t2D->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST_MIPMAP_LINEAR );
|
||||
t2D->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
|
||||
}
|
||||
|
||||
return t2D;
|
||||
}
|
||||
|
||||
osg::StateAttribute *daeReader::processTransparentType( domCommon_transparent_type *ctt, osg::StateSet *ss )
|
||||
{
|
||||
if ( ctt == NULL )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// bool retVal = false;
|
||||
osg::StateAttribute *sa = NULL;
|
||||
if ( ctt->getColor() != NULL )
|
||||
{
|
||||
domFloat4 &f4 = ctt->getColor()->getValue();
|
||||
//##compliant with OSG 1.0 API
|
||||
osg::BlendColor *bc = new osg::BlendColor();
|
||||
bc->setConstantColor(osg::Vec4( f4[0], f4[1], f4[2], f4[3] ));
|
||||
ss->setAttribute( bc );
|
||||
ss->setMode( GL_BLEND, GL_TRUE );
|
||||
ss->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
|
||||
ss->setRenderBinDetails( 10, "DepthSortedBin" );
|
||||
}
|
||||
else if ( ctt->getTexture() != NULL )
|
||||
{
|
||||
sa = processTexture( ctt->getTexture() );
|
||||
osg::BlendFunc *bf = new osg::BlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
ss->setAttribute( bf );
|
||||
ss->setMode( GL_BLEND, GL_TRUE );
|
||||
ss->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
|
||||
ss->setRenderBinDetails( 10, "DepthSortedBin" );
|
||||
}
|
||||
return sa;
|
||||
}
|
||||
208
src/osgPlugins/dae/daeRSceneObjects.cpp
Normal file
208
src/osgPlugins/dae/daeRSceneObjects.cpp
Normal file
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include "daeReader.h"
|
||||
#include <dae.h>
|
||||
#include <dom/domCOLLADA.h>
|
||||
|
||||
#include <osg/Switch>
|
||||
#include <osg/LightSource>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Switch>
|
||||
#include <osg/ShapeDrawable>
|
||||
|
||||
using namespace osgdae;
|
||||
|
||||
osg::Node* daeReader::processLight( domLight *dlight )
|
||||
{
|
||||
//do light processing here.
|
||||
domLight::domTechnique_common::domAmbient *ambient;
|
||||
domLight::domTechnique_common::domDirectional *directional;
|
||||
domLight::domTechnique_common::domPoint *point;
|
||||
domLight::domTechnique_common::domSpot *spot;
|
||||
|
||||
if ( dlight->getTechnique_common() == NULL ||
|
||||
dlight->getTechnique_common()->getContents().getCount() == 0 )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Invalid content for light" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
osg::Node* node = new osg::Switch();
|
||||
|
||||
osg::Light* light = new osg::Light();
|
||||
|
||||
osg::LightSource* lightsource = new osg::LightSource();
|
||||
|
||||
lightsource->setLight( light );
|
||||
light->setPosition(osg::Vec4(0,0,0,1));
|
||||
light->setLightNum( m_numlights );
|
||||
|
||||
daeElement *el = dlight->getTechnique_common()->getContents()[0];
|
||||
ambient = daeSafeCast< domLight::domTechnique_common::domAmbient >( el );
|
||||
directional = daeSafeCast< domLight::domTechnique_common::domDirectional >( el );
|
||||
point = daeSafeCast< domLight::domTechnique_common::domPoint >( el );
|
||||
spot = daeSafeCast< domLight::domTechnique_common::domSpot >( el );
|
||||
if ( ambient != NULL )
|
||||
{
|
||||
if ( ambient->getColor() == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Invalid content for ambient light" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
light->setAmbient( osg::Vec4( ambient->getColor()->getValue()[0], ambient->getColor()->getValue()[1],
|
||||
ambient->getColor()->getValue()[2], 1.0f ) );
|
||||
}
|
||||
else if ( directional != NULL )
|
||||
{
|
||||
if ( directional->getColor() == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Invalid content for ambient light" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
light->setDiffuse( osg::Vec4( directional->getColor()->getValue()[0], directional->getColor()->getValue()[1],
|
||||
directional->getColor()->getValue()[2], 1.0f ) );
|
||||
light->setSpecular( osg::Vec4( directional->getColor()->getValue()[0], directional->getColor()->getValue()[1],
|
||||
directional->getColor()->getValue()[2], 1.0f ) );
|
||||
|
||||
light->setDirection( osg::Vec3( 0, 0, -1 ) );
|
||||
}
|
||||
else if ( point != NULL )
|
||||
{
|
||||
if ( point->getColor() == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Invalid content for ambient light" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
light->setDiffuse( osg::Vec4( point->getColor()->getValue()[0], point->getColor()->getValue()[1],
|
||||
point->getColor()->getValue()[2], 1.0f ) );
|
||||
light->setSpecular( osg::Vec4( point->getColor()->getValue()[0], point->getColor()->getValue()[1],
|
||||
point->getColor()->getValue()[2], 1.0f ) );
|
||||
|
||||
if ( point->getConstant_attenuation() != NULL )
|
||||
{
|
||||
light->setConstantAttenuation( point->getConstant_attenuation()->getValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
light->setConstantAttenuation( 1.0 );
|
||||
}
|
||||
if ( point->getLinear_attenuation() != NULL )
|
||||
{
|
||||
light->setLinearAttenuation( point->getLinear_attenuation()->getValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
light->setLinearAttenuation( 0.0 );
|
||||
}
|
||||
if ( point->getQuadratic_attenuation() != NULL )
|
||||
{
|
||||
light->setQuadraticAttenuation( point->getQuadratic_attenuation()->getValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
light->setQuadraticAttenuation( 0.0 );
|
||||
}
|
||||
|
||||
}
|
||||
else if ( spot != NULL )
|
||||
{
|
||||
if ( spot->getColor() == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Invalid content for ambient light" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
light->setDiffuse( osg::Vec4( spot->getColor()->getValue()[0], spot->getColor()->getValue()[1],
|
||||
spot->getColor()->getValue()[2], 1.0f ) );
|
||||
light->setSpecular( osg::Vec4( spot->getColor()->getValue()[0], spot->getColor()->getValue()[1],
|
||||
spot->getColor()->getValue()[2], 1.0f ) );
|
||||
|
||||
if ( spot->getConstant_attenuation() != NULL )
|
||||
{
|
||||
light->setConstantAttenuation( spot->getConstant_attenuation()->getValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
light->setConstantAttenuation( 1.0f );
|
||||
}
|
||||
if ( spot->getLinear_attenuation() != NULL )
|
||||
{
|
||||
light->setLinearAttenuation( spot->getLinear_attenuation()->getValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
light->setLinearAttenuation( 0.0f );
|
||||
}
|
||||
if ( spot->getQuadratic_attenuation() != NULL )
|
||||
{
|
||||
light->setQuadraticAttenuation( spot->getQuadratic_attenuation()->getValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
light->setQuadraticAttenuation( 0.0f );
|
||||
}
|
||||
|
||||
if ( spot->getFalloff_angle() != NULL )
|
||||
{
|
||||
light->setSpotCutoff( spot->getFalloff_angle()->getValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
light->setSpotCutoff( 180.0f );
|
||||
}
|
||||
|
||||
if ( spot->getFalloff_exponent() != NULL )
|
||||
{
|
||||
light->setSpotExponent( spot->getFalloff_exponent()->getValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
light->setSpotExponent( 0.0f );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
osg::Switch* svitch = static_cast<osg::Switch*>(node);
|
||||
|
||||
// Switched of by default to avoid excessively large scene bound
|
||||
svitch->addChild(lightsource,false);
|
||||
|
||||
m_numlights++;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
osg::Node* daeReader::processCamera( domCamera* /*dcamera*/ )
|
||||
{
|
||||
//TODO: Make the camera actually make a camera to view from. Not just draw a cone.
|
||||
osg::Node *node = new osg::Switch();
|
||||
|
||||
osg::Cone* cone = new osg::Cone();
|
||||
|
||||
osg::ShapeDrawable* sd = new osg::ShapeDrawable(cone);
|
||||
|
||||
cone->setRadius(0.3);
|
||||
cone->setHeight(1.0);
|
||||
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
|
||||
geode->addDrawable(sd);
|
||||
geode->setName("camera");
|
||||
|
||||
osg::Switch* svitch = static_cast<osg::Switch*>(node);
|
||||
|
||||
// Switched of by default to avoid excessively large scene bound
|
||||
svitch->addChild(geode,false);
|
||||
|
||||
return node;
|
||||
}
|
||||
197
src/osgPlugins/dae/daeRTransforms.cpp
Normal file
197
src/osgPlugins/dae/daeRTransforms.cpp
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include "daeReader.h"
|
||||
#include <dae.h>
|
||||
#include <dom/domCOLLADA.h>
|
||||
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
#include <osg/MatrixTransform>
|
||||
|
||||
using namespace osgdae;
|
||||
|
||||
osg::Transform* daeReader::processMatrix( domMatrix *mat )
|
||||
{
|
||||
osg::Transform* xform = new osg::MatrixTransform();
|
||||
xform->setDataVariance(osg::Object::STATIC);
|
||||
|
||||
xform->setName( mat->getSid() ? mat->getSid() : "" );
|
||||
|
||||
osg::Matrix m;
|
||||
|
||||
if (mat->getValue().getCount() != 16 ) {
|
||||
osg::notify(osg::WARN)<<"Data is wrong size for matrix"<<std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//m.set((daeDouble*)mat->getValue().getRawData());
|
||||
m.set( mat->getValue()[0], mat->getValue()[4], mat->getValue()[8], mat->getValue()[12],
|
||||
mat->getValue()[1], mat->getValue()[5], mat->getValue()[9], mat->getValue()[13],
|
||||
mat->getValue()[2], mat->getValue()[6], mat->getValue()[10], mat->getValue()[14],
|
||||
mat->getValue()[3], mat->getValue()[7], mat->getValue()[11], mat->getValue()[15] );
|
||||
|
||||
xform->asMatrixTransform()->setMatrix(m);
|
||||
|
||||
return xform;
|
||||
}
|
||||
|
||||
osg::Transform* daeReader::processTranslate( domTranslate *trans )
|
||||
{
|
||||
osg::Transform* xform = new osg::PositionAttitudeTransform();
|
||||
//xform->setDataVariance(osg::Object::STATIC);
|
||||
|
||||
xform->setName( trans->getSid() ? trans->getSid() : "" );
|
||||
|
||||
if (trans->getValue().getCount() != 3 ) {
|
||||
osg::notify(osg::WARN)<<"Data is wrong size for translate"<<std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
domFloat3& t = trans->getValue();
|
||||
|
||||
xform->asPositionAttitudeTransform()->setPosition(
|
||||
osg::Vec3(t[0],t[1],t[2]));
|
||||
|
||||
return xform;
|
||||
}
|
||||
|
||||
osg::Transform* daeReader::processRotate( domRotate *rot )
|
||||
{
|
||||
osg::Transform* xform = new osg::PositionAttitudeTransform();
|
||||
//xform->setDataVariance(osg::Object::STATIC);
|
||||
|
||||
xform->setName( rot->getSid() ? rot->getSid() : "" );
|
||||
|
||||
if (rot->getValue().getCount() != 4 ) {
|
||||
osg::notify(osg::WARN)<<"Data is wrong size for rotate"<<std::endl;
|
||||
return NULL;
|
||||
}
|
||||
domFloat4& r = rot->getValue();
|
||||
|
||||
osg::Vec3 axis;
|
||||
axis.set(r[0],r[1],r[2]);
|
||||
xform->asPositionAttitudeTransform()->setAttitude(
|
||||
osg::Quat(osg::DegreesToRadians(r[3]),axis));
|
||||
|
||||
return xform;
|
||||
}
|
||||
|
||||
osg::Transform* daeReader::processScale( domScale *scale )
|
||||
{
|
||||
osg::Transform* xform = new osg::PositionAttitudeTransform();
|
||||
//xform->setDataVariance(osg::Object::STATIC);
|
||||
|
||||
xform->setName( scale->getSid() ? scale->getSid() : "" );
|
||||
|
||||
if (scale->getValue().getCount() != 3 ) {
|
||||
osg::notify(osg::WARN)<<"Data is wrong size for scale"<<std::endl;
|
||||
return NULL;
|
||||
}
|
||||
domFloat3& s = scale->getValue();
|
||||
|
||||
xform->asPositionAttitudeTransform()->setScale(
|
||||
osg::Vec3(s[0],s[1],s[2]));
|
||||
|
||||
return xform;
|
||||
}
|
||||
|
||||
osg::Transform* daeReader::processLookat( domLookat *la )
|
||||
{
|
||||
osg::Transform* xform = new osg::MatrixTransform();
|
||||
xform->setDataVariance(osg::Object::STATIC);
|
||||
|
||||
xform->setName( la->getSid() ? la->getSid() : "" );
|
||||
|
||||
if (la->getValue().getCount() != 9 ) {
|
||||
osg::notify(osg::WARN)<<"Data is wrong size for lookat"<<std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
osg::Matrix m;
|
||||
|
||||
osg::Vec3 eye;
|
||||
osg::Vec3 center;
|
||||
osg::Vec3 up;
|
||||
|
||||
eye.set( la->getValue()[0], la->getValue()[1], la->getValue()[2] );
|
||||
center.set( la->getValue()[3], la->getValue()[4], la->getValue()[5] );
|
||||
up.set( la->getValue()[6], la->getValue()[7], la->getValue()[8] );
|
||||
|
||||
m.makeLookAt( eye, center, up );
|
||||
|
||||
xform->asMatrixTransform()->setMatrix(m);
|
||||
|
||||
return xform;
|
||||
}
|
||||
|
||||
osg::Transform* daeReader::processSkew( domSkew *skew )
|
||||
{
|
||||
osg::Transform* xform = new osg::MatrixTransform();
|
||||
xform->setDataVariance(osg::Object::STATIC);
|
||||
|
||||
xform->setName( skew->getSid() ? skew->getSid() : "" );
|
||||
|
||||
if (skew->getValue().getCount() != 9 ) {
|
||||
osg::notify(osg::WARN)<<"Data is wrong size for skew"<<std::endl;
|
||||
return NULL;
|
||||
}
|
||||
domFloat7& s = skew->getValue();
|
||||
|
||||
float angle = s[0];
|
||||
float shear = sin(osg::DegreesToRadians(angle));
|
||||
osg::Vec3 around(s[1],s[2],s[3]);
|
||||
osg::Vec3 along(s[4],s[5],s[6]);
|
||||
|
||||
osg::Vec3 const x(1,0,0);
|
||||
osg::Vec3 const y(0,1,0);
|
||||
osg::Vec3 const z(0,0,1);
|
||||
|
||||
osg::Matrix m;
|
||||
|
||||
if ( along == x ) {
|
||||
if ( around == y ) {
|
||||
m(2,0) = shear;
|
||||
} else if ( around == z ) {
|
||||
m(1,0) = -shear;
|
||||
} else {
|
||||
//osg::notify(osg::WARN)<<"Unsupported skew around "<<around<<std::endl;
|
||||
}
|
||||
} else if ( along == y ) {
|
||||
if ( around == x ) {
|
||||
m(2,1) = -shear;
|
||||
} else if ( around == z ) {
|
||||
m(0,1) = shear;
|
||||
} else {
|
||||
//osg::notify(osg::WARN)<<"Unsupported skew around "<<around<<std::endl;
|
||||
}
|
||||
} else if ( along == z ) {
|
||||
if ( around == x ) {
|
||||
m(1,2) = shear;
|
||||
} else if ( around == y ) {
|
||||
m(0,2) = -shear;
|
||||
} else {
|
||||
//osg::notify(osg::WARN)<<"Unsupported skew around "<<around<<std::endl;
|
||||
}
|
||||
} else {
|
||||
//osg::notify(osg::WARN)<<"Unsupported skew along "<<along<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
if (angle > 0) {
|
||||
//osg::notify(osg::NOTICE)<<"Skew: angle("<<angle<<") around("<<around<<") along("<<along<<")"<<std::endl;
|
||||
}
|
||||
|
||||
xform->asMatrixTransform()->setMatrix(m);
|
||||
|
||||
return xform;
|
||||
}
|
||||
281
src/osgPlugins/dae/daeReader.cpp
Normal file
281
src/osgPlugins/dae/daeReader.cpp
Normal file
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include "daeReader.h"
|
||||
#include <dae.h>
|
||||
#include <dom/domCOLLADA.h>
|
||||
#include <dom/domInstanceWithExtra.h>
|
||||
|
||||
using namespace osgdae;
|
||||
|
||||
daeReader::daeReader()
|
||||
{
|
||||
dae = new DAE;
|
||||
m_numlights = 0;
|
||||
currentEffect = NULL;
|
||||
}
|
||||
|
||||
daeReader::~daeReader()
|
||||
{
|
||||
if ( dae )
|
||||
{
|
||||
delete dae;
|
||||
DAE::cleanup();
|
||||
dae = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool daeReader::convert( const std::string &fileURI )
|
||||
{
|
||||
std::string fURI;
|
||||
if ( fileURI[1] == ':' )
|
||||
{
|
||||
fURI = "/" + fileURI;
|
||||
}
|
||||
else
|
||||
{
|
||||
fURI = fileURI;
|
||||
}
|
||||
if( dae->load( fURI.c_str() ) != DAE_OK )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Load failed in COLLADA DOM" << std::endl;
|
||||
return false;
|
||||
}
|
||||
osg::notify( osg::INFO ) << "URI loaded: " << fURI << std::endl;
|
||||
|
||||
domCOLLADA* document = dae->getDom( fURI.c_str() );
|
||||
|
||||
if ( !document->getScene() || !document->getScene()->getInstance_visual_scene() )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "No scene found!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
domInstanceWithExtra *ivs = document->getScene()->getInstance_visual_scene();
|
||||
domVisual_scene *vs = daeSafeCast< domVisual_scene >( getElementFromURI( ivs->getUrl() ) );
|
||||
if ( vs == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Unable to locate visual scene!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
rootNode = processVisualScene( vs );
|
||||
|
||||
delete dae;
|
||||
DAE::cleanup();
|
||||
dae = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
osg::Node* daeReader::processVisualScene( domVisual_scene *scene )
|
||||
{
|
||||
osg::Node *retVal;
|
||||
//### do not add an empty group if there is only one
|
||||
unsigned int nbVisualSceneGroup=scene->getNode_array().getCount();
|
||||
if (nbVisualSceneGroup==0)
|
||||
{
|
||||
osg::notify( osg::WARN ) << "No visual scene group found !" << std::endl;
|
||||
retVal = new osg::Group();
|
||||
retVal->setName("Empty Collada scene");
|
||||
}
|
||||
else if (nbVisualSceneGroup==1)
|
||||
{
|
||||
osg::Node *node = processNode( scene->getNode_array()[0] );
|
||||
if ( node != NULL )
|
||||
retVal = node;
|
||||
else
|
||||
{
|
||||
retVal = new osg::Group();
|
||||
retVal->setName("Empty Collada scene (import failure)");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retVal = new osg::Group();
|
||||
retVal->setName("Collada visual scene group");
|
||||
for ( size_t i = 0; i < scene->getNode_array().getCount(); i++ )
|
||||
{
|
||||
osg::Node *node = processNode( scene->getNode_array()[i] );
|
||||
if ( node != NULL )
|
||||
{
|
||||
retVal->asGroup()->addChild( node );
|
||||
}
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
|
||||
}
|
||||
|
||||
osg::Node* daeReader::processNode( domNode *node )
|
||||
{
|
||||
osg::Node *retVal = new osg::Group();
|
||||
osg::Node *current = retVal;
|
||||
|
||||
size_t count = node->getContents().getCount();
|
||||
for ( size_t i = 0; i < count; i++ )
|
||||
{
|
||||
osg::Node *trans = NULL;
|
||||
|
||||
//I'm using daeSafeCast to check type because the pointer comparisons are a lot faster
|
||||
//than a strcmp
|
||||
|
||||
//TODO: I am doing transforms wrong. A Transform is itself a group node. They need to be
|
||||
//consolodated and then the children of the collada node need to be the children of the
|
||||
//transform node.
|
||||
domTranslate * t = daeSafeCast< domTranslate >( node->getContents()[i] );
|
||||
if ( t != NULL )
|
||||
{
|
||||
trans = processTranslate( t );
|
||||
if ( trans != NULL )
|
||||
{
|
||||
current->asGroup()->addChild( trans );
|
||||
current = trans;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domRotate * r = daeSafeCast< domRotate >( node->getContents()[i] );
|
||||
if ( r != NULL ) {
|
||||
trans = processRotate( r );
|
||||
if ( trans != NULL )
|
||||
{
|
||||
current->asGroup()->addChild( trans );
|
||||
current = trans;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domScale * s = daeSafeCast< domScale >( node->getContents()[i] );
|
||||
if ( s != NULL ) {
|
||||
trans = processScale( s );
|
||||
if ( trans != NULL )
|
||||
{
|
||||
current->asGroup()->addChild( trans );
|
||||
current = trans;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domMatrix * m = daeSafeCast< domMatrix >( node->getContents()[i] );
|
||||
if ( m != NULL ) {
|
||||
trans = processMatrix( m );
|
||||
if ( trans != NULL )
|
||||
{
|
||||
current->asGroup()->addChild( trans );
|
||||
current = trans;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domSkew *sk = daeSafeCast< domSkew >( node->getContents()[i] );
|
||||
if ( sk != NULL ) {
|
||||
trans = processSkew( sk );
|
||||
if ( trans != NULL )
|
||||
{
|
||||
current->asGroup()->addChild( trans );
|
||||
current = trans;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domInstance_geometry *ig = daeSafeCast< domInstance_geometry >( node->getContents()[i] );
|
||||
if ( ig != NULL )
|
||||
{
|
||||
trans = processInstance_geometry( ig );
|
||||
if ( trans != NULL )
|
||||
{
|
||||
current->asGroup()->addChild( trans );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domInstance_controller *ictrl = daeSafeCast< domInstance_controller >( node->getContents()[i] );
|
||||
if ( ictrl != NULL )
|
||||
{
|
||||
trans = processInstance_controller( ictrl );
|
||||
if ( trans != NULL )
|
||||
{
|
||||
current->asGroup()->addChild( trans );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domInstance_camera *ic = daeSafeCast< domInstance_camera >( node->getContents()[i] );
|
||||
if ( ic != NULL )
|
||||
{
|
||||
daeElement *el = getElementFromURI( ic->getUrl() );
|
||||
domCamera *c = daeSafeCast< domCamera >( el );
|
||||
if ( c == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Failed to locate camera " << ic->getUrl().getURI() << std::endl;
|
||||
}
|
||||
trans = processCamera( c );
|
||||
if ( trans != NULL )
|
||||
{
|
||||
current->asGroup()->addChild( trans );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domInstance_light *il = daeSafeCast< domInstance_light >( node->getContents()[i] );
|
||||
if ( il != NULL )
|
||||
{
|
||||
daeElement *el = getElementFromURI( il->getUrl() );
|
||||
domLight *l = daeSafeCast< domLight >( el );
|
||||
if ( l == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Failed to locate light " << il->getUrl().getURI() << std::endl;
|
||||
}
|
||||
trans = processLight( l );
|
||||
if ( trans != NULL )
|
||||
{
|
||||
current->asGroup()->addChild( trans );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domInstance_node *instn = daeSafeCast< domInstance_node >( node->getContents()[i] );
|
||||
if ( instn != NULL )
|
||||
{
|
||||
daeElement *el = getElementFromURI( instn->getUrl() );
|
||||
domNode *n = daeSafeCast< domNode >( el );
|
||||
if ( n == NULL )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "Failed to locate camera " << ic->getUrl().getURI() << std::endl;
|
||||
}
|
||||
trans = processNode( n );
|
||||
if ( trans != NULL )
|
||||
{
|
||||
current->asGroup()->addChild( trans );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
domNode *n = daeSafeCast< domNode >( node->getContents()[i] );
|
||||
if ( n != NULL )
|
||||
{
|
||||
trans = processNode( n );
|
||||
if ( trans != NULL )
|
||||
{
|
||||
current->asGroup()->addChild( trans );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const char *name = node->getContents()[i]->getElementName();
|
||||
if ( name == NULL ) name = node->getContents()[i]->getTypeName();
|
||||
osg::notify( osg::WARN ) << "Unsupported element type: " << name << " in COLLADA scene!" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
177
src/osgPlugins/dae/daeReader.h
Normal file
177
src/osgPlugins/dae/daeReader.h
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#ifndef _DAE_CONV_H_
|
||||
#define _DAE_CONV_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <dae.h>
|
||||
#include <dae/daeURI.h>
|
||||
#include <dae/daeElement.h>
|
||||
#include <dom/domCommon_color_or_texture_type.h>
|
||||
|
||||
#include <osg/Node>
|
||||
#include <osg/Transform>
|
||||
#include <osg/Notify>
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/Registry>
|
||||
#include <osg/Material>
|
||||
|
||||
#include "daeUtils.h"
|
||||
|
||||
|
||||
class domBind_material;
|
||||
class domCamera;
|
||||
//class domCommon_color_or_texture_type;
|
||||
class domCommon_float_or_param_type;
|
||||
class domGeometry;
|
||||
class domInstance_controller;
|
||||
class domInstance_geometry;
|
||||
class domInstanceWithExtra;
|
||||
class domLight;
|
||||
class domLookat;
|
||||
class domMatrix;
|
||||
class domNode;
|
||||
class domP;
|
||||
class domProfile_COMMON;
|
||||
class domScale;
|
||||
class domSkew;
|
||||
class domTranslate;
|
||||
class domRotate;
|
||||
class domVisual_scene;
|
||||
|
||||
#include <dom/domInputLocalOffset.h>
|
||||
|
||||
namespace osgdae {
|
||||
|
||||
class domSourceReader;
|
||||
|
||||
inline daeElement *getElementFromURI( daeURI &uri )
|
||||
{
|
||||
if ( uri.getState() == daeURI::uri_loaded || uri.getState() == daeURI::uri_pending ) {
|
||||
uri.resolveElement();
|
||||
}
|
||||
return uri.getElement();
|
||||
}
|
||||
inline daeElement *getElementFromIDRef( daeIDRef &idref )
|
||||
{
|
||||
if ( idref.getState() == daeIDRef::id_loaded || idref.getState() == daeIDRef::id_pending ) {
|
||||
idref.resolveElement();
|
||||
}
|
||||
return idref.getElement();
|
||||
}
|
||||
|
||||
template< typename TInputArray, typename TInputType >
|
||||
bool findInputSourceBySemantic( TInputArray& inputs, const char* semantic, daeElement *& element,
|
||||
TInputType ** input = NULL, int unit = 0 )
|
||||
{
|
||||
element = NULL;
|
||||
int count = 0;
|
||||
for ( size_t i = 0; i < inputs.getCount(); i++ ) {
|
||||
if ( !strcmp(semantic, inputs[i]->getSemantic()) ) {
|
||||
if ( count == unit )
|
||||
{
|
||||
element = getElementFromURI( inputs[i]->getSource() );
|
||||
*input = (TInputType*)inputs[i];
|
||||
return true;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@class daeReader
|
||||
@brief Read a OSG scene from a DAE file
|
||||
*/
|
||||
class daeReader {
|
||||
public:
|
||||
daeReader();
|
||||
virtual ~daeReader();
|
||||
|
||||
bool convert( const std::string &fileURI );
|
||||
|
||||
osg::Node* getRootNode() { return rootNode; }
|
||||
|
||||
protected:
|
||||
//scene processing
|
||||
osg::Node* processVisualScene( domVisual_scene *scene );
|
||||
osg::Node* processNode( domNode *node );
|
||||
//osg::Node* processInstance( domInstanceWithExtra *iwe );
|
||||
|
||||
//transform processing
|
||||
osg::Transform* processMatrix( domMatrix *mat );
|
||||
osg::Transform* processTranslate( domTranslate *trans );
|
||||
osg::Transform* processRotate( domRotate *rot );
|
||||
osg::Transform* processScale( domScale *scale );
|
||||
osg::Transform* processLookat( domLookat *la );
|
||||
osg::Transform* processSkew( domSkew *skew );
|
||||
|
||||
//geometry processing
|
||||
osg::Node* processInstance_geometry( domInstance_geometry *ig );
|
||||
osg::Node* processGeometry( domGeometry *geo );
|
||||
osg::Node* processInstance_controller( domInstance_controller *ictrl );
|
||||
|
||||
typedef std::map< daeElement*, domSourceReader > SourceMap;
|
||||
typedef std::map< int, osg::IntArray*, std::less<int> > IndexMap;
|
||||
|
||||
template< typename T >
|
||||
osg::Node* processSinglePPrimitive( T *group, SourceMap &sources, GLenum mode );
|
||||
|
||||
template< typename T >
|
||||
osg::Node* processMultiPPrimitive( T *group, SourceMap &sources, GLenum mode );
|
||||
|
||||
osg::Node* processPolylist( domPolylist *group, SourceMap &sources );
|
||||
|
||||
void resolveArrays( domInputLocalOffset_Array &inputs, osg::Geometry *&geom,
|
||||
SourceMap &sources, IndexMap &index_map );
|
||||
|
||||
void processP( domP *p, osg::Geometry *&geom, IndexMap &index_map, osg::DrawArrayLengths* dal/*GLenum mode*/ );
|
||||
|
||||
//material/effect processing
|
||||
void processBindMaterial( domBind_material *bm, osg::Node *geo );
|
||||
osg::StateSet *processMaterial( domMaterial *mat );
|
||||
osg::StateSet *processEffect( domEffect *effect );
|
||||
osg::StateSet *processProfileCOMMON( domProfile_COMMON *pc );
|
||||
bool processColorOrTextureType( domCommon_color_or_texture_type *cot,
|
||||
osg::Material::ColorMode channel, osg::Material *mat, domCommon_float_or_param_type *fop = NULL, osg::StateAttribute **sa = NULL );
|
||||
osg::StateAttribute *processTransparentType( domCommon_transparent_type *ctt, osg::StateSet *ss );
|
||||
|
||||
osg::StateAttribute *processTexture( domCommon_color_or_texture_type_complexType::domTexture *tex );
|
||||
|
||||
//scene objects
|
||||
osg::Node* processLight( domLight *dlight );
|
||||
osg::Node* processCamera( domCamera *dcamera );
|
||||
|
||||
protected:
|
||||
DAE *dae;
|
||||
osg::Node* rootNode;
|
||||
|
||||
int m_numlights;
|
||||
|
||||
domEffect *currentEffect;
|
||||
|
||||
std::map< domGeometry*, osg::Node* > geometryMap;
|
||||
std::map< domMaterial*, osg::StateSet* > materialMap;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
32
src/osgPlugins/dae/daeUtils.h
Normal file
32
src/osgPlugins/dae/daeUtils.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#ifndef _DAE_UTILS_H_
|
||||
#define _DAE_UTILS_H_
|
||||
|
||||
#include <dae/daeElement.h>
|
||||
|
||||
namespace osgdae {
|
||||
|
||||
template <typename T>
|
||||
inline T *daeSafeCast( daeElement *element )
|
||||
{
|
||||
if ( element && element->getMeta() == T::_Meta )
|
||||
return (T *)element;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
1154
src/osgPlugins/dae/daeWGeometry.cpp
Normal file
1154
src/osgPlugins/dae/daeWGeometry.cpp
Normal file
File diff suppressed because it is too large
Load Diff
338
src/osgPlugins/dae/daeWMaterials.cpp
Normal file
338
src/osgPlugins/dae/daeWMaterials.cpp
Normal file
@@ -0,0 +1,338 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include "daeWriter.h"
|
||||
|
||||
#include <dae/domAny.h>
|
||||
#include <dom/domCOLLADA.h>
|
||||
#include <dom/domConstants.h>
|
||||
#include <dom/domProfile_COMMON.h>
|
||||
|
||||
//#include <dom/domLibrary_effects.h>
|
||||
//#include <dom/domLibrary_materials.h>
|
||||
|
||||
using namespace osgdae;
|
||||
|
||||
void daeWriter::processMaterial( osg::StateSet *ss, domInstance_geometry *ig, const std::string &geoName )
|
||||
{
|
||||
domBind_material *bm = daeSafeCast< domBind_material >( ig->createAndPlace( COLLADA_ELEMENT_BIND_MATERIAL ) );
|
||||
domBind_material::domTechnique_common *tc = daeSafeCast< domBind_material::domTechnique_common >( bm->createAndPlace( "technique_common" ) );
|
||||
domInstance_material *im = daeSafeCast< domInstance_material >( tc->createAndPlace( COLLADA_ELEMENT_INSTANCE_MATERIAL ) );
|
||||
std::string symbol = geoName + "_material";
|
||||
im->setSymbol( symbol.c_str() );
|
||||
|
||||
std::map< osg::StateSet*, domMaterial* >::iterator iter = materialMap.find( ss );
|
||||
if ( iter != materialMap.end() )
|
||||
{
|
||||
std::string url = "#" + std::string( iter->second->getId() );
|
||||
im->setTarget( url.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( lib_mats == NULL )
|
||||
{
|
||||
lib_mats = daeSafeCast< domLibrary_materials >( dom->createAndPlace( COLLADA_ELEMENT_LIBRARY_MATERIALS ) );
|
||||
}
|
||||
|
||||
domMaterial *mat = daeSafeCast< domMaterial >( lib_mats->createAndPlace( COLLADA_ELEMENT_MATERIAL ) );
|
||||
std::string name = ss->getName();
|
||||
if ( name.empty() )
|
||||
{
|
||||
name = "material";
|
||||
}
|
||||
name = uniquify( name );
|
||||
|
||||
mat->setId( name.c_str() );
|
||||
|
||||
std::string url = "#" + name;
|
||||
im->setTarget( url.c_str() );
|
||||
|
||||
domInstance_effect *ie = daeSafeCast<domInstance_effect>( mat->createAndPlace( "instance_effect" ) );
|
||||
|
||||
if ( lib_effects == NULL )
|
||||
{
|
||||
lib_effects = daeSafeCast< domLibrary_effects >( dom->createAndPlace( COLLADA_ELEMENT_LIBRARY_EFFECTS ) );
|
||||
}
|
||||
domEffect *effect = daeSafeCast< domEffect >( lib_effects->createAndPlace( COLLADA_ELEMENT_EFFECT ) );
|
||||
std::string efName = name + "_effect";
|
||||
|
||||
effect->setId( efName.c_str() );
|
||||
|
||||
url = "#" + efName;
|
||||
ie->setUrl( url.c_str() );
|
||||
|
||||
domProfile_COMMON *pc = daeSafeCast< domProfile_COMMON >( effect->createAndPlace( COLLADA_ELEMENT_PROFILE_COMMON ) );
|
||||
domProfile_COMMON::domTechnique *pc_teq = daeSafeCast< domProfile_COMMON::domTechnique >( pc->createAndPlace( "technique" ) );
|
||||
pc_teq->setSid( "t0" );
|
||||
domProfile_COMMON::domTechnique::domPhong *phong = daeSafeCast< domProfile_COMMON::domTechnique::domPhong >( pc_teq->createAndPlace( "phong" ) );
|
||||
|
||||
osg::Texture *tex = static_cast<osg::Texture*>(ss->getTextureAttribute( 0, osg::StateAttribute::TEXTURE ));
|
||||
if ( ss->getTextureAttribute( 1, osg::StateAttribute::TEXTURE ) != NULL )
|
||||
{
|
||||
tex = static_cast<osg::Texture*>(ss->getTextureAttribute( 1, osg::StateAttribute::TEXTURE ));
|
||||
}
|
||||
if ( tex != NULL && tex->getImage( 0 ) != NULL )
|
||||
{
|
||||
//TODO: Export all of the texture Attributes like wrap mode and all that jazz
|
||||
domImage *img = daeSafeCast< domImage >( pc->createAndPlace( COLLADA_ELEMENT_IMAGE ) );
|
||||
std::string iName = efName + "-image";
|
||||
img->setId( iName.c_str() );
|
||||
|
||||
osg::Image *osgimg = tex->getImage( 0 );
|
||||
domImage::domInit_from *imgif = daeSafeCast< domImage::domInit_from >( img->createAndPlace( "init_from" ) );
|
||||
std::string imgstr = "/" + osgDB::convertFileNameToUnixStyle( osgDB::findDataFile( osgimg->getFileName() ) );
|
||||
daeURI uri( imgstr.c_str() );
|
||||
uri.validate();
|
||||
imgif->setValue( uri.getURI() );
|
||||
//imgif->setValue( imgstr.c_str() );
|
||||
//imgif->getValue().validate();
|
||||
imgif->getValue().makeRelativeTo( doc->getDocumentURI() );
|
||||
//imgif->setValue( osgimg->getFileName().c_str() );
|
||||
//osg::notify( osg::WARN ) << "original img filename " << osgimg->getFileName() << std::endl;
|
||||
//osg::notify( osg::WARN ) << "init_from filename " << imgstr << std::endl;
|
||||
|
||||
#ifndef EARTH_TEX
|
||||
domCommon_newparam_type *np = daeSafeCast< domCommon_newparam_type >( pc->createAndPlace( "newparam" ) );
|
||||
std::string surfName = efName + "-surface";
|
||||
np->setSid( surfName.c_str() );
|
||||
domFx_surface_common *surface = daeSafeCast< domFx_surface_common >( np->createAndPlace( "surface" ) );
|
||||
domFx_surface_init_from_common *sif = daeSafeCast< domFx_surface_init_from_common >( surface->createAndPlace("init_from") );
|
||||
sif->setValue( iName.c_str() );
|
||||
surface->setType( FX_SURFACE_TYPE_ENUM_2D );
|
||||
|
||||
np = daeSafeCast< domCommon_newparam_type >( pc->createAndPlace( "newparam" ) );
|
||||
std::string sampName = efName + "-sampler";
|
||||
np->setSid( sampName.c_str() );
|
||||
domFx_sampler2D_common *sampler = daeSafeCast< domFx_sampler2D_common >( np->createAndPlace( "sampler2D" ) );
|
||||
domFx_sampler2D_common_complexType::domSource *source = daeSafeCast< domFx_sampler2D_common_complexType::domSource >( sampler->createAndPlace( "source" ) );
|
||||
source->setValue( surfName.c_str() );
|
||||
|
||||
//set sampler state
|
||||
domFx_sampler2D_common_complexType::domWrap_s *wrap_s = daeSafeCast< domFx_sampler2D_common_complexType::domWrap_s >( sampler->createAndPlace( "wrap_s" ) );
|
||||
osg::Texture::WrapMode wrap = tex->getWrap( osg::Texture::WRAP_S );
|
||||
switch( wrap )
|
||||
{
|
||||
case osg::Texture::CLAMP:
|
||||
wrap_s->setValue( FX_SAMPLER_WRAP_COMMON_CLAMP );
|
||||
break;
|
||||
case osg::Texture::CLAMP_TO_BORDER:
|
||||
case osg::Texture::CLAMP_TO_EDGE:
|
||||
wrap_s->setValue( FX_SAMPLER_WRAP_COMMON_BORDER );
|
||||
break;
|
||||
case osg::Texture::REPEAT:
|
||||
wrap_s->setValue( FX_SAMPLER_WRAP_COMMON_WRAP );
|
||||
break;
|
||||
case osg::Texture::MIRROR:
|
||||
wrap_s->setValue( FX_SAMPLER_WRAP_COMMON_MIRROR );
|
||||
break;
|
||||
default:
|
||||
wrap_s->setValue( FX_SAMPLER_WRAP_COMMON_NONE );
|
||||
break;
|
||||
}
|
||||
|
||||
domFx_sampler2D_common_complexType::domWrap_t *wrap_t = daeSafeCast< domFx_sampler2D_common_complexType::domWrap_t >( sampler->createAndPlace( "wrap_t" ) );
|
||||
wrap = tex->getWrap( osg::Texture::WRAP_T );
|
||||
switch( wrap )
|
||||
{
|
||||
case osg::Texture::CLAMP:
|
||||
wrap_t->setValue( FX_SAMPLER_WRAP_COMMON_CLAMP );
|
||||
break;
|
||||
case osg::Texture::CLAMP_TO_BORDER:
|
||||
case osg::Texture::CLAMP_TO_EDGE:
|
||||
wrap_t->setValue( FX_SAMPLER_WRAP_COMMON_BORDER );
|
||||
break;
|
||||
case osg::Texture::REPEAT:
|
||||
wrap_t->setValue( FX_SAMPLER_WRAP_COMMON_WRAP );
|
||||
break;
|
||||
case osg::Texture::MIRROR:
|
||||
wrap_t->setValue( FX_SAMPLER_WRAP_COMMON_MIRROR );
|
||||
break;
|
||||
default:
|
||||
wrap_t->setValue( FX_SAMPLER_WRAP_COMMON_NONE );
|
||||
break;
|
||||
}
|
||||
|
||||
const osg::Vec4 &bcol = tex->getBorderColor();
|
||||
domFx_sampler2D_common_complexType::domBorder_color *dbcol = daeSafeCast< domFx_sampler2D_common_complexType::domBorder_color >( sampler->createAndPlace( "border_color" ) );
|
||||
dbcol->getValue().append( bcol.r() );
|
||||
dbcol->getValue().append( bcol.g() );
|
||||
dbcol->getValue().append( bcol.b() );
|
||||
dbcol->getValue().append( bcol.a() );
|
||||
|
||||
domFx_sampler2D_common_complexType::domMinfilter *minfilter = daeSafeCast< domFx_sampler2D_common_complexType::domMinfilter >( sampler->createAndPlace( "minfilter" ) );
|
||||
osg::Texture::FilterMode mode = tex->getFilter( osg::Texture::MIN_FILTER );
|
||||
switch( mode )
|
||||
{
|
||||
case osg::Texture::LINEAR:
|
||||
minfilter->setValue( FX_SAMPLER_FILTER_COMMON_LINEAR );
|
||||
break;
|
||||
case osg::Texture::LINEAR_MIPMAP_LINEAR:
|
||||
minfilter->setValue( FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_LINEAR );
|
||||
break;
|
||||
case osg::Texture::LINEAR_MIPMAP_NEAREST:
|
||||
minfilter->setValue( FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_NEAREST );
|
||||
break;
|
||||
case osg::Texture::NEAREST:
|
||||
minfilter->setValue( FX_SAMPLER_FILTER_COMMON_NEAREST );
|
||||
break;
|
||||
case osg::Texture::NEAREST_MIPMAP_LINEAR:
|
||||
minfilter->setValue( FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_LINEAR );
|
||||
break;
|
||||
case osg::Texture::NEAREST_MIPMAP_NEAREST:
|
||||
minfilter->setValue( FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_NEAREST );
|
||||
break;
|
||||
}
|
||||
|
||||
domFx_sampler2D_common_complexType::domMagfilter *magfilter = daeSafeCast< domFx_sampler2D_common_complexType::domMagfilter >( sampler->createAndPlace( "magfilter" ) );
|
||||
mode = tex->getFilter( osg::Texture::MAG_FILTER );
|
||||
switch( mode )
|
||||
{
|
||||
case osg::Texture::LINEAR:
|
||||
magfilter->setValue( FX_SAMPLER_FILTER_COMMON_LINEAR );
|
||||
break;
|
||||
case osg::Texture::LINEAR_MIPMAP_LINEAR:
|
||||
magfilter->setValue( FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_LINEAR );
|
||||
break;
|
||||
case osg::Texture::LINEAR_MIPMAP_NEAREST:
|
||||
magfilter->setValue( FX_SAMPLER_FILTER_COMMON_LINEAR_MIPMAP_NEAREST );
|
||||
break;
|
||||
case osg::Texture::NEAREST:
|
||||
magfilter->setValue( FX_SAMPLER_FILTER_COMMON_NEAREST );
|
||||
break;
|
||||
case osg::Texture::NEAREST_MIPMAP_LINEAR:
|
||||
magfilter->setValue( FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_LINEAR );
|
||||
break;
|
||||
case osg::Texture::NEAREST_MIPMAP_NEAREST:
|
||||
magfilter->setValue( FX_SAMPLER_FILTER_COMMON_NEAREST_MIPMAP_NEAREST );
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "diffuse" ) );
|
||||
domCommon_color_or_texture_type_complexType::domTexture *dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( cot->createAndPlace( "texture" ) );
|
||||
dtex->setTexture( sampName.c_str() );
|
||||
dtex->setTexcoord( "texcoord0" );
|
||||
#else
|
||||
domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "diffuse" ) );
|
||||
domCommon_color_or_texture_type_complexType::domTexture *dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( cot->createAndPlace( "texture" ) );
|
||||
dtex->setTexture( iName.c_str() );
|
||||
dtex->setTexcoord( "texcoord0" );
|
||||
#endif
|
||||
|
||||
domInstance_material::domBind_vertex_input *bvi = daeSafeCast< domInstance_material::domBind_vertex_input >( im->createAndPlace( "bind_vertex_input" ) );
|
||||
bvi->setSemantic( "texcoord0" );
|
||||
bvi->setInput_semantic( "TEXCOORD" );
|
||||
bvi->setInput_set( 0 );
|
||||
|
||||
//take care of blending if any
|
||||
osg::BlendFunc *bf = static_cast< osg::BlendFunc * >( ss->getAttribute( osg::StateAttribute::BLENDFUNC ) );
|
||||
osg::BlendColor *bc = static_cast< osg::BlendColor * >( ss->getAttribute( osg::StateAttribute::BLENDCOLOR ) );
|
||||
if ( bc != NULL )
|
||||
{
|
||||
domCommon_transparent_type *ctt = daeSafeCast< domCommon_transparent_type >( phong->createAndPlace( "transparent" ) );
|
||||
ctt->setOpaque( FX_OPAQUE_ENUM_RGB_ZERO );
|
||||
domCommon_color_or_texture_type_complexType::domColor *tcol = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( ctt->createAndPlace( "color" ) );
|
||||
tcol->getValue().append( bc->getConstantColor().r() );
|
||||
tcol->getValue().append( bc->getConstantColor().r() );
|
||||
tcol->getValue().append( bc->getConstantColor().r() );
|
||||
tcol->getValue().append( bc->getConstantColor().r() );
|
||||
}
|
||||
else if ( bf != NULL )
|
||||
{
|
||||
domCommon_transparent_type *ctt = daeSafeCast< domCommon_transparent_type >( phong->createAndPlace( "transparent" ) );
|
||||
ctt->setOpaque( FX_OPAQUE_ENUM_A_ONE );
|
||||
dtex = daeSafeCast< domCommon_color_or_texture_type_complexType::domTexture >( ctt->createAndPlace( "texture" ) );
|
||||
#ifndef EARTH_TEX
|
||||
dtex->setTexture( sampName.c_str() );
|
||||
#else
|
||||
dtex->setTexture( iName.c_str() );
|
||||
#endif
|
||||
dtex->setTexcoord( "texcoord0" );
|
||||
}
|
||||
|
||||
}
|
||||
osg::Material *osgmat = static_cast<osg::Material*>(ss->getAttribute( osg::StateAttribute::MATERIAL ));
|
||||
if ( osgmat != NULL )
|
||||
{
|
||||
const osg::Vec4 &eCol = osgmat->getEmissionFrontAndBack()?osgmat->getEmission( osg::Material::FRONT_AND_BACK ):osgmat->getEmission( osg::Material::FRONT );
|
||||
const osg::Vec4 &aCol = osgmat->getAmbientFrontAndBack()?osgmat->getAmbient( osg::Material::FRONT_AND_BACK ):osgmat->getAmbient( osg::Material::FRONT );
|
||||
const osg::Vec4 &dCol = osgmat->getDiffuseFrontAndBack()?osgmat->getDiffuse( osg::Material::FRONT_AND_BACK ):osgmat->getDiffuse( osg::Material::FRONT );
|
||||
const osg::Vec4 &sCol = osgmat->getSpecularFrontAndBack()?osgmat->getSpecular( osg::Material::FRONT_AND_BACK ):osgmat->getSpecular( osg::Material::FRONT );
|
||||
float shininess = osgmat->getShininessFrontAndBack()?osgmat->getShininess( osg::Material::FRONT_AND_BACK ):osgmat->getShininess( osg::Material::FRONT );
|
||||
|
||||
domCommon_color_or_texture_type *cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "emission" ) );
|
||||
domCommon_color_or_texture_type_complexType::domColor *col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->createAndPlace( "color" ) );
|
||||
col->getValue().append( eCol.r() );
|
||||
col->getValue().append( eCol.g() );
|
||||
col->getValue().append( eCol.b() );
|
||||
col->getValue().append( eCol.a() );
|
||||
|
||||
cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "ambient" ) );
|
||||
col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->createAndPlace( "color" ) );
|
||||
col->getValue().append( aCol.r() );
|
||||
col->getValue().append( aCol.g() );
|
||||
col->getValue().append( aCol.b() );
|
||||
col->getValue().append( aCol.a() );
|
||||
|
||||
|
||||
//### check if we really have a texture
|
||||
if ((tex == NULL) || (!cot->getTexture()))
|
||||
{
|
||||
cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "diffuse" ) );
|
||||
col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->createAndPlace( "color" ) );
|
||||
col->getValue().append( dCol.r() );
|
||||
col->getValue().append( dCol.g() );
|
||||
col->getValue().append( dCol.b() );
|
||||
col->getValue().append( dCol.a() );
|
||||
}
|
||||
else
|
||||
{
|
||||
cot = phong->getDiffuse();
|
||||
|
||||
domCommon_color_or_texture_type_complexType::domTexture *dtex = cot->getTexture();
|
||||
domExtra *extra = daeSafeCast< domExtra >( dtex->createAndPlace( COLLADA_ELEMENT_EXTRA ) );
|
||||
extra->setType( "color" );
|
||||
domTechnique *teq = daeSafeCast< domTechnique >( extra->createAndPlace( COLLADA_ELEMENT_TECHNIQUE ) );
|
||||
teq->setProfile( "SCEI" );
|
||||
domAny *any = (domAny*)(daeElement*)teq->createAndPlace( "color" );
|
||||
char colVal[256];
|
||||
colVal[0] = 0;
|
||||
for ( unsigned int i = 0; i < 4; i++ )
|
||||
{
|
||||
char val[16];
|
||||
#if 0
|
||||
itoa( dCol[i], val, 10 );
|
||||
#else
|
||||
snprintf(val,16,"%d",int(dCol[i]));
|
||||
#endif
|
||||
//strncat( colVal, val,256 );
|
||||
strncat( colVal, " ",256 );
|
||||
}
|
||||
any->setValue( colVal );
|
||||
|
||||
}
|
||||
|
||||
cot = daeSafeCast< domCommon_color_or_texture_type >( phong->createAndPlace( "specular" ) );
|
||||
col = daeSafeCast< domCommon_color_or_texture_type_complexType::domColor >( cot->createAndPlace( "color" ) );
|
||||
col->getValue().append( sCol.r() );
|
||||
col->getValue().append( sCol.g() );
|
||||
col->getValue().append( sCol.b() );
|
||||
col->getValue().append( sCol.a() );
|
||||
|
||||
domCommon_float_or_param_type *fop = daeSafeCast< domCommon_float_or_param_type >( phong->createAndPlace( "shininess" ) );
|
||||
domCommon_float_or_param_type_complexType::domFloat *f = daeSafeCast< domCommon_float_or_param_type_complexType::domFloat >( fop->createAndPlace( "float" ) );
|
||||
f->setValue( shininess );
|
||||
}
|
||||
|
||||
materialMap.insert( std::make_pair( ss, mat ) );
|
||||
}
|
||||
176
src/osgPlugins/dae/daeWSceneObjects.cpp
Normal file
176
src/osgPlugins/dae/daeWSceneObjects.cpp
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include "daeWriter.h"
|
||||
|
||||
#include <dom/domCOLLADA.h>
|
||||
|
||||
#include <dom/domNode.h>
|
||||
#include <dom/domConstants.h>
|
||||
#include <dom/domLibrary_cameras.h>
|
||||
#include <dom/domLibrary_lights.h>
|
||||
|
||||
//#include <dom/domVisual_scene.h>
|
||||
//#include <dom/domLibrary_visual_scenes.h>
|
||||
|
||||
using namespace osgdae;
|
||||
|
||||
|
||||
//GROUP
|
||||
void daeWriter::apply( osg::Group &node )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
debugPrint( node );
|
||||
#endif
|
||||
|
||||
while ( lastDepth >= _nodePath.size() )
|
||||
{
|
||||
//We are not a child of previous node
|
||||
currentNode = daeSafeCast< domNode >( currentNode->getParentElement() );
|
||||
lastDepth--;
|
||||
}
|
||||
currentNode = daeSafeCast< domNode >(currentNode->createAndPlace( COLLADA_ELEMENT_NODE ) );
|
||||
currentNode->setId(getNodeName(node,"group").c_str());
|
||||
|
||||
lastDepth = _nodePath.size();
|
||||
|
||||
lastVisited = GROUP;
|
||||
|
||||
traverse( node );
|
||||
}
|
||||
|
||||
|
||||
//SWITCH
|
||||
void daeWriter::apply( osg::Switch &node )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
debugPrint( node );
|
||||
#endif
|
||||
|
||||
while ( lastDepth >= _nodePath.size() )
|
||||
{
|
||||
//We are not a child of previous node
|
||||
currentNode = daeSafeCast< domNode >( currentNode->getParentElement() );
|
||||
lastDepth--;
|
||||
}
|
||||
currentNode = daeSafeCast< domNode >(currentNode->createAndPlace( COLLADA_ELEMENT_NODE ) );
|
||||
currentNode->setId(getNodeName(node,"switch").c_str());
|
||||
|
||||
lastDepth = _nodePath.size();
|
||||
|
||||
lastVisited = SWITCH;
|
||||
|
||||
unsigned int cnt = node.getNumChildren();
|
||||
for ( unsigned int i = 0; i < cnt; i++ )
|
||||
{
|
||||
if ( node.getValue( i ) )
|
||||
{
|
||||
node.getChild( i )->accept( *this );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//LOD
|
||||
void daeWriter::apply( osg::LOD &node )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
debugPrint( node );
|
||||
#endif
|
||||
|
||||
while ( lastDepth >= _nodePath.size() )
|
||||
{
|
||||
//We are not a child of previous node
|
||||
currentNode = daeSafeCast< domNode >( currentNode->getParentElement() );
|
||||
lastDepth--;
|
||||
}
|
||||
currentNode = daeSafeCast< domNode >(currentNode->createAndPlace( COLLADA_ELEMENT_NODE ) );
|
||||
lastDepth = _nodePath.size();
|
||||
currentNode->setId(getNodeName(node,"LOD").c_str());
|
||||
lastVisited = LOD;
|
||||
|
||||
//TODO : get the most or less detailed node, not only the first one
|
||||
|
||||
/*for ( unsigned int i = 0; i < node.getNumChildren(); i++ )
|
||||
{
|
||||
if ( node.getChild( i ) != NULL )
|
||||
{
|
||||
node.getChild( i )->accept( *this );
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
//unsigned int cnt = node.getNumChildren();
|
||||
node.getChild( 0 )->accept( *this );
|
||||
}
|
||||
|
||||
void daeWriter::apply( osg::ProxyNode &node )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "ProxyNode. Missing " << node.getNumChildren() << " children\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
//LIGHT
|
||||
void daeWriter::apply( osg::LightSource &node )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
debugPrint( node );
|
||||
#endif
|
||||
|
||||
domInstance_light *il = daeSafeCast< domInstance_light >( currentNode->createAndPlace( "instance_light" ) );
|
||||
std::string name = node.getName();
|
||||
if ( name.empty() )
|
||||
{
|
||||
name = uniquify( "light" );
|
||||
}
|
||||
std::string url = "#" + name;
|
||||
il->setUrl( url.c_str() );
|
||||
|
||||
if ( lib_lights == NULL )
|
||||
{
|
||||
lib_lights = daeSafeCast< domLibrary_lights >( dom->createAndPlace( COLLADA_ELEMENT_LIBRARY_LIGHTS ) );
|
||||
}
|
||||
domLight *light = daeSafeCast< domLight >( lib_lights->createAndPlace( COLLADA_ELEMENT_LIGHT ) );
|
||||
light->setId( name.c_str() );
|
||||
|
||||
lastVisited = LIGHT;
|
||||
|
||||
traverse( node );
|
||||
}
|
||||
|
||||
//CAMERA
|
||||
void daeWriter::apply( osg::CameraNode &node )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
debugPrint( node );
|
||||
#endif
|
||||
|
||||
domInstance_camera *ic = daeSafeCast< domInstance_camera >( currentNode->createAndPlace( "instance_camera" ) );
|
||||
std::string name = node.getName();
|
||||
if ( name.empty() )
|
||||
{
|
||||
name = uniquify( "camera" );
|
||||
}
|
||||
std::string url = "#" + name;
|
||||
ic->setUrl( url.c_str() );
|
||||
|
||||
if ( lib_cameras == NULL )
|
||||
{
|
||||
lib_cameras = daeSafeCast< domLibrary_cameras >( dom->createAndPlace( COLLADA_ELEMENT_LIBRARY_CAMERAS ) );
|
||||
}
|
||||
domCamera *cam = daeSafeCast< domCamera >( lib_cameras->createAndPlace( COLLADA_ELEMENT_CAMERA ) );
|
||||
cam->setId( name.c_str() );
|
||||
|
||||
lastVisited = CAMERA;
|
||||
|
||||
traverse( node );
|
||||
}
|
||||
134
src/osgPlugins/dae/daeWTransforms.cpp
Normal file
134
src/osgPlugins/dae/daeWTransforms.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include "daeWriter.h"
|
||||
|
||||
#include <dom/domCOLLADA.h>
|
||||
|
||||
#include <dom/domNode.h>
|
||||
#include <dom/domConstants.h>
|
||||
|
||||
using namespace osgdae;
|
||||
|
||||
//MATRIX
|
||||
void daeWriter::apply( osg::MatrixTransform &node )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
debugPrint( node );
|
||||
#endif
|
||||
|
||||
while ( lastDepth >= _nodePath.size() )
|
||||
{
|
||||
//We are not a child of previous node
|
||||
currentNode = daeSafeCast< domNode >( currentNode->getParentElement() );
|
||||
lastDepth--;
|
||||
}
|
||||
|
||||
currentNode = daeSafeCast< domNode >(currentNode->createAndPlace( COLLADA_ELEMENT_NODE ) );
|
||||
currentNode->setId(getNodeName(node,"matrixTransform").c_str());
|
||||
|
||||
domMatrix *mat = daeSafeCast< domMatrix >(currentNode->createAndPlace( COLLADA_ELEMENT_MATRIX ) );
|
||||
const osg::Matrix::value_type *mat_vals = node.getMatrix().ptr();
|
||||
//for ( int i = 0; i < 16; i++ )
|
||||
//{
|
||||
// mat->getValue().append( mat_vals[i] );
|
||||
//}
|
||||
mat->getValue().append( mat_vals[0] );
|
||||
mat->getValue().append( mat_vals[4] );
|
||||
mat->getValue().append( mat_vals[8] );
|
||||
mat->getValue().append( mat_vals[12] );
|
||||
mat->getValue().append( mat_vals[1] );
|
||||
mat->getValue().append( mat_vals[5] );
|
||||
mat->getValue().append( mat_vals[9] );
|
||||
mat->getValue().append( mat_vals[13] );
|
||||
mat->getValue().append( mat_vals[2] );
|
||||
mat->getValue().append( mat_vals[6] );
|
||||
mat->getValue().append( mat_vals[10] );
|
||||
mat->getValue().append( mat_vals[14] );
|
||||
mat->getValue().append( mat_vals[3] );
|
||||
mat->getValue().append( mat_vals[7] );
|
||||
mat->getValue().append( mat_vals[11] );
|
||||
mat->getValue().append( mat_vals[15] );
|
||||
|
||||
lastVisited = MATRIX;
|
||||
lastDepth = _nodePath.size();
|
||||
|
||||
traverse( node );
|
||||
}
|
||||
|
||||
//POSATT
|
||||
void daeWriter::apply( osg::PositionAttitudeTransform &node )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
debugPrint( node );
|
||||
#endif
|
||||
|
||||
while ( lastDepth >= _nodePath.size() )
|
||||
{
|
||||
//We are not a child of previous node
|
||||
currentNode = daeSafeCast< domNode >( currentNode->getParentElement() );
|
||||
lastDepth--;
|
||||
}
|
||||
currentNode = daeSafeCast< domNode >(currentNode->createAndPlace( COLLADA_ELEMENT_NODE ) );
|
||||
currentNode->setId(getNodeName(node,"positionAttitudeTransform").c_str());
|
||||
|
||||
const osg::Vec3 &pos = node.getPosition();
|
||||
const osg::Quat &q = node.getAttitude();
|
||||
const osg::Vec3 &s = node.getScale();
|
||||
|
||||
if ( s.x() != 1 || s.y() != 1 || s.z() != 1 )
|
||||
{
|
||||
//make a scale
|
||||
domScale *scale = daeSafeCast< domScale >( currentNode->createAndPlace( COLLADA_ELEMENT_SCALE ) );
|
||||
scale->getValue().append( s.x() );
|
||||
scale->getValue().append( s.y() );
|
||||
scale->getValue().append( s.z() );
|
||||
}
|
||||
|
||||
double angle;
|
||||
osg::Vec3 axis;
|
||||
q.getRotate( angle, axis );
|
||||
if ( angle != 0 )
|
||||
{
|
||||
//make a rotate
|
||||
domRotate *rot = daeSafeCast< domRotate >( currentNode->createAndPlace( COLLADA_ELEMENT_ROTATE ) );
|
||||
rot->getValue().append( axis.x() );
|
||||
rot->getValue().append( axis.y() );
|
||||
rot->getValue().append( axis.z() );
|
||||
rot->getValue().append( angle );
|
||||
}
|
||||
|
||||
if ( pos.x() != 0 || pos.y() != 0 || pos.z() != 0 )
|
||||
{
|
||||
//make a translate
|
||||
domTranslate *trans = daeSafeCast< domTranslate >( currentNode->createAndPlace( COLLADA_ELEMENT_TRANSLATE ) );
|
||||
trans->getValue().append( pos.x() );
|
||||
trans->getValue().append( pos.y() );
|
||||
trans->getValue().append( pos.z() );
|
||||
}
|
||||
|
||||
lastVisited = POSATT;
|
||||
lastDepth = _nodePath.size();
|
||||
|
||||
traverse( node );
|
||||
}
|
||||
|
||||
void daeWriter::apply( osg::Transform &node )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "some other transform type. Missing " << node.getNumChildren() << " children\n";
|
||||
}
|
||||
|
||||
void daeWriter::apply( osg::CoordinateSystemNode &node )
|
||||
{
|
||||
osg::notify( osg::WARN ) << "CoordinateSystemNode. Missing " << node.getNumChildren() << " children\n";
|
||||
}
|
||||
153
src/osgPlugins/dae/daeWriter.cpp
Normal file
153
src/osgPlugins/dae/daeWriter.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include "daeWriter.h"
|
||||
|
||||
#include <dom/domCOLLADA.h>
|
||||
|
||||
#include <dom/domNode.h>
|
||||
#include <dom/domConstants.h>
|
||||
|
||||
using namespace osgdae;
|
||||
|
||||
daeWriter::daeWriter( const std::string &fname,bool _usePolygons ) : osg::NodeVisitor( TRAVERSE_ALL_CHILDREN ),
|
||||
usePolygons (_usePolygons)
|
||||
{
|
||||
success = true;
|
||||
|
||||
dae = new DAE();
|
||||
dae->setDatabase( NULL );
|
||||
dae->setIOPlugin( NULL );
|
||||
//create document
|
||||
dae->getDatabase()->createDocument( fname.c_str(), &doc );
|
||||
dom = (domCOLLADA*)doc->getDomRoot();
|
||||
//create scene and instance visual scene
|
||||
domCOLLADA::domScene *scene = daeSafeCast< domCOLLADA::domScene >( dom->createAndPlace( COLLADA_ELEMENT_SCENE ) );
|
||||
domInstanceWithExtra *ivs = daeSafeCast< domInstanceWithExtra >( scene->createAndPlace( "instance_visual_scene" ) );
|
||||
ivs->setUrl( "#defaultScene" );
|
||||
//create library visual scenes and a visual scene and the root node
|
||||
lib_vis_scenes = daeSafeCast<domLibrary_visual_scenes>( dom->createAndPlace( COLLADA_ELEMENT_LIBRARY_VISUAL_SCENES ) );
|
||||
vs = daeSafeCast< domVisual_scene >( lib_vis_scenes->createAndPlace( COLLADA_ELEMENT_VISUAL_SCENE ) );
|
||||
vs->setId( "defaultScene" );
|
||||
currentNode = daeSafeCast< domNode >( vs->createAndPlace( COLLADA_ELEMENT_NODE ) );
|
||||
currentNode->setId( "sceneRoot" );
|
||||
|
||||
//create Asset
|
||||
createAssetTag();
|
||||
|
||||
lib_cameras = NULL;
|
||||
lib_effects = NULL;
|
||||
lib_geoms = NULL;
|
||||
lib_lights = NULL;
|
||||
lib_mats = NULL;
|
||||
|
||||
lastDepth = 0;
|
||||
}
|
||||
|
||||
daeWriter::~daeWriter()
|
||||
{
|
||||
if ( dae != NULL )
|
||||
{
|
||||
delete dae;
|
||||
DAE::cleanup();
|
||||
dae = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void daeWriter::debugPrint( osg::Node &node )
|
||||
{
|
||||
std::string indent = "";
|
||||
for ( unsigned int i = 0; i < _nodePath.size(); i++ )
|
||||
{
|
||||
indent += " ";
|
||||
}
|
||||
osg::notify( osg::INFO ) << indent << node.className() << std::endl;
|
||||
}
|
||||
|
||||
bool daeWriter::writeFile()
|
||||
{
|
||||
if ( dae->save( (daeUInt)0 ) != DAE_OK )
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
void daeWriter::setRootNode( const osg::Node &node )
|
||||
{
|
||||
std::string fname = osgDB::findDataFile( node.getName() );
|
||||
//rootName = fname.c_str();
|
||||
//rootName.validate();
|
||||
}
|
||||
|
||||
//### provide a name to node
|
||||
std::string daeWriter::getNodeName(const osg::Node & node,const std::string & defaultName)
|
||||
{
|
||||
std::string nodeName;
|
||||
if ((node.getName().empty()) || (node.getName()!=""))
|
||||
nodeName=uniquify(defaultName);
|
||||
else
|
||||
nodeName=node.getName();
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
//NODE
|
||||
void daeWriter::apply( osg::Node &node )
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
debugPrint( node );
|
||||
#endif
|
||||
|
||||
osg::notify( osg::INFO ) << "generic node\n";
|
||||
lastVisited = NODE;
|
||||
|
||||
traverse( node );
|
||||
}
|
||||
|
||||
|
||||
std::string daeWriter::uniquify( const std::string &name )
|
||||
{
|
||||
std::map< std::string, int >::iterator iter = uniqueNames.find( name );
|
||||
if ( iter != uniqueNames.end() )
|
||||
{
|
||||
iter->second++;
|
||||
char str[5];
|
||||
#if 0
|
||||
itoa( iter->second, str, 10 );
|
||||
#else
|
||||
snprintf(str,5,"%d",iter->second);
|
||||
#endif
|
||||
return name + "_" + str;
|
||||
}
|
||||
else
|
||||
{
|
||||
uniqueNames.insert( std::make_pair( name, 0 ) );
|
||||
return name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void daeWriter::createAssetTag()
|
||||
{
|
||||
domAsset *asset = daeSafeCast< domAsset >(dom->createAndPlace( COLLADA_ELEMENT_ASSET ) );
|
||||
domAsset::domCreated *c = daeSafeCast< domAsset::domCreated >( asset->createAndPlace( "created" ) );
|
||||
domAsset::domModified *m = daeSafeCast< domAsset::domModified >( asset->createAndPlace( "modified" ) );
|
||||
domAsset::domUnit *u = daeSafeCast< domAsset::domUnit >( asset->createAndPlace( "unit" ) );
|
||||
|
||||
//TODO : set date and time
|
||||
c->setValue( "2006-07-25T00:00:00Z" );
|
||||
m->setValue( "2006-07-25T00:00:00Z" );
|
||||
|
||||
u->setName( "meter" );
|
||||
u->setMeter( 1 );
|
||||
}
|
||||
221
src/osgPlugins/dae/daeWriter.h
Normal file
221
src/osgPlugins/dae/daeWriter.h
Normal file
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#ifndef _DAE_WRITER_H_
|
||||
#define _DAE_WRITER_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <osg/Node>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Group>
|
||||
#include <osg/LightSource>
|
||||
#include <osg/CameraNode>
|
||||
#include <osg/Material>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
#include <osg/Switch>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/LOD>
|
||||
#include <osg/ProxyNode>
|
||||
#include <osg/CoordinateSystemNode>
|
||||
#include <osg/BlendColor>
|
||||
#include <osg/BlendFunc>
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/Registry>
|
||||
|
||||
#include "daeUtils.h"
|
||||
|
||||
#include <dae.h>
|
||||
#include <dae/daeDocument.h>
|
||||
|
||||
|
||||
class domCOLLADA;
|
||||
class domGeometry;
|
||||
class domInstance_geometry;
|
||||
class domLibrary_cameras;
|
||||
class domLibrary_effects;
|
||||
class domLibrary_geometries;
|
||||
class domLibrary_lights;
|
||||
class domLibrary_materials;
|
||||
class domLibrary_visual_scenes;
|
||||
class domMaterial;
|
||||
class domMesh;
|
||||
class domNode;
|
||||
class domSource;
|
||||
class domVisual_scene;
|
||||
class domP;
|
||||
|
||||
namespace osgdae {
|
||||
|
||||
/**
|
||||
@class daeWriter
|
||||
@brief Write a OSG scene into a DAE file
|
||||
*/
|
||||
class daeWriter : public osg::NodeVisitor
|
||||
{
|
||||
protected:
|
||||
class ArrayNIndices;
|
||||
public:
|
||||
enum NodeType { NODE, GEODE, GROUP, LIGHT, CAMERA, MATRIX, POSATT, SWITCH, LOD };
|
||||
|
||||
daeWriter( const std::string &fname, bool usePolygons=false );
|
||||
virtual ~daeWriter();
|
||||
|
||||
void setRootNode( const osg::Node &node );
|
||||
|
||||
bool isSuccess() { return success; }
|
||||
|
||||
bool writeFile();
|
||||
|
||||
virtual void apply( osg::Node &node );
|
||||
virtual void apply( osg::Geode &node );
|
||||
virtual void apply( osg::Group &node );
|
||||
virtual void apply( osg::LightSource &node );
|
||||
virtual void apply( osg::CameraNode &node );
|
||||
virtual void apply( osg::MatrixTransform &node );
|
||||
virtual void apply( osg::PositionAttitudeTransform &node );
|
||||
virtual void apply( osg::Switch &node );
|
||||
virtual void apply( osg::LOD &node );
|
||||
|
||||
//virtual void apply( osg::Billboard &node);
|
||||
virtual void apply( osg::ProxyNode &node );
|
||||
//virtual void apply( osg::Projection &node)
|
||||
virtual void apply( osg::CoordinateSystemNode &node );
|
||||
//virtual void apply( osg::ClipNode &node)
|
||||
//virtual void apply( osg::TexGenNode &node)
|
||||
virtual void apply( osg::Transform &node );
|
||||
//virtual void apply( osg::CameraView &node)
|
||||
//virtual void apply( osg::Sequence &node)
|
||||
//virtual void apply( osg::PagedLOD &node)
|
||||
//virtual void apply( osg::ClearNode &node)
|
||||
//virtual void apply( osg::OccluderNode &node)
|
||||
|
||||
/*protected:
|
||||
struct MeshData {
|
||||
domMesh *mesh;
|
||||
domSource *pos;
|
||||
domSource *norm;
|
||||
domSource *color;
|
||||
std::vector< domSource * > texcoord;
|
||||
std::string name;
|
||||
};*/
|
||||
|
||||
|
||||
protected: //methods
|
||||
void debugPrint( osg::Node &node );
|
||||
|
||||
|
||||
bool processGeometry( osg::Geometry *geom, domGeometry *geo, const std::string &name );
|
||||
domSource* createSource( daeElement *parent, const std::string &baseName, int size, bool color = false, bool uv = false );
|
||||
template < typename Ty >
|
||||
Ty *createPrimGroup( daeString type, domMesh *mesh, domSource *norm, domSource *color, const std::vector< domSource* > &texcoord );
|
||||
|
||||
void processMaterial( osg::StateSet *ss, domInstance_geometry *ig, const std::string &geoName );
|
||||
|
||||
void createAssetTag();
|
||||
|
||||
protected: //members
|
||||
DAE *dae;
|
||||
daeDocument *doc;
|
||||
domCOLLADA *dom;
|
||||
domLibrary_cameras *lib_cameras;
|
||||
domLibrary_effects *lib_effects;
|
||||
domLibrary_geometries *lib_geoms;
|
||||
domLibrary_lights *lib_lights;
|
||||
domLibrary_materials *lib_mats;
|
||||
domLibrary_visual_scenes *lib_vis_scenes;
|
||||
domNode *currentNode;
|
||||
domVisual_scene *vs;
|
||||
|
||||
bool success;
|
||||
NodeType lastVisited;
|
||||
unsigned int lastDepth;
|
||||
|
||||
std::map< std::string, int > uniqueNames;
|
||||
|
||||
std::map< osg::Geometry*, domGeometry * > geometryMap;
|
||||
std::map< osg::StateSet*, domMaterial * > materialMap;
|
||||
|
||||
daeURI rootName;
|
||||
|
||||
bool usePolygons;
|
||||
|
||||
protected: //inner classes
|
||||
class ArrayNIndices
|
||||
{
|
||||
public:
|
||||
enum Mode { NONE = 0, VEC2 = 2, VEC3 = 3, VEC4 = 4 };
|
||||
osg::Vec2Array *vec2;
|
||||
osg::Vec3Array *vec3;
|
||||
osg::Vec4Array *vec4;
|
||||
osg::IndexArray *inds;
|
||||
Mode mode;
|
||||
|
||||
ArrayNIndices( osg::Array *array, osg::IndexArray *ind ) : vec2(0), vec3(0), vec4(0), inds( ind ), mode(NONE)
|
||||
{
|
||||
if ( array != NULL )
|
||||
{
|
||||
switch( array->getType() )
|
||||
{
|
||||
case osg::Array::Vec2ArrayType:
|
||||
mode = VEC2;
|
||||
vec2 = (osg::Vec2Array*)array;
|
||||
break;
|
||||
case osg::Array::Vec3ArrayType:
|
||||
mode = VEC3;
|
||||
vec3 = (osg::Vec3Array*)array;
|
||||
break;
|
||||
case osg::Array::Vec4ArrayType:
|
||||
mode = VEC4;
|
||||
vec4 = (osg::Vec4Array*)array;
|
||||
break;
|
||||
default:
|
||||
osg::notify( osg::WARN ) << "Array is unsupported vector type" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private: //members
|
||||
|
||||
/** append elements (verts, normals, colors and texcoord) for file write */
|
||||
void appendGeometryIndices(osg::Geometry *geom,
|
||||
domP * p,
|
||||
unsigned int vindex,
|
||||
domSource * norm,
|
||||
domSource * color,
|
||||
const ArrayNIndices & verts,
|
||||
const ArrayNIndices & normals,
|
||||
const ArrayNIndices & colors,
|
||||
const std::vector<ArrayNIndices> & texcoords,
|
||||
unsigned int ncount,
|
||||
unsigned int ccount);
|
||||
|
||||
/** provide a name to node */
|
||||
std::string getNodeName(const osg::Node & node,const std::string & defaultName);
|
||||
|
||||
/** provide an unique name */
|
||||
std::string uniquify( const std::string &name );
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
87
src/osgPlugins/dae/domSourceReader.cpp
Normal file
87
src/osgPlugins/dae/domSourceReader.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#include "domSourceReader.h"
|
||||
|
||||
#include <dom/domSource.h>
|
||||
|
||||
using namespace osgdae;
|
||||
|
||||
domSourceReader::domSourceReader() : m_array_type( None ), m_count( 0 )
|
||||
{}
|
||||
|
||||
domSourceReader::domSourceReader( domSource *src ) : m_array_type( None ), m_count( 0 )
|
||||
{
|
||||
domSource::domTechnique_common* technique = src->getTechnique_common();
|
||||
if ( technique == NULL ) {
|
||||
osg::notify(osg::WARN)<<"Warning: IntDaeSource::createFrom: Unable to find COMMON technique"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
domAccessor* accessor = technique->getAccessor();
|
||||
int stride = accessor->getStride();
|
||||
m_count = accessor->getCount();
|
||||
|
||||
switch ( stride ) {
|
||||
case 1:
|
||||
m_array_type = Float;
|
||||
m_float_array = new osg::FloatArray();
|
||||
break;
|
||||
case 2:
|
||||
m_array_type = Vec2;
|
||||
m_vec2_array = new osg::Vec2Array();
|
||||
break;
|
||||
case 3:
|
||||
m_array_type = Vec3;
|
||||
m_vec3_array = new osg::Vec3Array();
|
||||
break;
|
||||
case 4:
|
||||
m_array_type = Vec4;
|
||||
m_vec4_array = new osg::Vec4Array();
|
||||
break;
|
||||
default:
|
||||
osg::notify(osg::WARN)<<"Unsupported stride: "<<stride<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Only handle floats for now...
|
||||
daeDoubleArray* float_array = NULL;
|
||||
if ( src->getFloat_array() != NULL ) {
|
||||
float_array = &(src->getFloat_array()->getValue());
|
||||
}
|
||||
if ( !float_array ) {
|
||||
osg::notify(osg::WARN)<<"No float array found"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
daeDoubleArray& va = *float_array;
|
||||
for ( size_t i = 0; i < accessor->getCount(); i++ ) {
|
||||
switch ( accessor->getStride() ) {
|
||||
case 1:
|
||||
m_float_array->push_back( va[i] );
|
||||
break;
|
||||
case 2:
|
||||
m_vec2_array->push_back( osg::Vec2( va[i*2], va[i*2+1] ) );
|
||||
break;
|
||||
case 3:
|
||||
m_vec3_array->push_back( osg::Vec3( va[i*3], va[i*3+1], va[i*3+2] ) );
|
||||
break;
|
||||
case 4:
|
||||
m_vec4_array->push_back( osg::Vec4( va[i*4], va[i*4+1], va[i*4+2], va[i*4+3] ) );
|
||||
break;
|
||||
default:
|
||||
osg::notify(osg::WARN)<<"Unsupported stride in Source: "<<accessor->getStride()<<std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
76
src/osgPlugins/dae/domSourceReader.h
Normal file
76
src/osgPlugins/dae/domSourceReader.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
||||
*
|
||||
* Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
|
||||
* file except in compliance with the License. You may obtain a copy of the License at:
|
||||
* http://research.scea.com/scea_shared_source_license.html
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
#ifndef _DOM_SRC_CONV_H_
|
||||
#define _DOM_SRC_CONV_H_
|
||||
|
||||
#include <osg/Array>
|
||||
#include <osg/Notify>
|
||||
|
||||
class domSource;
|
||||
|
||||
namespace osgdae {
|
||||
|
||||
/**
|
||||
@class domSourceReader
|
||||
@brief Convert sources from DAE to OSG arrays
|
||||
*/
|
||||
class domSourceReader
|
||||
{
|
||||
public:
|
||||
enum ArrayType {None,Float,Vec2,Vec3,Vec4};
|
||||
|
||||
public:
|
||||
|
||||
domSourceReader();
|
||||
domSourceReader( domSource *src );
|
||||
|
||||
ArrayType getArrayType() const { return m_array_type; };
|
||||
|
||||
osg::FloatArray* getFloatArray() { return m_float_array.get(); };
|
||||
|
||||
osg::Vec2Array* getVec2Array() { return m_vec2_array.get(); };
|
||||
|
||||
osg::Vec3Array* getVec3Array() { return m_vec3_array.get(); };
|
||||
|
||||
osg::Vec4Array* getVec4Array() { return m_vec4_array.get(); };
|
||||
|
||||
int getCount() const { return m_count; };
|
||||
|
||||
#define ASSERT_TYPE(type) if (type!=m_array_type) { osg::notify(osg::WARN)<<"Wrong array type requested ("#type" != "<<m_array_type<<")"<<std::endl; }
|
||||
|
||||
float getFloat( int index ) { ASSERT_TYPE( Float ); return (*m_float_array)[index]; };
|
||||
|
||||
osg::Vec2 const& getVec2( int index ) { ASSERT_TYPE( Vec2 ); return (*m_vec2_array)[index]; };
|
||||
|
||||
osg::Vec3 const& getVec3( int index ) { ASSERT_TYPE( Vec3 ); return (*m_vec3_array)[index]; };
|
||||
|
||||
osg::Vec4 const& getVec4( int index ) { ASSERT_TYPE( Vec4 ); return (*m_vec4_array)[index]; };
|
||||
|
||||
#undef ASSERT_TYPE
|
||||
|
||||
protected:
|
||||
|
||||
ArrayType m_array_type;
|
||||
int m_count;
|
||||
|
||||
osg::ref_ptr<osg::FloatArray> m_float_array;
|
||||
osg::ref_ptr<osg::Vec2Array> m_vec2_array;
|
||||
osg::ref_ptr<osg::Vec3Array> m_vec3_array;
|
||||
osg::ref_ptr<osg::Vec4Array> m_vec4_array;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
80
src/osgPlugins/dae/scea_shared_source_license.html
Normal file
80
src/osgPlugins/dae/scea_shared_source_license.html
Normal file
@@ -0,0 +1,80 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>SCEA Shared Source License 1.0</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<center><b><font size="5">SCEA Shared Source License 1.0</font></b></center>
|
||||
|
||||
<p>
|
||||
|
||||
<b>Terms and Conditions:</b>
|
||||
</p>
|
||||
<b>1. Definitions:</b>
|
||||
|
||||
<p>
|
||||
"<b>Software</b>" shall mean the software and related documentation, whether in Source or Object Form, made available under this SCEA Shared Source license ("<b>License</b>"), that is indicated by a copyright notice file included in the source files or attached or accompanying the source files.
|
||||
</p>
|
||||
<p>
|
||||
"<b>Licensor</b>" shall mean Sony Computer Entertainment America, Inc. (herein "<b>SCEA</b>")
|
||||
</p>
|
||||
<p>
|
||||
"<b>Object Code</b>" or "<b>Object Form</b>" shall mean any form that results from translation or transformation of Source Code, including but not limited to compiled object code or conversions to other forms intended for machine execution.
|
||||
</p>
|
||||
<p>
|
||||
"<b>Source Code</b>" or "<b>Source Form</b>" shall have the plain meaning generally accepted in the software industry, including but not limited to software source code, documentation source, header and configuration files.
|
||||
</p>
|
||||
<p>
|
||||
"<b>You</b>" or "<b>Your</b>" shall mean you as an individual or as a company, or whichever form under which you are exercising rights under this License.
|
||||
</p>
|
||||
<p><b>2. License Grant.</b></p>
|
||||
|
||||
<p>Licensor hereby grants to You, free of charge subject to the terms and conditions of this License, an irrevocable, non-exclusive, worldwide, perpetual, and royalty-free license to use, modify, reproduce, distribute, publicly perform or display the Software in Object or Source Form .
|
||||
</p>
|
||||
<p><b>3. No Right to File for Patent.</b></p>
|
||||
|
||||
<p>In exchange for the rights that are granted to You free of charge under this License, You agree that You will not file for any patent application, seek copyright protection or take any other action that might otherwise impair the ownership rights in and to the Software that may belong to SCEA or any of the other contributors/authors of the Software.
|
||||
</p>
|
||||
<p><b>4. Contributions.</b></p>
|
||||
|
||||
<p>SCEA welcomes contributions in form of modifications, optimizations, tools or documentation designed to improve or expand the performance and scope of the Software (collectively "<b>Contributions</b>"). Per the terms of this License You are free to modify the Software and those modifications would belong to You. You may however wish to donate Your Contributions to SCEA for consideration for inclusion into the Software. For the avoidance of doubt, if You elect to send Your Contributions to SCEA, You are doing so voluntarily and are giving the Contributions to SCEA and its parent company Sony Computer Entertainment, Inc., free of charge, to use, modify or distribute in any form or in any manner. SCEA acknowledges that if You make a donation of Your Contributions to SCEA, such Contributions shall not exclusively belong to SCEA or its parent company and such donation shall not be to Your exclusion. SCEA, in its sole discretion, shall determine whether or not to include Your donated Contributions into the Software, in whole, in part, or as modified by SCEA. Should SCEA elect to include any such Contributions into the Software, it shall do so at its own risk and may elect to give credit or special thanks to any such contributors in the attached copyright notice. However, if any of Your contributions are included into the Software, they will become part of the Software and will be distributed under the terms and conditions of this License. Further, if Your donated Contributions are integrated into the Software then Sony Computer Entertainment, Inc. shall become the copyright owner of the Software now containing Your contributions and SCEA would be the Licensor.
|
||||
</p>
|
||||
<p><b>5. Redistribution in Source Form</b></p>
|
||||
|
||||
<p>You may redistribute copies of the Software, modifications or derivatives thereof in Source Code Form, provided that You:
|
||||
</p>
|
||||
|
||||
<ul>a. Include a copy of this License and any copyright notices with source</ul>
|
||||
<ul>b. Identify modifications if any were made to the Software</ul>
|
||||
<ul>c. Include a copy of all documentation accompanying the Software and modifications made by You</ul>
|
||||
|
||||
|
||||
<p><b>6. Redistribution in Object Form</b></p>
|
||||
|
||||
<p>If You redistribute copies of the Software, modifications or derivatives thereof in Object Form only (as incorporated into finished goods, i.e. end user applications) then You will not have a duty to include any copies of the code, this License, copyright notices, other attributions or documentation.
|
||||
</p>
|
||||
<p><b>7. No Warranty</b></p>
|
||||
|
||||
<p>THE SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT ANY REPRESENTATIONS OR WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. YOU ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING, MODIFYING OR REDISTRIBUTING THE SOFTWARE AND ASSUME ANY RISKS ASSOCIATED WITH YOUR EXERCISE OF PERMISSIONS UNDER THIS LICENSE.
|
||||
</p>
|
||||
<p><b>8. Limitation of Liability</b></p>
|
||||
|
||||
<p>UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY WILL EITHER PARTY BE LIABLE TO THE OTHER PARTY OR ANY THIRD PARTY FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL, INCIDENTAL, OR EXEMPLARY DAMAGES WITH RESPECT TO ANY INJURY, LOSS, OR DAMAGE, ARISING UNDER OR IN CONNECTION WITH THIS LETTER AGREEMENT, WHETHER FORESEEABLE OR UNFORESEEABLE, EVEN IF SUCH PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH INJURY, LOSS, OR DAMAGE. THE LIMITATIONS OF LIABILITY SET FORTH IN THIS SECTION SHALL APPLY TO THE FULLEST EXTENT PERMISSIBLE AT LAW OR ANY GOVERMENTAL REGULATIONS.
|
||||
</p>
|
||||
<p><b>9. Governing Law and Consent to Jurisdiction</b></p>
|
||||
|
||||
<p>This Agreement shall be governed by and interpreted in accordance with the laws of the State of California, excluding that body of law related to choice of laws, and of the United States of America. Any action or proceeding brought to enforce the terms of this Agreement or to adjudicate any dispute arising hereunder shall be brought in the Superior Court of the County of San Mateo, State of California or the United States District Court for the Northern District of California. Each of the parties hereby submits itself to the exclusive jurisdiction and venue of such courts for purposes of any such action. In addition, each party hereby waives the right to a jury trial in any action or proceeding related to this Agreement.
|
||||
</p>
|
||||
<p><b>10. Copyright Notice for Redistribution of Source Code</b></p>
|
||||
|
||||
<p>Copyright 2005 Sony Computer Entertainment Inc.
|
||||
</p>
|
||||
<p>Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:
|
||||
</p>
|
||||
<a href=http://research.scea.com/scea_shared_source_license.html/>http://research.scea.com/scea_shared_source_license.html</a>
|
||||
<p>Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user