diff --git "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/UI/DemoHead_UI/Json/DemoHead_UI.json" "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/UI/DemoHead_UI/Json/DemoHead_UI.json" index 27f674d..1fab8d6 100644 --- "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/UI/DemoHead_UI/Json/DemoHead_UI.json" +++ "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/UI/DemoHead_UI/Json/DemoHead_UI.json" @@ -62,7 +62,7 @@ "tag": 14, "touchAble": false, "useMergedTexture": false, - "visible": false, + "visible": true, "width": 452, "x": -23, "y": -28, @@ -332,7 +332,7 @@ "tag": 14, "touchAble": false, "useMergedTexture": false, - "visible": false, + "visible": true, "width": 452, "x": -78, "y": -27, diff --git "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/animation3d.cpp" "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/animation3d.cpp" index 039e8e9..951530c 100644 --- "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/animation3d.cpp" +++ "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/animation3d.cpp" @@ -1,4 +1,5 @@ #include "animation3d.h" +#include "binarytool.h" Animation3D* Animation3D::create(const std::string &modelPath, const std::string &texturePath, const std::string &animationPath) { @@ -11,21 +12,75 @@ bool Animation3D::loadFromObj(const std::string& path) { std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path); cocos2d::Data meshdata = FileUtils::getInstance()->getDataFromFile(fullPath); + unsigned int len = meshdata.getSize(); const unsigned char *rawdata = meshdata.getBytes(); + int pos = 0; + unsigned int magic = *((int*)rawdata); + pos += 4; + + unsigned int version = *((int*)(rawdata+pos)); + pos += 4; + unsigned short aniFileLen = *((short*)(rawdata + pos)); + pos += 2; + pos += aniFileLen; - std::vector v; - std::vector vn; - std::vector vt; - std::vector > faceGroup; + unsigned short textureFileLen = *((short*)(rawdata + pos)); + pos += 2; + pos += textureFileLen; + unsigned int meshNum = *((int*)(rawdata + pos)); + pos += 4; + log("magic=%u, ver=%u, meshnum=%u", magic,version,meshNum); + + unsigned int i = 0; + while (i < meshNum){ + MeshHead *meshhead = new MeshHead(); + _meshHeads.push_back(meshhead); + readMesh(rawdata, pos, meshhead); + i++; + } + + unsigned int vertNum = *((int*)(rawdata + pos)); + pos += 4; + + i = 0; + while (i < vertNum){ + + i++; + } return true; } +void Animation3D::readMesh(const unsigned char *rawdata, int& pos, MeshHead *meshhead) +{ + unsigned short nameLen = *((short*)(rawdata + pos)); + pos += 2; + + pos += nameLen; + + meshhead->vertexStart = *((int*)(rawdata + pos)); + pos += 4; + + meshhead->vertexCount = *((int*)(rawdata + pos)); + pos += 4; + + meshhead->indexStart = *((int*)(rawdata + pos)); + pos += 4; + + meshhead->indexCount = *((int*)(rawdata + pos)); + pos += 4; +} + +void readVertex(const unsigned char *rawdata, int& pos, Vertex *vertex) +{ + +} + void Animation3D::setBlendFunc(const BlendFunc &blendFunc) { if (_blend.src != blendFunc.src || _blend.dst != blendFunc.dst) diff --git "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/animation3d.h" "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/animation3d.h" index d5b4cc2..9086b05 100644 --- "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/animation3d.h" +++ "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/animation3d.h" @@ -5,18 +5,29 @@ USING_NS_CC; -struct vertex_index +struct MeshHead { - int v_idx, vt_idx, vn_idx; - vertex_index() {}; - vertex_index(int idx) : v_idx(idx), vt_idx(idx), vn_idx(idx) {}; - vertex_index(int vidx, int vtidx, int vnidx) : v_idx(vidx), vt_idx(vtidx), vn_idx(vnidx) {}; + char name[1024]; + unsigned int vertexStart; + unsigned int vertexCount; + unsigned int indexStart; + unsigned int indexCount; +}; +struct Vertex{ + float x , y , z; + float nx , ny , nz; + float u, v; + int bones[4]; + int weights[4]; }; class Animation3D : public Node, public BlendProtocol { public: + static void readVertex(const unsigned char *rawdata, int& pos, Vertex *vertex); + static void readMesh(const unsigned char *rawdata, int& pos, MeshHead *meshhead); + static Animation3D* create(const std::string &modelPath, const std::string &texturePath, const std::string &animationPath); bool Animation3D::loadFromObj(const std::string& path); @@ -28,6 +39,9 @@ class Animation3D : public Node, public BlendProtocol MeshCommand _meshCommand; Texture2D* _texture; BlendFunc _blend; + std::vector _meshHeads; + std::vector _vertices; //顶点数据 + std::vector _indices; //索引数据 }; #endif \ No newline at end of file diff --git "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/binarytool.cpp" "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/binarytool.cpp" new file mode 100644 index 0000000..c7bc583 --- /dev/null +++ "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/binarytool.cpp" @@ -0,0 +1,17 @@ +#include "binarytool.h" + +void BinaryTool::fillInt(unsigned char* in, int pos, unsigned int intVar) +{ + in[pos + 3] = intVar & 0xff; + in[pos + 2] = (intVar & 0xff00) >> 8; + in[pos + 1] = (intVar & 0xff0000) >> 16; + in[pos] = (intVar & 0xff000000) >> 24; +} + +unsigned int BinaryTool::getInt(const unsigned char* in, int pos) +{ + return (unsigned char)(*(in + pos + 3)) + + ((unsigned char)(*(in + pos + 2)) << 8) + + ((unsigned char)(*(in + pos + 1)) << 16) + + ((unsigned char)(*(in + pos)) << 16); +} \ No newline at end of file diff --git "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/binarytool.h" "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/binarytool.h" new file mode 100644 index 0000000..0381cdf --- /dev/null +++ "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/binarytool.h" @@ -0,0 +1,11 @@ +#ifndef __BINARY_TOOL_H__ +#define __BINARY_TOOL_H__ + +class BinaryTool{ +public: + static void fillInt(unsigned char* in, int pos, unsigned int intVar); + static unsigned int getInt(const unsigned char* in, int pos); + +}; + +#endif \ No newline at end of file diff --git "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/map.cpp" "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/map.cpp" index 70e8c28..0819e84 100644 --- "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/map.cpp" +++ "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/map.cpp" @@ -62,7 +62,7 @@ bool GameMap::init() _role = nullptr; - _tdRole = Sprite3D::create("Sprite3DTest/boss1.obj"); + _tdRole = Sprite3D::create("Sprite3DTest/boss.obj"); _tdRole->setScale(13.f); _tdRole->setTexture("Sprite3DTest/boss.png"); _road->addChild(_tdRole); diff --git "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/net.cpp" "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/net.cpp" index ab64a02..58c9108 100644 --- "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/net.cpp" +++ "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/net.cpp" @@ -1,5 +1,6 @@ #include "net.h" #include "events.h" +#include "binarytool.h" static NetLayer* instance = nullptr; @@ -68,8 +69,8 @@ void NetLayer::clientMove(int x, int y) pack.cmd = pkgUtil::NetProtocol::mvrole; pack.len = 8; pack.raw = new unsigned char[8]; - pkgUtil::fillInt(pack.raw, 0, x); - pkgUtil::fillInt(pack.raw, 4, y); + BinaryTool::fillInt(pack.raw, 0, x); + BinaryTool::fillInt(pack.raw, 4, y); send(pack); } @@ -85,15 +86,15 @@ void NetLayer::onMessage(cocos2d::network::WebSocket* ws, const cocos2d::network pkgUtil::unpkg((unsigned char*)data.bytes,&pack); if (pack.cmd == pkgUtil::NetProtocol::login){ - _uid = pkgUtil::getInt(pack.raw, 0); + _uid = BinaryTool::getInt(pack.raw, 0); log("login uid=%d", _uid); dispatcher.dispatchCustomEvent(NET_LOGIN); } else if (pack.cmd == pkgUtil::NetProtocol::addrole){ Add_Role addrole; - addrole.uid = pkgUtil::getInt(pack.raw, 0); - addrole.x = pkgUtil::getInt(pack.raw, 4); - addrole.y = pkgUtil::getInt(pack.raw, 8); + addrole.uid = BinaryTool::getInt(pack.raw, 0); + addrole.x = BinaryTool::getInt(pack.raw, 4); + addrole.y = BinaryTool::getInt(pack.raw, 8); addrole.isHero = (_uid == addrole.uid); log("addrole=%d,x=%d,y=%d", addrole.uid, addrole.x, addrole.y); diff --git "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/pkgutil.cpp" "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/pkgutil.cpp" index 0e05794..efbd015 100644 --- "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/pkgutil.cpp" +++ "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/pkgutil.cpp" @@ -1,4 +1,6 @@ #include "pkgutil.h" +#include "binarytool.h" + #include using namespace std; @@ -13,26 +15,10 @@ void pkgUtil::printRaw(unsigned char* data, int len) printf("\n"); } -void pkgUtil::fillInt(unsigned char* in, int pos, unsigned int intVar) -{ - in[pos + 3] = intVar & 0xff; - in[pos + 2] = (intVar & 0xff00) >> 8; - in[pos + 1] = (intVar & 0xff0000) >> 16; - in[pos] = (intVar & 0xff000000) >> 24; -} - -unsigned int pkgUtil::getInt(const unsigned char* in, int pos) -{ - return (unsigned char)(*(in + pos + 3)) - + ((unsigned char)(*(in + pos + 2)) << 8) - + ((unsigned char)(*(in + pos + 1)) << 16) - + ((unsigned char)(*(in + pos)) << 16); -} - void pkgUtil::pkg(netpack *pack, unsigned char* out) { - fillInt(out, 0, pack->len); - fillInt(out, 4, pack->cmd); + BinaryTool::fillInt(out, 0, pack->len); + BinaryTool::fillInt(out, 4, pack->cmd); unsigned int i = 0; while (i < pack->len){ @@ -43,8 +29,8 @@ void pkgUtil::pkg(netpack *pack, unsigned char* out) void pkgUtil::unpkg(const unsigned char* in, netpack *pack) { - int len = getInt(in, 0); - int cmd = getInt(in, 4); + int len = BinaryTool::getInt(in, 0); + int cmd = BinaryTool::getInt(in, 4); pack->raw = new unsigned char[len]; pack->len = len; pack->cmd = cmd; diff --git "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/pkgutil.h" "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/pkgutil.h" index 89f0820..04b1571 100644 --- "a/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/pkgutil.h" +++ "b/proj/\345\212\250\347\224\273\350\265\204\346\272\220/cocos/pkgutil.h" @@ -39,8 +39,6 @@ class pkgUtil static void printRaw(unsigned char* data, int len); static void pkg(netpack *pack, unsigned char* out); //封包 static void unpkg(const unsigned char* in, netpack *pack); //解包 - static void fillInt(unsigned char* in, int pos, unsigned int intVar); - static unsigned int getInt(const unsigned char* in, int pos); pkgUtil(); void append(const char* str, int len); void getNext(netpack* pack);