vrshoot

diff libs/assimp/LWSLoader.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/assimp/LWSLoader.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,242 @@
     1.4 +/*
     1.5 +Open Asset Import Library (assimp)
     1.6 +----------------------------------------------------------------------
     1.7 +
     1.8 +Copyright (c) 2006-2012, assimp team
     1.9 +All rights reserved.
    1.10 +
    1.11 +Redistribution and use of this software in source and binary forms, 
    1.12 +with or without modification, are permitted provided that the 
    1.13 +following conditions are met:
    1.14 +
    1.15 +* Redistributions of source code must retain the above
    1.16 +  copyright notice, this list of conditions and the
    1.17 +  following disclaimer.
    1.18 +
    1.19 +* Redistributions in binary form must reproduce the above
    1.20 +  copyright notice, this list of conditions and the
    1.21 +  following disclaimer in the documentation and/or other
    1.22 +  materials provided with the distribution.
    1.23 +
    1.24 +* Neither the name of the assimp team, nor the names of its
    1.25 +  contributors may be used to endorse or promote products
    1.26 +  derived from this software without specific prior
    1.27 +  written permission of the assimp team.
    1.28 +
    1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
    1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.40 +
    1.41 +----------------------------------------------------------------------
    1.42 +*/
    1.43 +
    1.44 +/** @file  LWSLoader.h
    1.45 + *  @brief Declaration of the LightWave scene importer class. 
    1.46 + */
    1.47 +#ifndef AI_LWSLOADER_H_INCLUDED
    1.48 +#define AI_LWSLOADER_H_INCLUDED
    1.49 +
    1.50 +#include "LWOFileData.h"
    1.51 +#include "SceneCombiner.h"
    1.52 +
    1.53 +namespace Assimp	{
    1.54 +	namespace LWS	{
    1.55 +
    1.56 +// ---------------------------------------------------------------------------
    1.57 +/** Represents an element in a LWS file.
    1.58 + *
    1.59 + *  This can either be a single data line - <name> <value> or a data
    1.60 + *  group - { name <data_line0> ... n }
    1.61 + */
    1.62 +class Element
    1.63 +{
    1.64 +public:
    1.65 +	Element()
    1.66 +	{}
    1.67 +
    1.68 +	// first: name, second: rest
    1.69 +	std::string tokens[2];
    1.70 +	std::list<Element> children;
    1.71 +
    1.72 +	//! Recursive parsing function
    1.73 +	void Parse (const char*& buffer);
    1.74 +};
    1.75 +
    1.76 +#define AI_LWS_MASK (0xffffffff >> 4u)
    1.77 +
    1.78 +// ---------------------------------------------------------------------------
    1.79 +/** Represents a LWS scenegraph element
    1.80 + */
    1.81 +struct NodeDesc
    1.82 +{
    1.83 +	NodeDesc()
    1.84 +		:	number	(0)
    1.85 +		,	parent	(0)
    1.86 +		,	name	("")
    1.87 +		,	isPivotSet (false)
    1.88 +		,	lightColor (1.f,1.f,1.f)
    1.89 +		,	lightIntensity (1.f)
    1.90 +		,	lightType (0)
    1.91 +		,	lightFalloffType (0)
    1.92 +		,	lightConeAngle (45.f)
    1.93 +		,	parent_resolved (NULL)
    1.94 +	{}
    1.95 +
    1.96 +	enum {
    1.97 +	
    1.98 +		OBJECT = 1,
    1.99 +		LIGHT  = 2,
   1.100 +		CAMERA = 3,
   1.101 +		BONE   = 4
   1.102 +	} type; // type of node
   1.103 +
   1.104 +	// if object: path
   1.105 +	std::string path;
   1.106 +	unsigned int id;
   1.107 +
   1.108 +	// number of object
   1.109 +	unsigned int number;
   1.110 +
   1.111 +	// index of parent index
   1.112 +	unsigned int parent;
   1.113 +
   1.114 +	// lights & cameras & dummies: name
   1.115 +	const char* name;
   1.116 +
   1.117 +	// animation channels
   1.118 +	std::list< LWO::Envelope > channels;
   1.119 +
   1.120 +	// position of pivot point
   1.121 +	aiVector3D pivotPos;
   1.122 +	bool isPivotSet;
   1.123 +
   1.124 +
   1.125 +
   1.126 +	// color of light source
   1.127 +	aiColor3D lightColor;
   1.128 +
   1.129 +	// intensity of light source
   1.130 +	float lightIntensity;
   1.131 +
   1.132 +	// type of light source
   1.133 +	unsigned int lightType;
   1.134 +
   1.135 +	// falloff type of light source
   1.136 +	unsigned int lightFalloffType;
   1.137 +
   1.138 +	// cone angle of (spot) light source
   1.139 +	float lightConeAngle;
   1.140 +
   1.141 +	// soft cone angle of (spot) light source
   1.142 +	float lightEdgeAngle;
   1.143 +
   1.144 +
   1.145 +
   1.146 +	// list of resolved children
   1.147 +	std::list< NodeDesc* > children;
   1.148 +
   1.149 +	// resolved parent node
   1.150 +	NodeDesc* parent_resolved;
   1.151 +
   1.152 +
   1.153 +	// for std::find()
   1.154 +	bool operator == (unsigned int num)  const {
   1.155 +		if (!num)
   1.156 +			return false;
   1.157 +		unsigned int _type = num >> 28u;
   1.158 +		
   1.159 +		return _type == static_cast<unsigned int>(type) && (num & AI_LWS_MASK) == number;
   1.160 +	}
   1.161 +};
   1.162 +
   1.163 +} // end namespace LWS
   1.164 +
   1.165 +// ---------------------------------------------------------------------------
   1.166 +/** LWS (LightWave Scene Format) importer class.
   1.167 + *
   1.168 + *  This class does heavily depend on the LWO importer class. LWS files
   1.169 + *  contain mainly descriptions how LWO objects are composed together
   1.170 + *  in a scene. 
   1.171 +*/
   1.172 +class LWSImporter : public BaseImporter
   1.173 +{
   1.174 +public:
   1.175 +	LWSImporter();
   1.176 +	~LWSImporter();
   1.177 +
   1.178 +
   1.179 +public:
   1.180 +
   1.181 +	// -------------------------------------------------------------------
   1.182 +	// Check whether we can read a specific file
   1.183 +	bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
   1.184 +		bool checkSig) const;
   1.185 +
   1.186 +protected:
   1.187 +
   1.188 +	// -------------------------------------------------------------------
   1.189 +	// Get list of supported extensions
   1.190 +	const aiImporterDesc* GetInfo () const;
   1.191 +
   1.192 +	// -------------------------------------------------------------------
   1.193 +	// Import file into given scene data structure
   1.194 +	void InternReadFile( const std::string& pFile, aiScene* pScene, 
   1.195 +		IOSystem* pIOHandler);
   1.196 +
   1.197 +	// -------------------------------------------------------------------
   1.198 +	// Setup import properties
   1.199 +	void SetupProperties(const Importer* pImp);
   1.200 +
   1.201 +private:
   1.202 +
   1.203 +
   1.204 +	// -------------------------------------------------------------------
   1.205 +	// Read an envelope description
   1.206 +	void ReadEnvelope(const LWS::Element& dad, LWO::Envelope& out );
   1.207 +
   1.208 +	// -------------------------------------------------------------------
   1.209 +	// Read an envelope description for the older LW file format
   1.210 +	void ReadEnvelope_Old(std::list< LWS::Element >::const_iterator& it, 
   1.211 +		const std::list< LWS::Element >::const_iterator& end,
   1.212 +		LWS::NodeDesc& nodes,
   1.213 +		unsigned int version);
   1.214 +
   1.215 +	// -------------------------------------------------------------------
   1.216 +	// Setup a nice name for a node 
   1.217 +	void SetupNodeName(aiNode* nd, LWS::NodeDesc& src);
   1.218 +
   1.219 +	// -------------------------------------------------------------------
   1.220 +	// Recursively build the scenegraph
   1.221 +	void BuildGraph(aiNode* nd, 
   1.222 +		LWS::NodeDesc& src, 
   1.223 +		std::vector<AttachmentInfo>& attach,
   1.224 +		BatchLoader& batch,
   1.225 +		aiCamera**& camOut,
   1.226 +		aiLight**& lightOut, 
   1.227 +		std::vector<aiNodeAnim*>& animOut);
   1.228 +
   1.229 +	// -------------------------------------------------------------------
   1.230 +	// Try several dirs until we find the right location of a LWS file.
   1.231 +	std::string FindLWOFile(const std::string& in);
   1.232 +
   1.233 +private:
   1.234 +
   1.235 +	bool configSpeedFlag;
   1.236 +	IOSystem* io;
   1.237 +
   1.238 +	double first,last,fps;
   1.239 +
   1.240 +	bool noSkeletonMesh; 
   1.241 +};
   1.242 +
   1.243 +} // end of namespace Assimp
   1.244 +
   1.245 +#endif // AI_LWSIMPORTER_H_INC