Cocos2d-x 3.x 圖形學(xué)渲染系列二十九.doc_第1頁
Cocos2d-x 3.x 圖形學(xué)渲染系列二十九.doc_第2頁
Cocos2d-x 3.x 圖形學(xué)渲染系列二十九.doc_第3頁
Cocos2d-x 3.x 圖形學(xué)渲染系列二十九.doc_第4頁
Cocos2d-x 3.x 圖形學(xué)渲染系列二十九.doc_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

Cocos2d-x 3.x 圖形學(xué)渲染系列二十九下面以模型Attribute屬性給讀者展示如下所示:cpp view plain copy#ifdef _MSC_VER #pragma once #endif #ifndef MODELDATA_ATTRIBUTES_H #define MODELDATA_ATTRIBUTES_H #include ./json/BaseJSONWriter.h #include #define ATTRIBUTE_UNKNOWN 0 #define ATTRIBUTE_POSITION 1 #define ATTRIBUTE_NORMAL 2 #define ATTRIBUTE_COLOR 3 #define ATTRIBUTE_COLORPACKED 4 #define ATTRIBUTE_TANGENT 5 #define ATTRIBUTE_BINORMAL 6 #define ATTRIBUTE_TEXCOORD0 7 #define ATTRIBUTE_TEXCOORD1 8 #define ATTRIBUTE_TEXCOORD2 9 #define ATTRIBUTE_TEXCOORD3 10 #define ATTRIBUTE_TEXCOORD4 11 #define ATTRIBUTE_TEXCOORD5 12 #define ATTRIBUTE_TEXCOORD6 13 #define ATTRIBUTE_TEXCOORD7 14 #define ATTRIBUTE_BLENDWEIGHT0 15 #define ATTRIBUTE_BLENDWEIGHT1 16 #define ATTRIBUTE_BLENDWEIGHT2 17 #define ATTRIBUTE_BLENDWEIGHT3 18 #define ATTRIBUTE_BLENDWEIGHT4 19 #define ATTRIBUTE_BLENDWEIGHT5 20 #define ATTRIBUTE_BLENDWEIGHT6 21 #define ATTRIBUTE_BLENDWEIGHT7 22 #define ATTRIBUTE_COUNT 23 #define ATTRIBUTE_TYPE_SIGNED 0x00 #define ATTRIBUTE_TYPE_UNSIGNED 0x80 #define ATTRIBUTE_TYPE_HEX 0x40 #define ATTRIBUTE_TYPE_FLOAT 0 #define ATTRIBUTE_TYPE_INT 1 #define ATTRIBUTE_TYPE_UINT (ATTRIBUTE_TYPE_INT | ATTRIBUTE_TYPE_UNSIGNED) #define ATTRIBUTE_TYPE_UINT_HEX (ATTRIBUTE_TYPE_UINT | ATTRIBUTE_TYPE_HEX) #define INIT_VECTOR(T, A) std:vector(A, A + sizeof(A) / sizeof(*A) namespace fbxconv namespace modeldata staticconstchar * AttributeNames = UNKNOWN, VERTEX_ATTRIB_POSITION, VERTEX_ATTRIB_NORMAL, VERTEX_ATTRIB_COLOR, COLORPACKED, VERTEX_ATTRIB_TANGENT, VERTEX_ATTRIB_BINORMAL, VERTEX_ATTRIB_TEX_COORD, VERTEX_ATTRIB_TEX_COORD1, VERTEX_ATTRIB_TEX_COORD2, VERTEX_ATTRIB_TEX_COORD3, VERTEX_ATTRIB_TEX_COORD4, VERTEX_ATTRIB_TEX_COORD5, VERTEX_ATTRIB_TEX_COORD6, VERTEX_ATTRIB_TEX_COORD7, VERTEX_ATTRIB_BLEND_WEIGHT, VERTEX_ATTRIB_BLEND_INDEX, BLENDWEIGHT2, BLENDWEIGHT3, BLENDWEIGHT4, BLENDWEIGHT5, BLENDWEIGHT6, BLENDWEIGHT7 ; staticconstunsignedshort AttributeTypeV2 = ATTRIBUTE_TYPE_FLOAT, ATTRIBUTE_TYPE_FLOAT; staticconstunsignedshort AttributeTypeV4 = ATTRIBUTE_TYPE_FLOAT, ATTRIBUTE_TYPE_FLOAT, ATTRIBUTE_TYPE_FLOAT, ATTRIBUTE_TYPE_FLOAT; staticconstunsignedshort AttributeTypeV3 = ATTRIBUTE_TYPE_FLOAT, ATTRIBUTE_TYPE_FLOAT, ATTRIBUTE_TYPE_FLOAT; staticconstunsignedshort AttributeTypeUIntHex = ATTRIBUTE_TYPE_UINT_HEX; staticconstunsignedshort AttributeTypeBlend = ATTRIBUTE_TYPE_INT, ATTRIBUTE_TYPE_FLOAT; staticconststd:vector AttributeTypes = INIT_VECTOR(unsignedshort, AttributeTypeV4), / Unknown INIT_VECTOR(unsignedshort, AttributeTypeV3), / Position INIT_VECTOR(unsignedshort, AttributeTypeV3), / INIT_VECTOR(unsignedshort, AttributeTypeV4), / INIT_VECTOR(unsignedshort, AttributeTypeUIntHex),/ ColorPacked INIT_VECTOR(unsignedshort, AttributeTypeV3), / Tangent INIT_VECTOR(unsignedshort, AttributeTypeV3), / Binormal INIT_VECTOR(unsignedshort, AttributeTypeV2), / Texcoord0 INIT_VECTOR(unsignedshort, AttributeTypeV2), / Texcoord1 INIT_VECTOR(unsignedshort, AttributeTypeV2), / Texcoord2 INIT_VECTOR(unsignedshort, AttributeTypeV2), / Texcoord3 INIT_VECTOR(unsignedshort, AttributeTypeV2), / Texcoord4 INIT_VECTOR(unsignedshort, AttributeTypeV2), / Texcoord5 INIT_VECTOR(unsignedshort, AttributeTypeV2), / Texcoord6 INIT_VECTOR(unsignedshort, AttributeTypeV2), / Texcoord7 INIT_VECTOR(unsignedshort, AttributeTypeBlend), / Blendweight0 INIT_VECTOR(unsignedshort, AttributeTypeBlend), / Blendweight1 INIT_VECTOR(unsignedshort, AttributeTypeBlend), / Blendweight2 INIT_VECTOR(unsignedshort, AttributeTypeBlend), / Blendweight3 INIT_VECTOR(unsignedshort, AttributeTypeBlend), / Blendweight4 INIT_VECTOR(unsignedshort, AttributeTypeBlend), / Blendweight5 INIT_VECTOR(unsignedshort, AttributeTypeBlend), / Blendweight6 INIT_VECTOR(unsignedshort, AttributeTypeBlend) / Blendweight7 ; struct MeshVertexAttrib /屬性大小 unsignedint size; std:string type; std:string name; ; #define ATTRIBUTE_SIZE(idx) (AttributeTypesidx.size() struct Attributes : publicjson:ConstSerializable unsignedlong value; std:map attributemap; Attributes() : value(0) MeshVertexAttrib v1; = VERTEX_ATTRIB_POSITION; v1.size = 3; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_POSITION= v1; = VERTEX_ATTRIB_NORMAL; v1.size = 3; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_NORMAL= v1; = VERTEX_ATTRIB_TEX_COORD; v1.size = 2; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_TEX_COORD= v1; = VERTEX_ATTRIB_TEX_COORD1; v1.size = 2; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_TEX_COORD1= v1; = VERTEX_ATTRIB_TEX_COORD2; v1.size = 2; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_TEX_COORD2= v1; = VERTEX_ATTRIB_TEX_COORD3; v1.size = 2; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_TEX_COORD3= v1; = VERTEX_ATTRIB_TEX_COORD4; v1.size = 2; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_TEX_COORD4= v1; = VERTEX_ATTRIB_TEX_COORD5; v1.size = 2; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_TEX_COORD5= v1; = VERTEX_ATTRIB_TEX_COORD6; v1.size = 2; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_TEX_COORD6= v1; = VERTEX_ATTRIB_TEX_COORD7; v1.size = 2; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_TEX_COORD7= v1; = VERTEX_ATTRIB_BLEND_WEIGHT; v1.size = 4; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_BLEND_WEIGHT= v1; = VERTEX_ATTRIB_BLEND_INDEX; v1.size = 4; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_BLEND_INDEX= v1; = VERTEX_ATTRIB_COLOR; v1.size = 4; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_COLOR= v1; = VERTEX_ATTRIB_TANGENT; v1.size = 3; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_TANGENT= v1; = VERTEX_ATTRIB_BINORMAL; v1.size = 3; v1.type = GL_FLOAT; attributemapVERTEX_ATTRIB_BINORMAL= v1; Attributes(constunsignedlong&v) : value(v) Attributes(constAttributes©From) : value(copyFrom.value) inlinebooloperator=(constAttributes& rhs) const returnvalue = rhs.value; unsignedint size() const unsignedint result = 0; for (unsignedint i = 0; i ATTRIBUTE_COUNT; i+) if (has(i) result += (unsignedint)ATTRIBUTE_SIZE(i); return result; unsignedint length() const unsignedint result = 0; for (unsignedint i = 0; i ATTRIBUTE_COUNT; i+) if (has(i) result+; return result; constint get(unsignedint index) const for (unsignedint i = 0; i ATTRIBUTE_COUNT; i+) if (has(i) & index- = 0) return i; return -1; constchar *name(constunsignedint&index) const constint a = get(index); return a 0 ? 0 : AttributeNamesa; constunsignedshort getType(constunsignedint&v) const unsignedint s = 0; for (unsignedint i = 0; i v) returnAttributeTypesiv-s; s+=is; return0; void set(constunsignedint&attribute, constbool&v) if (v) add(attribute); else remove(attribute); void add(constunsignedint&attribute) value |= (1 attribute); void remove(constunsignedint&attribute) value&= -1 (1 attribute); inlinebool has(constunsignedint&attribute) const return (value& (1 attribute) != 0; inlinebool hasPosition() const returnhas(ATTRIBUTE_POSITION); void hasPosition(constbool&v) set(ATTRIBUTE_POSITION, v); inlinebool hasNormal() const returnhas(ATTRIBUTE_NORMAL); void hasNormal(constbool&v) set(ATTRIBUTE_NORMAL, v); inlinebool hasColor() const returnhas(ATTRIBUTE_COLOR); void hasColor(constbool&v) set(ATTRIBUTE_COLOR, v); inlinebool hasColorPacked() const returnhas(ATTRIBUTE_COLORPACKED); void hasColorPacked(constbool&v) set(ATTRIBUTE_COLORPACKED, v); inlinebool hasTangent() const returnhas(ATTRIBUTE_TANGENT); void hasTangent(constbool&v) set(ATTRIBUTE_TANGENT, v); inlinebool hasBinormal() const returnhas(ATTRIBUTE_BINORMAL); void hasBinormal(constbool&v) set(ATTRIBUTE_BINORMAL, v); inlinebool hasUV(constunsignedshort&uv) const returnhas(ATTRIBUTE_TEXCOORD0 + uv); void hasUV(constunsignedshort&uv, constbool&v) set(ATTRIBUTE_TEXCOORD0 + uv, v); inlinebool hasBlendWeight(constunsignedshort&index) const returnhas(ATTRIBUTE_BLENDWEIGHT0 + index); void hasBlendWeight(constunsignedshort&index, constbool&v) set(ATTRIBUTE_BLENDWEIGHT0 + index, v); virtualvoid serialize(json:BaseJSONWriter&writer) const; void writeBinary(FILE* file); ; #endif 模型所包含的法線,切線,次法線等信息都是通過上述文件定義實(shí)現(xiàn)的,最終可從轉(zhuǎn)換后的模型文本文件中顯示出來。接下來介紹在Reader模塊中的矩陣類實(shí)現(xiàn),模型骨骼動畫的播放都會涉及到矩陣的運(yùn)算,類定義完整代碼實(shí)現(xiàn)如下:cpp view plain copy 在CODE上查看代碼片派生到我的代碼片#ifdef _MSC_VER #pragma once #endif /_MSC_VER #ifndef FBXCONV_READERS_MATRIX3_H #define FBXCONV_READERS_MATRIX3_H namespace fbxconv namespace readers templatestruct Matrix3 T m9; T &x1; T &x2; T &x3; T &y1; T &y2; T &y3; T &z1; T &z2; T &z3; Matrix3() : x1(m0), x2(m1), x3(m2), y1(m3), y2(m4), y3(m5), z1(m6), z2(m7), z3(m8) idt(); Matrix3(constMatrix3©From) : x1(m0), x2(m1), x3(m2), y1(m3), y2(m4), y3(m5), z1(m6), z2(m7), z3(m8) set(copyFrom); inlineMatrix3&operator=(constMatrix3&rhs) return set(rhs); inlineMatrix3&operator*=(constMatrix3&rhs) return mul(rhs); inlineMatrix3&operator+=(constMatrix3&rhs) return add(rhs); Matrix3&idt() return set(1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f); Matrix3&set(constMatrix3&rhs) return set(rhs.x1, rhs.x2, rhs.x3, rhs.y1, rhs.y2, rhs.y3, rhs.z1, rhs.z2, rhs.z3); Matrix3&set(const T &_x1, const T &_x2, const T &_x3, const T &_y1, const T &_y2, const T &_y3, const T &_z1, const T &_z2, const T &_z3) x1 = _x1; x2 = _x2; x3 = _x3; y1 = _y1; y2 = _y2; y3 = _y3; z1 = _z1; z2 = _z2; z3 = _z3; return *this; inlineMatrix3&scale(const T &x = (T)1., const T &y = (T)1., const T &z = (T)1.) returnmulr(x, y, z); Matrix3&rotate(const T &radians) const T c = cos(radians); const T s = sin(radians); return mul(c, -s, s, c); Matrix3&translate(const T &x = (T)0., const T &y = (T)0.) return set( x1, x2, x1 * x + x2 * y + x3, y1, y2, y1 * x + y2 * y + y3, z1, z2, z1 * x + z2 * y + z3); Matrix3&trn(const T &x = (T)0., const T &y = (T)0.) x3 += x; y3 += y; return *this; Matrix3&mul(constMatrix3&rhs) return mul(rhs.x1, rhs.x2, rhs.x3, rhs.y1, rhs.y2, rhs.y3, rhs.z1, rhs.z2, rhs.z3); Matrix3&mul(const T &_x1, const T &_x2, const T &_x3, const T &_y1, const T &_y2, const T &_y3, nst T &_z1, const T &_z2, const T &_z3) return set( x1 * _x1 + x2 * _y1 + x3 * _z1, x1 * _x2 + x2 * _y2 + x3 * _z2, x1 * _x3 + x2 * _y3 + x3 * _z3, y1 * _x1 + y2 * _y1 + y3 * _z1, x2 * _x2 + y2 * _y2 + y3 * _z2, y1 * _x3 + y2 * _y3 + y3 * _z3, z1 * _x1 + z2 * _y1 + z3 * _z1, x3 * _x2 + z2 * _y2 + z3 * _z2, z1 * _x3 + z2 * _y3 + z3 * _z3); Matrix3&mulr(const T &x = (T)1., const T &y = (T)1., const T &z = (T)1.) return set( x1 * x, z2 * y, x3 * z, y1 * x, y2 * y, y3 * z, z1 * x,

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論