Skip to content

Commit

Permalink
3d
Browse files Browse the repository at this point in the history
  • Loading branch information
heweitykc committed Jun 25, 2014
1 parent 621078c commit 6b1954d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
32 changes: 27 additions & 5 deletions proj/动画资源/cocos/animation3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ Animation3D* Animation3D::create(const std::string &modelPath, const std::string
{
auto animation = new Animation3D();
animation->loadFromObj(modelPath);
animation->setTexture(texturePath);
animation->autorelease();
return animation;
}

void Animation3D::setTexture(const std::string& texFile)
{
_texture = Director::getInstance()->getTextureCache()->addImage(texFile);
}

bool Animation3D::loadFromObj(const std::string& path)
{
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
Expand Down Expand Up @@ -122,11 +129,6 @@ void Animation3D::readMesh(const unsigned char *rawdata, int& pos, MeshHead *mes
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)
Expand All @@ -135,6 +137,26 @@ void Animation3D::setBlendFunc(const BlendFunc &blendFunc)
}
}

Animation3D::~Animation3D()
{
log("~Animation3D");
for (std::vector<MeshHead*>::iterator it = _meshHeads.begin(); it != _meshHeads.end(); it++){
if (NULL != *it){
delete *it;
*it = NULL;
}
}
_meshHeads.clear();

for (std::vector<Vertex*>::iterator it = _vertices.begin(); it != _vertices.end(); it++){
if (NULL != *it){
delete *it;
*it = NULL;
}
}
_vertices.clear();
}

const BlendFunc& Animation3D::getBlendFunc() const
{
return _blend;
Expand Down
16 changes: 10 additions & 6 deletions proj/动画资源/cocos/animation3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,27 @@ struct Vertex{
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);
~Animation3D();

bool Animation3D::loadFromObj(const std::string& path);
void setTexture(const std::string& texFile);

virtual void setBlendFunc(const BlendFunc &blendFunc) override;
virtual const BlendFunc &getBlendFunc() const override;
private:
Mesh *_mesh;
MeshCommand _meshCommand;
Texture2D* _texture;
BlendFunc _blend;
std::vector<MeshHead*> _meshHeads;
std::vector<Vertex*> _vertices; //¶¥µãÊý¾Ý
std::vector<unsigned short> _indices; //Ë÷ÒýÊý¾Ý

Texture2D* _texture;
std::vector<MeshHead*> _meshHeads;

std::vector<Vertex*> _vertices; //¶¥µãÊý¾Ý
std::vector<unsigned short> _indices; //Ë÷ÒýÊý¾Ý
};

#endif

0 comments on commit 6b1954d

Please sign in to comment.