Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加3D相关的一些方法 #101

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cocos/2d/CCAnimationCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ void AnimationCache::addAnimation(Animation *animation, const std::string& name)

void AnimationCache::removeAnimation(const std::string& name)
{
if (name.size()==0)
if (name.size()==0) {
_animations.clear();
return;

}
_animations.erase(name);
}

Expand Down
7 changes: 3 additions & 4 deletions cocos/2d/CCAnimationCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ class CC_DLL AnimationCache : public Ref
*/
void addAnimation(Animation *animation, const std::string& name);

/** Deletes a Animation from the cache.

/** Deletes a Animation from the cache. default delete all Animation.
*/
void removeAnimation(const std::string& name);

void removeAnimation(const std::string& name = "");
/** Returns a Animation that was previously added.
If the name is not found it will return nil.
You should retain the returned copy if you are going to use it.
Expand Down
31 changes: 29 additions & 2 deletions cocos/3d/CCSprite3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,35 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
void Sprite3D::setGLProgramState(GLProgramState *glProgramState)
{
Node::setGLProgramState(glProgramState);
for (auto& state : _meshes) {
state->setGLProgramState(glProgramState);
for (auto& it : _meshes) {
auto mesh = it->getMeshIndexData()->getMeshVertexData();

bool meshHasSkin = mesh->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_BLEND_INDEX)
&& mesh->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_BLEND_WEIGHT);
bool meshHasNormal = mesh->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_NORMAL);

bool programHasSkin = glProgramState->getGLProgram()->getVertexAttrib(s_attributeNames[GLProgram::VERTEX_ATTRIB_BLEND_INDEX])
&& glProgramState->getGLProgram()->getVertexAttrib(s_attributeNames[GLProgram::VERTEX_ATTRIB_BLEND_WEIGHT]);
bool programHasNormal = glProgramState->getGLProgram()->getVertexAttrib(s_attributeNames[GLProgram::VERTEX_ATTRIB_NORMAL]);

if (meshHasSkin != programHasSkin || meshHasNormal != programHasNormal) {
break;
}

long offset = 0;
auto attributeCount = mesh->getMeshVertexAttribCount();
for (auto k = 0; k < attributeCount; k++) {
auto meshattribute = mesh->getMeshVertexAttrib(k);
glProgramState->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
meshattribute.size,
meshattribute.type,
GL_FALSE,
mesh->getVertexBuffer()->getSizePerVertex(),
(GLvoid*)offset);
offset += meshattribute.attribSizeBytes;
}

it->setGLProgramState(glProgramState);
}
}
void Sprite3D::setGLProgram(GLProgram *glprogram)
Expand Down
150 changes: 150 additions & 0 deletions cocos/scripting/lua-bindings/auto/lua_cocos2dx_3d_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,153 @@ static int lua_cocos2dx_3d_Mesh_finalize(lua_State* tolua_S)
return 0;
}

int lua_cocos2dx_3d_Mesh_getVertexSizeInBytes(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Mesh* cobj = nullptr;
bool ok = true;

#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif


#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Mesh",0,&tolua_err)) goto tolua_lerror;
#endif

cobj = (cocos2d::Mesh*)tolua_tousertype(tolua_S,1,0);

#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_3d_Mesh_getVertexSizeInBytes'", nullptr);
return 0;
}
#endif

argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_3d_Mesh_getVertexSizeInBytes'", nullptr);
return 0;
}
int ret = cobj->getVertexSizeInBytes();
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Mesh:getVertexSizeInBytes",argc, 0);
return 0;

#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_3d_Mesh_getVertexSizeInBytes'.",&tolua_err);
#endif

return 0;
}

int lua_cocos2dx_3d_Mesh_getMeshVertexAttribCount(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Mesh* cobj = nullptr;
bool ok = true;

#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif


#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Mesh",0,&tolua_err)) goto tolua_lerror;
#endif

cobj = (cocos2d::Mesh*)tolua_tousertype(tolua_S,1,0);

#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_3d_Mesh_getMeshVertexAttribCount'", nullptr);
return 0;
}
#endif

argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_3d_Mesh_getMeshVertexAttribCount'", nullptr);
return 0;
}
ssize_t ret = cobj->getMeshVertexAttribCount();
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Mesh:getMeshVertexAttribCount",argc, 0);
return 0;

#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_3d_Mesh_getMeshVertexAttribCount'.",&tolua_err);
#endif

return 0;
}

int lua_cocos2dx_3d_Mesh_getMeshVertexAttribute(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Mesh* cobj = nullptr;
bool ok = true;

#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif


#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Mesh",0,&tolua_err)) goto tolua_lerror;
#endif

cobj = (cocos2d::Mesh*)tolua_tousertype(tolua_S,1,0);

#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_3d_Mesh_getMeshVertexAttribute'", nullptr);
return 0;
}
#endif

argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
int arg0;

ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "cc.Mesh:getMeshVertexAttribute");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_3d_Mesh_getMeshVertexAttribute'", nullptr);
return 0;
}
const cocos2d::MeshVertexAttrib& ret = cobj->getMeshVertexAttribute(arg0);
mesh_vertex_attrib_to_luaval(tolua_S, ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Mesh:getMeshVertexAttribute",argc, 1);
return 0;

#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_3d_Mesh_getMeshVertexAttribute'.",&tolua_err);
#endif

return 0;
}

int lua_register_cocos2dx_3d_Mesh(lua_State* tolua_S)
{
tolua_usertype(tolua_S,"cc.Mesh");
Expand All @@ -1506,6 +1653,9 @@ int lua_register_cocos2dx_3d_Mesh(lua_State* tolua_S)
tolua_function(tolua_S,"getBlendFunc",lua_cocos2dx_3d_Mesh_getBlendFunc);
tolua_function(tolua_S,"isVisible",lua_cocos2dx_3d_Mesh_isVisible);
tolua_function(tolua_S,"setVisible",lua_cocos2dx_3d_Mesh_setVisible);
tolua_function(tolua_S,"getVertexSizeInBytes",lua_cocos2dx_3d_Mesh_getVertexSizeInBytes);
tolua_function(tolua_S,"getMeshVertexAttribute",lua_cocos2dx_3d_Mesh_getMeshVertexAttribute);
tolua_function(tolua_S,"getMeshVertexAttribCount",lua_cocos2dx_3d_Mesh_getMeshVertexAttribCount);
tolua_endmodule(tolua_S);
std::string typeName = typeid(cocos2d::Mesh).name();
g_luaType[typeName] = "cc.Mesh";
Expand Down
13 changes: 12 additions & 1 deletion cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62453,7 +62453,18 @@ int lua_cocos2dx_AnimationCache_removeAnimation(lua_State* tolua_S)
#endif

argc = lua_gettop(tolua_S)-1;
if (argc == 1)
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_AnimationCache_removeAnimation'", nullptr);
return 0;
}
cobj->removeAnimation();
lua_settop(tolua_S, 1);
return 1;
}
else if (argc == 1)
{
std::string arg0;

Expand Down
Loading