vrshoot
diff libs/assimp/ColladaHelper.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/ColladaHelper.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,602 @@ 1.4 +/** Helper structures for the Collada loader */ 1.5 + 1.6 +/* 1.7 +Open Asset Import Library (assimp) 1.8 +---------------------------------------------------------------------- 1.9 + 1.10 +Copyright (c) 2006-2012, assimp team 1.11 +All rights reserved. 1.12 + 1.13 +Redistribution and use of this software in source and binary forms, 1.14 +with or without modification, are permitted provided that the 1.15 +following conditions are met: 1.16 + 1.17 +* Redistributions of source code must retain the above 1.18 +copyright notice, this list of conditions and the 1.19 +following disclaimer. 1.20 + 1.21 +* Redistributions in binary form must reproduce the above 1.22 +copyright notice, this list of conditions and the 1.23 +following disclaimer in the documentation and/or other 1.24 +materials provided with the distribution. 1.25 + 1.26 +* Neither the name of the assimp team, nor the names of its 1.27 +contributors may be used to endorse or promote products 1.28 +derived from this software without specific prior 1.29 +written permission of the assimp team. 1.30 + 1.31 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.32 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.33 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.34 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.35 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.36 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.37 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.38 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.39 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.40 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.41 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.42 + 1.43 +---------------------------------------------------------------------- 1.44 +*/ 1.45 + 1.46 +#ifndef AI_COLLADAHELPER_H_INC 1.47 +#define AI_COLLADAHELPER_H_INC 1.48 + 1.49 +namespace Assimp { 1.50 +namespace Collada { 1.51 + 1.52 +/** Collada file versions which evolved during the years ... */ 1.53 +enum FormatVersion 1.54 +{ 1.55 + FV_1_5_n, 1.56 + FV_1_4_n, 1.57 + FV_1_3_n 1.58 +}; 1.59 + 1.60 + 1.61 +/** Transformation types that can be applied to a node */ 1.62 +enum TransformType 1.63 +{ 1.64 + TF_LOOKAT, 1.65 + TF_ROTATE, 1.66 + TF_TRANSLATE, 1.67 + TF_SCALE, 1.68 + TF_SKEW, 1.69 + TF_MATRIX 1.70 +}; 1.71 + 1.72 +/** Different types of input data to a vertex or face */ 1.73 +enum InputType 1.74 +{ 1.75 + IT_Invalid, 1.76 + IT_Vertex, // special type for per-index data referring to the <vertices> element carrying the per-vertex data. 1.77 + IT_Position, 1.78 + IT_Normal, 1.79 + IT_Texcoord, 1.80 + IT_Color, 1.81 + IT_Tangent, 1.82 + IT_Bitangent 1.83 +}; 1.84 + 1.85 +/** Contains all data for one of the different transformation types */ 1.86 +struct Transform 1.87 +{ 1.88 + std::string mID; ///< SID of the transform step, by which anim channels address their target node 1.89 + TransformType mType; 1.90 + float f[16]; ///< Interpretation of data depends on the type of the transformation 1.91 +}; 1.92 + 1.93 +/** A collada camera. */ 1.94 +struct Camera 1.95 +{ 1.96 + Camera() 1.97 + : mOrtho (false) 1.98 + , mHorFov (10e10f) 1.99 + , mVerFov (10e10f) 1.100 + , mAspect (10e10f) 1.101 + , mZNear (0.1f) 1.102 + , mZFar (1000.f) 1.103 + {} 1.104 + 1.105 + // Name of camera 1.106 + std::string mName; 1.107 + 1.108 + // True if it is an orthografic camera 1.109 + bool mOrtho; 1.110 + 1.111 + //! Horizontal field of view in degrees 1.112 + float mHorFov; 1.113 + 1.114 + //! Vertical field of view in degrees 1.115 + float mVerFov; 1.116 + 1.117 + //! Screen aspect 1.118 + float mAspect; 1.119 + 1.120 + //! Near& far z 1.121 + float mZNear, mZFar; 1.122 +}; 1.123 + 1.124 +#define aiLightSource_AMBIENT 0xdeaddead 1.125 +#define ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET 1e9f 1.126 + 1.127 +/** A collada light source. */ 1.128 +struct Light 1.129 +{ 1.130 + Light() 1.131 + : mAttConstant (1.f) 1.132 + , mAttLinear (0.f) 1.133 + , mAttQuadratic (0.f) 1.134 + , mFalloffAngle (180.f) 1.135 + , mFalloffExponent (0.f) 1.136 + , mPenumbraAngle (ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET) 1.137 + , mOuterAngle (ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET) 1.138 + , mIntensity (1.f) 1.139 + {} 1.140 + 1.141 + //! Type of the light source aiLightSourceType + ambient 1.142 + unsigned int mType; 1.143 + 1.144 + //! Color of the light 1.145 + aiColor3D mColor; 1.146 + 1.147 + //! Light attenuation 1.148 + float mAttConstant,mAttLinear,mAttQuadratic; 1.149 + 1.150 + //! Spot light falloff 1.151 + float mFalloffAngle; 1.152 + float mFalloffExponent; 1.153 + 1.154 + // ----------------------------------------------------- 1.155 + // FCOLLADA extension from here 1.156 + 1.157 + //! ... related stuff from maja and max extensions 1.158 + float mPenumbraAngle; 1.159 + float mOuterAngle; 1.160 + 1.161 + //! Common light intensity 1.162 + float mIntensity; 1.163 +}; 1.164 + 1.165 +/** Short vertex index description */ 1.166 +struct InputSemanticMapEntry 1.167 +{ 1.168 + InputSemanticMapEntry() 1.169 + : mSet (0) 1.170 + {} 1.171 + 1.172 + //! Index of set, optional 1.173 + unsigned int mSet; 1.174 + 1.175 + //! Name of referenced vertex input 1.176 + InputType mType; 1.177 +}; 1.178 + 1.179 +/** Table to map from effect to vertex input semantics */ 1.180 +struct SemanticMappingTable 1.181 +{ 1.182 + //! Name of material 1.183 + std::string mMatName; 1.184 + 1.185 + //! List of semantic map commands, grouped by effect semantic name 1.186 + std::map<std::string, InputSemanticMapEntry> mMap; 1.187 + 1.188 + //! For std::find 1.189 + bool operator == (const std::string& s) const { 1.190 + return s == mMatName; 1.191 + } 1.192 +}; 1.193 + 1.194 +/** A reference to a mesh inside a node, including materials assigned to the various subgroups. 1.195 + * The ID refers to either a mesh or a controller which specifies the mesh 1.196 + */ 1.197 +struct MeshInstance 1.198 +{ 1.199 + ///< ID of the mesh or controller to be instanced 1.200 + std::string mMeshOrController; 1.201 + 1.202 + ///< Map of materials by the subgroup ID they're applied to 1.203 + std::map<std::string, SemanticMappingTable> mMaterials; 1.204 +}; 1.205 + 1.206 +/** A reference to a camera inside a node*/ 1.207 +struct CameraInstance 1.208 +{ 1.209 + ///< ID of the camera 1.210 + std::string mCamera; 1.211 +}; 1.212 + 1.213 +/** A reference to a light inside a node*/ 1.214 +struct LightInstance 1.215 +{ 1.216 + ///< ID of the camera 1.217 + std::string mLight; 1.218 +}; 1.219 + 1.220 +/** A reference to a node inside a node*/ 1.221 +struct NodeInstance 1.222 +{ 1.223 + ///< ID of the node 1.224 + std::string mNode; 1.225 +}; 1.226 + 1.227 +/** A node in a scene hierarchy */ 1.228 +struct Node 1.229 +{ 1.230 + std::string mName; 1.231 + std::string mID; 1.232 + std::string mSID; 1.233 + Node* mParent; 1.234 + std::vector<Node*> mChildren; 1.235 + 1.236 + /** Operations in order to calculate the resulting transformation to parent. */ 1.237 + std::vector<Transform> mTransforms; 1.238 + 1.239 + /** Meshes at this node */ 1.240 + std::vector<MeshInstance> mMeshes; 1.241 + 1.242 + /** Lights at this node */ 1.243 + std::vector<LightInstance> mLights; 1.244 + 1.245 + /** Cameras at this node */ 1.246 + std::vector<CameraInstance> mCameras; 1.247 + 1.248 + /** Node instances at this node */ 1.249 + std::vector<NodeInstance> mNodeInstances; 1.250 + 1.251 + /** Rootnodes: Name of primary camera, if any */ 1.252 + std::string mPrimaryCamera; 1.253 + 1.254 + //! Constructor. Begin with a zero parent 1.255 + Node() { 1.256 + mParent = NULL; 1.257 + } 1.258 + 1.259 + //! Destructor: delete all children subsequently 1.260 + ~Node() { 1.261 + for( std::vector<Node*>::iterator it = mChildren.begin(); it != mChildren.end(); ++it) 1.262 + delete *it; 1.263 + } 1.264 +}; 1.265 + 1.266 +/** Data source array: either floats or strings */ 1.267 +struct Data 1.268 +{ 1.269 + bool mIsStringArray; 1.270 + std::vector<float> mValues; 1.271 + std::vector<std::string> mStrings; 1.272 +}; 1.273 + 1.274 +/** Accessor to a data array */ 1.275 +struct Accessor 1.276 +{ 1.277 + size_t mCount; // in number of objects 1.278 + size_t mSize; // size of an object, in elements (floats or strings, mostly 1) 1.279 + size_t mOffset; // in number of values 1.280 + size_t mStride; // Stride in number of values 1.281 + std::vector<std::string> mParams; // names of the data streams in the accessors. Empty string tells to ignore. 1.282 + size_t mSubOffset[4]; // Suboffset inside the object for the common 4 elements. For a vector, thats XYZ, for a color RGBA and so on. 1.283 + // For example, SubOffset[0] denotes which of the values inside the object is the vector X component. 1.284 + std::string mSource; // URL of the source array 1.285 + mutable const Data* mData; // Pointer to the source array, if resolved. NULL else 1.286 + 1.287 + Accessor() 1.288 + { 1.289 + mCount = 0; mSize = 0; mOffset = 0; mStride = 0; mData = NULL; 1.290 + mSubOffset[0] = mSubOffset[1] = mSubOffset[2] = mSubOffset[3] = 0; 1.291 + } 1.292 +}; 1.293 + 1.294 +/** A single face in a mesh */ 1.295 +struct Face 1.296 +{ 1.297 + std::vector<size_t> mIndices; 1.298 +}; 1.299 + 1.300 +/** An input channel for mesh data, referring to a single accessor */ 1.301 +struct InputChannel 1.302 +{ 1.303 + InputType mType; // Type of the data 1.304 + size_t mIndex; // Optional index, if multiple sets of the same data type are given 1.305 + size_t mOffset; // Index offset in the indices array of per-face indices. Don't ask, can't explain that any better. 1.306 + std::string mAccessor; // ID of the accessor where to read the actual values from. 1.307 + mutable const Accessor* mResolved; // Pointer to the accessor, if resolved. NULL else 1.308 + 1.309 + InputChannel() { mType = IT_Invalid; mIndex = 0; mOffset = 0; mResolved = NULL; } 1.310 +}; 1.311 + 1.312 +/** Subset of a mesh with a certain material */ 1.313 +struct SubMesh 1.314 +{ 1.315 + std::string mMaterial; ///< subgroup identifier 1.316 + size_t mNumFaces; ///< number of faces in this submesh 1.317 +}; 1.318 + 1.319 +/** Contains data for a single mesh */ 1.320 +struct Mesh 1.321 +{ 1.322 + Mesh() 1.323 + { 1.324 + for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS;++i) 1.325 + mNumUVComponents[i] = 2; 1.326 + } 1.327 + 1.328 + // just to check if there's some sophisticated addressing involved... 1.329 + // which we don't support, and therefore should warn about. 1.330 + std::string mVertexID; 1.331 + 1.332 + // Vertex data addressed by vertex indices 1.333 + std::vector<InputChannel> mPerVertexData; 1.334 + 1.335 + // actual mesh data, assembled on encounter of a <p> element. Verbose format, not indexed 1.336 + std::vector<aiVector3D> mPositions; 1.337 + std::vector<aiVector3D> mNormals; 1.338 + std::vector<aiVector3D> mTangents; 1.339 + std::vector<aiVector3D> mBitangents; 1.340 + std::vector<aiVector3D> mTexCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS]; 1.341 + std::vector<aiColor4D> mColors[AI_MAX_NUMBER_OF_COLOR_SETS]; 1.342 + 1.343 + unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS]; 1.344 + 1.345 + // Faces. Stored are only the number of vertices for each face. 1.346 + // 1 == point, 2 == line, 3 == triangle, 4+ == poly 1.347 + std::vector<size_t> mFaceSize; 1.348 + 1.349 + // Position indices for all faces in the sequence given in mFaceSize - 1.350 + // necessary for bone weight assignment 1.351 + std::vector<size_t> mFacePosIndices; 1.352 + 1.353 + // Submeshes in this mesh, each with a given material 1.354 + std::vector<SubMesh> mSubMeshes; 1.355 +}; 1.356 + 1.357 +/** Which type of primitives the ReadPrimitives() function is going to read */ 1.358 +enum PrimitiveType 1.359 +{ 1.360 + Prim_Invalid, 1.361 + Prim_Lines, 1.362 + Prim_LineStrip, 1.363 + Prim_Triangles, 1.364 + Prim_TriStrips, 1.365 + Prim_TriFans, 1.366 + Prim_Polylist, 1.367 + Prim_Polygon 1.368 +}; 1.369 + 1.370 +/** A skeleton controller to deform a mesh with the use of joints */ 1.371 +struct Controller 1.372 +{ 1.373 + // the URL of the mesh deformed by the controller. 1.374 + std::string mMeshId; 1.375 + 1.376 + // accessor URL of the joint names 1.377 + std::string mJointNameSource; 1.378 + 1.379 + ///< The bind shape matrix, as array of floats. I'm not sure what this matrix actually describes, but it can't be ignored in all cases 1.380 + float mBindShapeMatrix[16]; 1.381 + 1.382 + // accessor URL of the joint inverse bind matrices 1.383 + std::string mJointOffsetMatrixSource; 1.384 + 1.385 + // input channel: joint names. 1.386 + InputChannel mWeightInputJoints; 1.387 + // input channel: joint weights 1.388 + InputChannel mWeightInputWeights; 1.389 + 1.390 + // Number of weights per vertex. 1.391 + std::vector<size_t> mWeightCounts; 1.392 + 1.393 + // JointIndex-WeightIndex pairs for all vertices 1.394 + std::vector< std::pair<size_t, size_t> > mWeights; 1.395 +}; 1.396 + 1.397 +/** A collada material. Pretty much the only member is a reference to an effect. */ 1.398 +struct Material 1.399 +{ 1.400 + std::string mEffect; 1.401 +}; 1.402 + 1.403 +/** Type of the effect param */ 1.404 +enum ParamType 1.405 +{ 1.406 + Param_Sampler, 1.407 + Param_Surface 1.408 +}; 1.409 + 1.410 +/** A param for an effect. Might be of several types, but they all just refer to each other, so I summarize them */ 1.411 +struct EffectParam 1.412 +{ 1.413 + ParamType mType; 1.414 + std::string mReference; // to which other thing the param is referring to. 1.415 +}; 1.416 + 1.417 +/** Shading type supported by the standard effect spec of Collada */ 1.418 +enum ShadeType 1.419 +{ 1.420 + Shade_Invalid, 1.421 + Shade_Constant, 1.422 + Shade_Lambert, 1.423 + Shade_Phong, 1.424 + Shade_Blinn 1.425 +}; 1.426 + 1.427 +/** Represents a texture sampler in collada */ 1.428 +struct Sampler 1.429 +{ 1.430 + Sampler() 1.431 + : mWrapU (true) 1.432 + , mWrapV (true) 1.433 + , mMirrorU () 1.434 + , mMirrorV () 1.435 + , mOp (aiTextureOp_Multiply) 1.436 + , mUVId (UINT_MAX) 1.437 + , mWeighting (1.f) 1.438 + , mMixWithPrevious (1.f) 1.439 + {} 1.440 + 1.441 + /** Name of image reference 1.442 + */ 1.443 + std::string mName; 1.444 + 1.445 + /** Wrap U? 1.446 + */ 1.447 + bool mWrapU; 1.448 + 1.449 + /** Wrap V? 1.450 + */ 1.451 + bool mWrapV; 1.452 + 1.453 + /** Mirror U? 1.454 + */ 1.455 + bool mMirrorU; 1.456 + 1.457 + /** Mirror V? 1.458 + */ 1.459 + bool mMirrorV; 1.460 + 1.461 + /** Blend mode 1.462 + */ 1.463 + aiTextureOp mOp; 1.464 + 1.465 + /** UV transformation 1.466 + */ 1.467 + aiUVTransform mTransform; 1.468 + 1.469 + /** Name of source UV channel 1.470 + */ 1.471 + std::string mUVChannel; 1.472 + 1.473 + /** Resolved UV channel index or UINT_MAX if not known 1.474 + */ 1.475 + unsigned int mUVId; 1.476 + 1.477 + // OKINO/MAX3D extensions from here 1.478 + // ------------------------------------------------------- 1.479 + 1.480 + /** Weighting factor 1.481 + */ 1.482 + float mWeighting; 1.483 + 1.484 + /** Mixing factor from OKINO 1.485 + */ 1.486 + float mMixWithPrevious; 1.487 +}; 1.488 + 1.489 +/** A collada effect. Can contain about anything according to the Collada spec, 1.490 + but we limit our version to a reasonable subset. */ 1.491 +struct Effect 1.492 +{ 1.493 + // Shading mode 1.494 + ShadeType mShadeType; 1.495 + 1.496 + // Colors 1.497 + aiColor4D mEmissive, mAmbient, mDiffuse, mSpecular, 1.498 + mTransparent, mReflective; 1.499 + 1.500 + // Textures 1.501 + Sampler mTexEmissive, mTexAmbient, mTexDiffuse, mTexSpecular, 1.502 + mTexTransparent, mTexBump, mTexReflective; 1.503 + 1.504 + // Scalar factory 1.505 + float mShininess, mRefractIndex, mReflectivity; 1.506 + float mTransparency; 1.507 + 1.508 + // local params referring to each other by their SID 1.509 + typedef std::map<std::string, Collada::EffectParam> ParamLibrary; 1.510 + ParamLibrary mParams; 1.511 + 1.512 + // MAX3D extensions 1.513 + // --------------------------------------------------------- 1.514 + // Double-sided? 1.515 + bool mDoubleSided, mWireframe, mFaceted; 1.516 + 1.517 + Effect() 1.518 + : mShadeType (Shade_Phong) 1.519 + , mEmissive ( 0, 0, 0, 1) 1.520 + , mAmbient ( 0.1f, 0.1f, 0.1f, 1) 1.521 + , mDiffuse ( 0.6f, 0.6f, 0.6f, 1) 1.522 + , mSpecular ( 0.4f, 0.4f, 0.4f, 1) 1.523 + , mTransparent ( 0, 0, 0, 1) 1.524 + , mShininess (10.0f) 1.525 + , mRefractIndex (1.f) 1.526 + , mReflectivity (1.f) 1.527 + , mTransparency (0.f) 1.528 + , mDoubleSided (false) 1.529 + , mWireframe (false) 1.530 + , mFaceted (false) 1.531 + { 1.532 + } 1.533 +}; 1.534 + 1.535 +/** An image, meaning texture */ 1.536 +struct Image 1.537 +{ 1.538 + std::string mFileName; 1.539 + 1.540 + /** If image file name is zero, embedded image data 1.541 + */ 1.542 + std::vector<uint8_t> mImageData; 1.543 + 1.544 + /** If image file name is zero, file format of 1.545 + * embedded image data. 1.546 + */ 1.547 + std::string mEmbeddedFormat; 1.548 + 1.549 +}; 1.550 + 1.551 +/** An animation channel. */ 1.552 +struct AnimationChannel 1.553 +{ 1.554 + /** URL of the data to animate. Could be about anything, but we support only the 1.555 + * "NodeID/TransformID.SubElement" notation 1.556 + */ 1.557 + std::string mTarget; 1.558 + 1.559 + /** Source URL of the time values. Collada calls them "input". Meh. */ 1.560 + std::string mSourceTimes; 1.561 + /** Source URL of the value values. Collada calls them "output". */ 1.562 + std::string mSourceValues; 1.563 +}; 1.564 + 1.565 +/** An animation. Container for 0-x animation channels or 0-x animations */ 1.566 +struct Animation 1.567 +{ 1.568 + /** Anim name */ 1.569 + std::string mName; 1.570 + 1.571 + /** the animation channels, if any */ 1.572 + std::vector<AnimationChannel> mChannels; 1.573 + 1.574 + /** the sub-animations, if any */ 1.575 + std::vector<Animation*> mSubAnims; 1.576 + 1.577 + /** Destructor */ 1.578 + ~Animation() 1.579 + { 1.580 + for( std::vector<Animation*>::iterator it = mSubAnims.begin(); it != mSubAnims.end(); ++it) 1.581 + delete *it; 1.582 + } 1.583 +}; 1.584 + 1.585 +/** Description of a collada animation channel which has been determined to affect the current node */ 1.586 +struct ChannelEntry 1.587 +{ 1.588 + const Collada::AnimationChannel* mChannel; ///> the source channel 1.589 + std::string mTransformId; // the ID of the transformation step of the node which is influenced 1.590 + size_t mTransformIndex; // Index into the node's transform chain to apply the channel to 1.591 + size_t mSubElement; // starting index inside the transform data 1.592 + 1.593 + // resolved data references 1.594 + const Collada::Accessor* mTimeAccessor; ///> Collada accessor to the time values 1.595 + const Collada::Data* mTimeData; ///> Source data array for the time values 1.596 + const Collada::Accessor* mValueAccessor; ///> Collada accessor to the key value values 1.597 + const Collada::Data* mValueData; ///> Source datat array for the key value values 1.598 + 1.599 + ChannelEntry() { mChannel = NULL; mSubElement = 0; } 1.600 +}; 1.601 + 1.602 +} // end of namespace Collada 1.603 +} // end of namespace Assimp 1.604 + 1.605 +#endif // AI_COLLADAHELPER_H_INC