Torque3D Documentation / _generateds / colladaAppMaterial.h

colladaAppMaterial.h

Engine/source/ts/collada/colladaAppMaterial.h

More...

Classes:

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _COLLADA_APP_MATERIAL_H_
25#define _COLLADA_APP_MATERIAL_H_
26
27#ifndef _APPMATERIAL_H_
28#include "ts/loader/appMaterial.h"
29#endif
30#ifndef _COLLADA_EXTENSIONS_H_
31#include "ts/collada/colladaExtensions.h"
32#endif
33
34class Material;
35
36class ColladaAppMaterial : public AppMaterial
37{
38public:
39   const domMaterial*         mat;              ///< Collada <material> element
40   domEffect*                 effect;           ///< Collada <effect> element
41   ColladaExtension_effect*   effectExt;        ///< effect extension
42   String                     name;             ///< Name of this material (cleaned)
43
44   // Settings extracted from the Collada file, and optionally saved to materials.tscript
45   String                     diffuseMap;
46   String                     normalMap;
47
48   LinearColorF               diffuseColor;
49   F32                        roughness;
50   F32                        metalness;
51   bool                       doubleSided;
52
53   ColladaAppMaterial(const char* matName);
54   ColladaAppMaterial(const domMaterial* pMat);
55   ~ColladaAppMaterial() { delete effectExt; }
56
57   String getName() const { return name; }
58
59   void resolveFloat(const domCommon_float_or_param_type* value, F32* dst);
60   void resolveColor(const domCommon_color_or_texture_type* value, LinearColorF* dst);
61
62   // Determine the material transparency
63   template<class T> void resolveTransparency(const T shader, F32* dst)
64   {
65      // Start out by getting the <transparency> value
66      *dst = 1.0f;
67      resolveFloat(shader->getTransparency(), dst);
68
69      // Multiply the transparency by the transparent color
70      LinearColorF transColor(1.0f, 1.0f, 1.0f, 1.0f);
71      if (shader->getTransparent() && shader->getTransparent()->getColor()) {
72         const domCommon_color_or_texture_type::domColor* color = shader->getTransparent()->getColor();
73         transColor.set(color->getValue()[0], color->getValue()[1], color->getValue()[2], color->getValue()[3]);
74      }
75
76      if (!shader->getTransparent() || (shader->getTransparent()->getOpaque() == FX_OPAQUE_ENUM_A_ONE)) {
77         // multiply by alpha value and invert (so 1.0 is fully opaque)
78         *dst = 1.0f - (*dst * transColor.alpha);
79      }
80      else {
81         // multiply by average of the RGB values
82         F32 avg = (transColor.red + transColor.blue + transColor.green) / 3;
83         *dst *= avg;
84      }
85   }
86
87   Material *createMaterial(const Torque::Path& path) const;
88};
89
90#endif // _COLLADA_APP_MATERIAL_H_
91