~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to COLLADAMax/src/COLLADAMaxMaterialExporter.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008-2009 NetAllied Systems GmbH
 
3
 
 
4
        This file is part of COLLADAMax.
 
5
 
 
6
    Portions of the code are:
 
7
    Copyright (c) 2005-2007 Feeling Software Inc.
 
8
    Copyright (c) 2005-2007 Sony Computer Entertainment America
 
9
    
 
10
    Based on the 3dsMax COLLADASW Tools:
 
11
    Copyright (c) 2005-2006 Autodesk Media Entertainment
 
12
        
 
13
    Licensed under the MIT Open Source License, 
 
14
    for details please see LICENSE file or the website
 
15
    http://www.opensource.org/licenses/mit-license.php
 
16
*/
 
17
 
 
18
 
 
19
#include "COLLADAMaxStableHeaders.h"
 
20
 
 
21
#include "COLLADAMaxMaterialExporter.h"
 
22
#include "COLLADASWNode.h"
 
23
 
 
24
#include "COLLADAMaxExportSceneGraph.h"
 
25
 
 
26
#include <iparamm2.h>
 
27
 
 
28
namespace COLLADAMax
 
29
{
 
30
 
 
31
 
 
32
    // The information from this file comes from the MaxSDK sample: /material/multi.cpp.
 
33
 
 
34
    namespace MultiMaterial
 
35
    {
 
36
        const Class_ID classID ( MULTI_CLASS_ID, 0 );
 
37
        // Reference #s.
 
38
        const unsigned int PBLOCK_REF = 0;
 
39
        const unsigned int MTL_REF = 1;
 
40
 
 
41
        // multi_params param IDs
 
42
        enum
 
43
        {
 
44
            multi_mtls,
 
45
            multi_ons,
 
46
            multi_names,
 
47
            multi_ids,
 
48
        };
 
49
    };
 
50
 
 
51
 
 
52
    //---------------------------------------------------------------
 
53
    MaterialExporter::MaterialExporter ( COLLADASW::StreamWriter * streamWriter, DocumentExporter * documentExporter )
 
54
            : COLLADASW::LibraryMaterials ( streamWriter ),
 
55
            mDocumentExporter ( documentExporter )
 
56
    {}
 
57
 
 
58
 
 
59
    //---------------------------------------------------------------
 
60
    void MaterialExporter::doExport()
 
61
    {
 
62
 
 
63
        // set mWireFrameColorEffectList
 
64
        mWireFrameColorEffectList = & ( mDocumentExporter->getEffectExporter() ->getWireFrameColorEffectMap() );
 
65
 
 
66
        // export all wire frame color materials
 
67
 
 
68
        for ( WireFrameColorEffectList::const_iterator it = mWireFrameColorEffectList->begin(); it != mWireFrameColorEffectList->end(); ++it )
 
69
        {
 
70
            const String & effectURL = EffectExporter::getEffectId ( *it );
 
71
            String materialId = getMaterialIdFromEffectId ( effectURL );
 
72
 
 
73
            openMaterial ( materialId, materialId );
 
74
            addInstanceEffect ( "#" + effectURL );
 
75
            closeMaterial ();
 
76
        }
 
77
 
 
78
        // export all ordinary materials
 
79
 
 
80
        for ( ExportedEffectIdAndNameList::const_iterator it = mExportedEffectIdAndNameList.begin(); it != mExportedEffectIdAndNameList.end(); ++it )
 
81
        {
 
82
                        const EffectIdAndName & effectIdAndName= *it;
 
83
                        const String & effectURL = effectIdAndName.effectId;
 
84
            String materialId = getMaterialIdFromEffectId ( effectURL );
 
85
 
 
86
                        const String & effectName = effectIdAndName.effectName;
 
87
                        openMaterial ( materialId, COLLADABU::Utils::checkNCName(effectName) );
 
88
            addInstanceEffect ( "#" + effectURL );
 
89
            closeMaterial ();
 
90
        }
 
91
 
 
92
        closeLibrary();
 
93
    }
 
94
 
 
95
 
 
96
    //---------------------------------------------------------------
 
97
    String MaterialExporter::getMaterialIdFromEffectId ( const String & effectId )
 
98
    {
 
99
        return effectId + MATERIAL_ID_SUFFIX;
 
100
    }
 
101
 
 
102
 
 
103
    //---------------------------------------------------------------
 
104
    Mtl* MaterialExporter::GetSubMaterialById ( Mtl* mtl, int materialId )
 
105
    {
 
106
        if ( !mtl->IsMultiMtl() )
 
107
            return 0;
 
108
 
 
109
        IParamBlock2* subMaterialParameters = ( IParamBlock2* ) mtl->GetReference ( MultiMaterial::PBLOCK_REF );
 
110
 
 
111
        if ( !subMaterialParameters )
 
112
            return mtl->GetSubMtl ( materialId );
 
113
 
 
114
        // check if we ever reach this point
 
115
        assert ( false );
 
116
 
 
117
        int subMaterialCount = mtl->NumSubMtls();
 
118
 
 
119
        for ( int subMaterialIndex = 0; subMaterialIndex < subMaterialCount; ++subMaterialIndex )
 
120
        {
 
121
            int subMatId = subMaterialParameters->GetInt ( MultiMaterial::multi_ids,0 , subMaterialIndex );
 
122
 
 
123
            if ( subMatId == materialId )
 
124
            {
 
125
                Mtl * material = mtl->GetSubMtl ( subMaterialIndex );
 
126
 
 
127
                if ( material )
 
128
                    return material;
 
129
            }
 
130
        }
 
131
 
 
132
        return 0;
 
133
    }
 
134
 
 
135
}