mirror of https://github.com/axmolengine/axmol.git
animation test
This commit is contained in:
parent
87c7e2b0e9
commit
0c95fe1fbd
|
@ -34,6 +34,30 @@ NS_CC_BEGIN
|
|||
|
||||
Bundle3D* Bundle3D::_instance = nullptr;
|
||||
|
||||
Bundle3D::MeshData::MeshData()
|
||||
: vertex(nullptr)
|
||||
, vertexSizeInFloat(0)
|
||||
, indices(nullptr)
|
||||
, numIndex(0)
|
||||
, attribs(nullptr)
|
||||
, attribCount(0)
|
||||
{
|
||||
|
||||
}
|
||||
Bundle3D::MeshData::~MeshData()
|
||||
{
|
||||
resetData();
|
||||
}
|
||||
void Bundle3D::MeshData::resetData()
|
||||
{
|
||||
CC_SAFE_DELETE_ARRAY(vertex);
|
||||
CC_SAFE_DELETE_ARRAY(indices);
|
||||
CC_SAFE_DELETE_ARRAY(attribs);
|
||||
vertexSizeInFloat = 0;
|
||||
numIndex = 0;
|
||||
attribCount = 0;
|
||||
}
|
||||
|
||||
Bundle3D* Bundle3D::getInstance()
|
||||
{
|
||||
if (_instance == nullptr)
|
||||
|
@ -57,7 +81,30 @@ bool Bundle3D::load(const std::string& path)
|
|||
*/
|
||||
bool Bundle3D::loadMeshData(const std::string& id, MeshData* meshdata)
|
||||
{
|
||||
//meshdata->vertex;
|
||||
meshdata->resetData();
|
||||
meshdata->vertexSizeInFloat = 5 * 4;
|
||||
meshdata->vertex = new float[meshdata->vertexSizeInFloat];
|
||||
float vert[] = {0.f,50.f,0.f,0.f,0.f, 0.f,0.f,50.f,1.f,1.f, 50.f,0.f,0.f,1.f,1.f, -50.f,0.f,0.f,1.f,1.f};
|
||||
memcpy(meshdata->vertex, vert, meshdata->vertexSizeInFloat * sizeof(float));
|
||||
|
||||
//meshdata->numIndex = 4 * 3;
|
||||
meshdata->numIndex = 3;
|
||||
meshdata->indices = new unsigned short[meshdata->numIndex];
|
||||
unsigned short index[] = {0,1,2};//{0,1,2, 0,3,1, 0,2,3, 3,2,1};
|
||||
memcpy(meshdata->indices, index, meshdata->numIndex * sizeof(unsigned short));
|
||||
|
||||
meshdata->attribCount = 2;
|
||||
meshdata->attribs = new MeshVertexAttrib[meshdata->attribCount];
|
||||
meshdata->attribs[0].attribSizeBytes = 3 * sizeof(float);
|
||||
meshdata->attribs[0].size = 3;
|
||||
meshdata->attribs[0].type = GL_FLOAT;
|
||||
meshdata->attribs[0].vertexAttrib = GLProgram::VERTEX_ATTRIB_POSITION;
|
||||
|
||||
meshdata->attribs[1].attribSizeBytes = 2 * sizeof(float);
|
||||
meshdata->attribs[1].size = 2;
|
||||
meshdata->attribs[1].type = GL_FLOAT;
|
||||
meshdata->attribs[1].vertexAttrib = GLProgram::VERTEX_ATTRIB_TEX_COORD;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -78,6 +125,7 @@ bool Bundle3D::loadSkinData(const std::string& id, SkinData* skindata)
|
|||
*/
|
||||
bool Bundle3D::loadMaterialData(const std::string& id, MaterialData* materialdata)
|
||||
{
|
||||
materialdata->texturePath = "Sprite3DTest/boss.png";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,9 @@ public:
|
|||
int numIndex;
|
||||
MeshVertexAttrib* attribs;
|
||||
int attribCount;
|
||||
void resetData();
|
||||
MeshData();
|
||||
~MeshData();
|
||||
};
|
||||
struct SkinData
|
||||
{
|
||||
|
|
|
@ -152,10 +152,10 @@ protected:
|
|||
class MeshSkin: public Ref
|
||||
{
|
||||
public:
|
||||
MeshSkin* getOrCreate(const std::string& filename, const std::string& name);
|
||||
static MeshSkin* getOrCreate(const std::string& filename, const std::string& name);
|
||||
|
||||
//create a new meshskin if do not want to share meshskin
|
||||
MeshSkin* create(const std::string& filename, const std::string& name);
|
||||
static MeshSkin* create(const std::string& filename, const std::string& name);
|
||||
|
||||
//get & set bind shape matrix
|
||||
const Mat4& getBindShape() const;
|
||||
|
|
|
@ -153,14 +153,19 @@ bool Sprite3D::loadFromC3x(const std::string& path)
|
|||
}
|
||||
|
||||
_mesh = Mesh::create(meshdata.vertex, meshdata.vertexSizeInFloat, meshdata.indices, meshdata.numIndex, meshdata.attribs, meshdata.attribCount);
|
||||
_mesh->retain();
|
||||
CC_SAFE_RETAIN(_mesh);
|
||||
|
||||
Bundle3D::SkinData skindata;
|
||||
ret = bundle->loadSkinData("", &skindata);
|
||||
// _skin = MeshSkin::create(fullPath, "");
|
||||
// CC_SAFE_RETAIN(_skin);
|
||||
|
||||
Bundle3D::MaterialData materialdata;
|
||||
ret = bundle->loadMaterialData("", &materialdata);
|
||||
if (ret)
|
||||
{
|
||||
setTexture(materialdata.texturePath);
|
||||
}
|
||||
|
||||
genGLProgramState();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -292,7 +297,7 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, bool transformUpd
|
|||
_mesh->getIndexCount(),
|
||||
transform);
|
||||
|
||||
_meshCommand.setCullFaceEnabled(true);
|
||||
//_meshCommand.setCullFaceEnabled(true);
|
||||
_meshCommand.setDepthTestEnabled(true);
|
||||
if (_skin)
|
||||
{
|
||||
|
|
|
@ -11,5 +11,6 @@ uniform vec4 u_color;
|
|||
void main(void)
|
||||
{
|
||||
gl_FragColor = texture2D(CC_Texture0, TextureCoordOut) * u_color;
|
||||
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -41,7 +41,8 @@ static int sceneIdx = -1;
|
|||
static std::function<Layer*()> createFunctions[] =
|
||||
{
|
||||
CL(Sprite3DBasicTest),
|
||||
CL(Sprite3DEffectTest)
|
||||
CL(Sprite3DEffectTest),
|
||||
CL(Sprite3DWithSkinTest)
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
@ -502,3 +503,41 @@ void Sprite3DEffectTest::onTouchesEnded(const std::vector<Touch*>& touches, Even
|
|||
addNewSpriteWithCoords( location );
|
||||
}
|
||||
}
|
||||
|
||||
Sprite3DWithSkinTest::Sprite3DWithSkinTest()
|
||||
{
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesEnded = CC_CALLBACK_2(Sprite3DWithSkinTest::onTouchesEnded, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );
|
||||
}
|
||||
std::string Sprite3DWithSkinTest::title() const
|
||||
{
|
||||
return "Testing Sprite3D";
|
||||
}
|
||||
std::string Sprite3DWithSkinTest::subtitle() const
|
||||
{
|
||||
return "Sprite3D from .c3t";
|
||||
}
|
||||
|
||||
void Sprite3DWithSkinTest::addNewSpriteWithCoords(Vec2 p)
|
||||
{
|
||||
auto sprite = Sprite3D::create("Sprite3DTest/XXX.c3t");
|
||||
sprite->setScale(8.f);
|
||||
sprite->setTexture("Sprite3DTest/boss.png");
|
||||
addChild(sprite);
|
||||
|
||||
sprite->setPosition( Vec2( p.x, p.y) );
|
||||
}
|
||||
|
||||
void Sprite3DWithSkinTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
||||
{
|
||||
for (auto touch: touches)
|
||||
{
|
||||
auto location = touch->getLocation();
|
||||
|
||||
addNewSpriteWithCoords( location );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,6 +135,19 @@ public:
|
|||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
};
|
||||
|
||||
class Sprite3DWithSkinTest : public Sprite3DTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DWithSkinTest);
|
||||
Sprite3DWithSkinTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void addNewSpriteWithCoords(Vec2 p);
|
||||
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
};
|
||||
|
||||
class Sprite3DTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue