123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- /*
- Open Asset Import Library (assimp)
- ----------------------------------------------------------------------
- Copyright (c) 2006-2016, assimp team
- All rights reserved.
- Redistribution and use of this software in source and binary forms,
- with or without modification, are permitted provided that the
- following conditions are met:
- * Redistributions of source code must retain the above
- copyright notice, this list of conditions and the
- following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the
- following disclaimer in the documentation and/or other
- materials provided with the distribution.
- * Neither the name of the assimp team, nor the names of its
- contributors may be used to endorse or promote products
- derived from this software without specific prior
- written permission of the assimp team.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ----------------------------------------------------------------------
- */
- /// \file X3DImporter_Light.cpp
- /// \brief Parsing data from nodes of "Lighting" set of X3D.
- /// \date 2015-2016
- /// \author [email protected]
- #ifndef ASSIMP_BUILD_NO_X3D_IMPORTER
- #include "X3DImporter.hpp"
- #include "X3DImporter_Macro.hpp"
- #include "StringUtils.h"
- namespace Assimp {
- // <DirectionalLight
- // DEF="" ID
- // USE="" IDREF
- // ambientIntensity="0" SFFloat [inputOutput]
- // color="1 1 1" SFColor [inputOutput]
- // direction="0 0 -1" SFVec3f [inputOutput]
- // global="false" SFBool [inputOutput]
- // intensity="1" SFFloat [inputOutput]
- // on="true" SFBool [inputOutput]
- // />
- void X3DImporter::ParseNode_Lighting_DirectionalLight()
- {
- std::string def, use;
- float ambientIntensity = 0;
- aiColor3D color(1, 1, 1);
- aiVector3D direction(0, 0, -1);
- bool global = false;
- float intensity = 1;
- bool on = true;
- CX3DImporter_NodeElement* ne( nullptr );
- MACRO_ATTRREAD_LOOPBEG;
- MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
- MACRO_ATTRREAD_CHECK_RET("ambientIntensity", ambientIntensity, XML_ReadNode_GetAttrVal_AsFloat);
- MACRO_ATTRREAD_CHECK_REF("color", color, XML_ReadNode_GetAttrVal_AsCol3f);
- MACRO_ATTRREAD_CHECK_REF("direction", direction, XML_ReadNode_GetAttrVal_AsVec3f);
- MACRO_ATTRREAD_CHECK_RET("global", global, XML_ReadNode_GetAttrVal_AsBool);
- MACRO_ATTRREAD_CHECK_RET("intensity", intensity, XML_ReadNode_GetAttrVal_AsFloat);
- MACRO_ATTRREAD_CHECK_RET("on", on, XML_ReadNode_GetAttrVal_AsBool);
- MACRO_ATTRREAD_LOOPEND;
- // if "USE" defined then find already defined element.
- if(!use.empty())
- {
- MACRO_USE_CHECKANDAPPLY(def, use, ENET_DirectionalLight, ne);
- }
- else
- {
- if(on)
- {
- // create and if needed - define new geometry object.
- ne = new CX3DImporter_NodeElement_Light(CX3DImporter_NodeElement::ENET_DirectionalLight, NodeElement_Cur);
- if(!def.empty())
- ne->ID = def;
- else
- ne->ID = "DirectionalLight_" + to_string((size_t)ne);// make random name
- ((CX3DImporter_NodeElement_Light*)ne)->AmbientIntensity = ambientIntensity;
- ((CX3DImporter_NodeElement_Light*)ne)->Color = color;
- ((CX3DImporter_NodeElement_Light*)ne)->Direction = direction;
- ((CX3DImporter_NodeElement_Light*)ne)->Global = global;
- ((CX3DImporter_NodeElement_Light*)ne)->Intensity = intensity;
- // Assimp want a node with name similar to a light. "Why? I don't no." )
- ParseHelper_Group_Begin(false);
- NodeElement_Cur->ID = ne->ID;// assign name to node and return to light element.
- ParseHelper_Node_Exit();
- // check for child nodes
- if(!mReader->isEmptyElement())
- ParseNode_Metadata(ne, "DirectionalLight");
- else
- NodeElement_Cur->Child.push_back(ne);// add made object as child to current element
- NodeElement_List.push_back(ne);// add element to node element list because its a new object in graph
- }// if(on)
- }// if(!use.empty()) else
- }
- // <PointLight
- // DEF="" ID
- // USE="" IDREF
- // ambientIntensity="0" SFFloat [inputOutput]
- // attenuation="1 0 0" SFVec3f [inputOutput]
- // color="1 1 1" SFColor [inputOutput]
- // global="true" SFBool [inputOutput]
- // intensity="1" SFFloat [inputOutput]
- // location="0 0 0" SFVec3f [inputOutput]
- // on="true" SFBool [inputOutput]
- // radius="100" SFFloat [inputOutput]
- // />
- void X3DImporter::ParseNode_Lighting_PointLight()
- {
- std::string def, use;
- float ambientIntensity = 0;
- aiVector3D attenuation( 1, 0, 0 );
- aiColor3D color( 1, 1, 1 );
- bool global = true;
- float intensity = 1;
- aiVector3D location( 0, 0, 0 );
- bool on = true;
- float radius = 100;
- CX3DImporter_NodeElement* ne( nullptr );
- MACRO_ATTRREAD_LOOPBEG;
- MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
- MACRO_ATTRREAD_CHECK_RET("ambientIntensity", ambientIntensity, XML_ReadNode_GetAttrVal_AsFloat);
- MACRO_ATTRREAD_CHECK_REF("attenuation", attenuation, XML_ReadNode_GetAttrVal_AsVec3f);
- MACRO_ATTRREAD_CHECK_REF("color", color, XML_ReadNode_GetAttrVal_AsCol3f);
- MACRO_ATTRREAD_CHECK_RET("global", global, XML_ReadNode_GetAttrVal_AsBool);
- MACRO_ATTRREAD_CHECK_RET("intensity", intensity, XML_ReadNode_GetAttrVal_AsFloat);
- MACRO_ATTRREAD_CHECK_REF("location", location, XML_ReadNode_GetAttrVal_AsVec3f);
- MACRO_ATTRREAD_CHECK_RET("on", on, XML_ReadNode_GetAttrVal_AsBool);
- MACRO_ATTRREAD_CHECK_RET("radius", radius, XML_ReadNode_GetAttrVal_AsFloat);
- MACRO_ATTRREAD_LOOPEND;
- // if "USE" defined then find already defined element.
- if(!use.empty())
- {
- MACRO_USE_CHECKANDAPPLY(def, use, ENET_PointLight, ne);
- }
- else
- {
- if(on)
- {
- // create and if needed - define new geometry object.
- ne = new CX3DImporter_NodeElement_Light(CX3DImporter_NodeElement::ENET_PointLight, NodeElement_Cur);
- if(!def.empty()) ne->ID = def;
- ((CX3DImporter_NodeElement_Light*)ne)->AmbientIntensity = ambientIntensity;
- ((CX3DImporter_NodeElement_Light*)ne)->Attenuation = attenuation;
- ((CX3DImporter_NodeElement_Light*)ne)->Color = color;
- ((CX3DImporter_NodeElement_Light*)ne)->Global = global;
- ((CX3DImporter_NodeElement_Light*)ne)->Intensity = intensity;
- ((CX3DImporter_NodeElement_Light*)ne)->Location = location;
- ((CX3DImporter_NodeElement_Light*)ne)->Radius = radius;
- // Assimp want a node with name similar to a light. "Why? I don't no." )
- ParseHelper_Group_Begin(false);
- // make random name
- if(ne->ID.empty()) ne->ID = "PointLight_" + to_string((size_t)ne);
- NodeElement_Cur->ID = ne->ID;// assign name to node and return to light element.
- ParseHelper_Node_Exit();
- // check for child nodes
- if(!mReader->isEmptyElement())
- ParseNode_Metadata(ne, "PointLight");
- else
- NodeElement_Cur->Child.push_back(ne);// add made object as child to current element
- NodeElement_List.push_back(ne);// add element to node element list because its a new object in graph
- }// if(on)
- }// if(!use.empty()) else
- }
- // <SpotLight
- // DEF="" ID
- // USE="" IDREF
- // ambientIntensity="0" SFFloat [inputOutput]
- // attenuation="1 0 0" SFVec3f [inputOutput]
- // beamWidth="0.7854" SFFloat [inputOutput]
- // color="1 1 1" SFColor [inputOutput]
- // cutOffAngle="1.570796" SFFloat [inputOutput]
- // direction="0 0 -1" SFVec3f [inputOutput]
- // global="true" SFBool [inputOutput]
- // intensity="1" SFFloat [inputOutput]
- // location="0 0 0" SFVec3f [inputOutput]
- // on="true" SFBool [inputOutput]
- // radius="100" SFFloat [inputOutput]
- // />
- void X3DImporter::ParseNode_Lighting_SpotLight()
- {
- std::string def, use;
- float ambientIntensity = 0;
- aiVector3D attenuation( 1, 0, 0 );
- float beamWidth = 0.7854f;
- aiColor3D color( 1, 1, 1 );
- float cutOffAngle = 1.570796f;
- aiVector3D direction( 0, 0, -1 );
- bool global = true;
- float intensity = 1;
- aiVector3D location( 0, 0, 0 );
- bool on = true;
- float radius = 100;
- CX3DImporter_NodeElement* ne( nullptr );
- MACRO_ATTRREAD_LOOPBEG;
- MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
- MACRO_ATTRREAD_CHECK_RET("ambientIntensity", ambientIntensity, XML_ReadNode_GetAttrVal_AsFloat);
- MACRO_ATTRREAD_CHECK_REF("attenuation", attenuation, XML_ReadNode_GetAttrVal_AsVec3f);
- MACRO_ATTRREAD_CHECK_RET("beamWidth", beamWidth, XML_ReadNode_GetAttrVal_AsFloat);
- MACRO_ATTRREAD_CHECK_REF("color", color, XML_ReadNode_GetAttrVal_AsCol3f);
- MACRO_ATTRREAD_CHECK_RET("cutOffAngle", cutOffAngle, XML_ReadNode_GetAttrVal_AsFloat);
- MACRO_ATTRREAD_CHECK_REF("direction", direction, XML_ReadNode_GetAttrVal_AsVec3f);
- MACRO_ATTRREAD_CHECK_RET("global", global, XML_ReadNode_GetAttrVal_AsBool);
- MACRO_ATTRREAD_CHECK_RET("intensity", intensity, XML_ReadNode_GetAttrVal_AsFloat);
- MACRO_ATTRREAD_CHECK_REF("location", location, XML_ReadNode_GetAttrVal_AsVec3f);
- MACRO_ATTRREAD_CHECK_RET("on", on, XML_ReadNode_GetAttrVal_AsBool);
- MACRO_ATTRREAD_CHECK_RET("radius", radius, XML_ReadNode_GetAttrVal_AsFloat);
- MACRO_ATTRREAD_LOOPEND;
- // if "USE" defined then find already defined element.
- if(!use.empty())
- {
- MACRO_USE_CHECKANDAPPLY(def, use, ENET_SpotLight, ne);
- }
- else
- {
- if(on)
- {
- // create and if needed - define new geometry object.
- ne = new CX3DImporter_NodeElement_Light(CX3DImporter_NodeElement::ENET_SpotLight, NodeElement_Cur);
- if(!def.empty()) ne->ID = def;
- if(beamWidth > cutOffAngle) beamWidth = cutOffAngle;
- ((CX3DImporter_NodeElement_Light*)ne)->AmbientIntensity = ambientIntensity;
- ((CX3DImporter_NodeElement_Light*)ne)->Attenuation = attenuation;
- ((CX3DImporter_NodeElement_Light*)ne)->BeamWidth = beamWidth;
- ((CX3DImporter_NodeElement_Light*)ne)->Color = color;
- ((CX3DImporter_NodeElement_Light*)ne)->CutOffAngle = cutOffAngle;
- ((CX3DImporter_NodeElement_Light*)ne)->Direction = direction;
- ((CX3DImporter_NodeElement_Light*)ne)->Global = global;
- ((CX3DImporter_NodeElement_Light*)ne)->Intensity = intensity;
- ((CX3DImporter_NodeElement_Light*)ne)->Location = location;
- ((CX3DImporter_NodeElement_Light*)ne)->Radius = radius;
- // Assimp want a node with name similar to a light. "Why? I don't no." )
- ParseHelper_Group_Begin(false);
- // make random name
- if(ne->ID.empty()) ne->ID = "SpotLight_" + to_string((size_t)ne);
- NodeElement_Cur->ID = ne->ID;// assign name to node and return to light element.
- ParseHelper_Node_Exit();
- // check for child nodes
- if(!mReader->isEmptyElement())
- ParseNode_Metadata(ne, "SpotLight");
- else
- NodeElement_Cur->Child.push_back(ne);// add made object as child to current element
- NodeElement_List.push_back(ne);// add element to node element list because its a new object in graph
- }// if(on)
- }// if(!use.empty()) else
- }
- }// namespace Assimp
- #endif // !ASSIMP_BUILD_NO_X3D_IMPORTER
|