[About macOS Ventura 13.0] (12/20/2022)
The currently released Live2D Cubism SDK is not guaranteed to work with macOS Ventura.
Please refrain from upgrading the macOS as they may not work properly.
The Cubism Editor license file may be lost after the macOS upgrade.
Please make sure to deactivate the Cubism Editor license before upgrading the macOS.
For more detailsCubism Editor 5.0 alpha3 is now available! (4/27/2023)
We have incorporated some of your comments and suggestions. Thank you for your comments and requests!
We will continue to welcome your feedback on alpha3.
Download / Manual and Update History Sometimes the live2d model shows darkness
Could you tell me how to solve this problem
0 ·
Comments
Only this image information can't identify the cause .
Please tell me the detailed information .
( Your OS, development environment , SDK Version or Program code etc...)
I know the same thing will happen in the change of texture color in Unity .
>> Transparency and texture color change of Live2D
As the image shows, the live2dSprite.cpp and live2dSprite.h is my code.
{
Live2dSprite *sprite = new (std::nothrow) Live2dSprite(modelDir,modelFileName, size);
if (sprite)
{
sprite->autorelease();
return sprite;
}
CC_SAFE_DELETE(sprite);
return nullptr;
}
Live2dSprite::Live2dSprite(const std::string& modelDir,
const std::string& modelFileName,
const Size &size):
DrawNode(), touchMgr(nullptr),deviceToScreen(nullptr),
viewMatrix(nullptr), l2d_model(nullptr),_eventListener(nullptr),
l2d_size(size),_shadow(1.0),_isRenderShadow(false)
{
l2d_model = new LAppModel();
l2d_model->load(modelDir.c_str(), modelFileName.c_str());
model_width = l2d_model->getCanvasWidth();
model_height = l2d_model->getCanvasHeight();
touchMgr=new TouchManager();
deviceToScreen = new L2DMatrix44();
viewMatrix = new L2DViewMatrix();
//Size size=Director::getInstance()->getWinSize();
float width= l2d_size.width;
float height= l2d_size.height;
float ratio=(float)height/width;
float left = VIEW_LOGICAL_LEFT;
float right = VIEW_LOGICAL_RIGHT;
float bottom = -ratio;
float top = ratio;
_scale = _scaleX = 1.0f;
viewMatrix->setScreenRect(left,right,bottom,top);
float screenW=abs(left-right);
deviceToScreen->multTranslate(-width/2.0f,-height/2.0f );
deviceToScreen->multScale( screenW/width , -screenW/width );
viewMatrix->setMaxScale( VIEW_MAX_SCALE );
viewMatrix->setMinScale( VIEW_MIN_SCALE );
viewMatrix->setMaxScreenRect(
VIEW_LOGICAL_MAX_LEFT,
VIEW_LOGICAL_MAX_RIGHT,
VIEW_LOGICAL_MAX_BOTTOM,
VIEW_LOGICAL_MAX_TOP
);
}
void Live2dSprite::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags)
{
DrawNode::draw(renderer, transform, flags);
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(Live2dSprite::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void Live2dSprite::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
{
this->updatePosition(ccpAdd( getParent()->getPosition(), getPosition()));
kmGLPushMatrix();
kmGLLoadMatrix(&transform);
if(_isRenderShadow)
{
int size = l2d_model->getModelSetting()->getTextureNum();
auto model = ((Live2DModelOpenGL*)l2d_model->getLive2DModel());
for(int i = 0;isetTextureColor(i, 0.0, 0.0, 0.0, 0);
}
}
// colors
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
modelUpdate();
if(_isRenderShadow)
{
int size = l2d_model->getModelSetting()->getTextureNum();
auto model = ((Live2DModelOpenGL*)l2d_model->getLive2DModel());
for(int i = 0;isetTextureColor(i, _shadow, _shadow, _shadow, 0);
}
}
kmGLPopMatrix();
glFrontFace(GL_CCW);
}
void Live2dSprite::modelUpdate()
{
live2d::DrawProfileCocos2D::preDraw();
L2DMatrix44 projection;
Director* director=Director::getInstance();
Size window=director->getWinSize();
projection.scale(1, window.width/window.height);
//float scale = model_width/window.width;
//projection.scale(scale, window.width/window.height * scale);
if (viewMatrix != NULL) {
projection.append(viewMatrix);
}
if(l2d_model != NULL)
{
l2d_model->update();
l2d_model->draw(projection);
}
live2d::DrawProfileCocos2D::postDraw();
}
Live2D API Reference - DrawParam->setBaseColor()
What is isetTextureColor?I think that perhaps _shadow becomes 0.0 . I think it is draw correctly if you use the following .
void Live2dSprite::setShadowOnModel(float shadow)
{
if(shadow>1.0 || shadow<0.0)
{
shadow = 1.0;
}
_shadow = shadow;
/*
if(l2d_model)
{
int size = l2d_model->getModelSetting()->getTextureNum();
auto model = ((Live2DModelOpenGL*)l2d_model->getLive2DModel());
for(int i = 0;isetTextureColor(i, _shadow, _shadow, _shadow, 0);
}
}
*/
}
void Live2dSprite::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
{
this->updatePosition(ccpAdd( getParent()->getPosition(), getPosition()));
kmGLPushMatrix();
kmGLLoadMatrix(&transform);
/*
if(_isRenderShadow)
{
int size = l2d_model->getModelSetting()->getTextureNum();
auto model = ((Live2DModelOpenGL*)l2d_model->getLive2DModel());
for(int i = 0;isetTextureColor(i, 0.0, 0.0, 0.0, 0);
}
}
*/
// colors
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
modelUpdate();
/*
if(_isRenderShadow)
{
int size = l2d_model->getModelSetting()->getTextureNum();
auto model = ((Live2DModelOpenGL*)l2d_model->getLive2DModel());
for(int i = 0;isetTextureColor(i, _shadow, _shadow, _shadow, 0);
}
}
*/
kmGLPopMatrix();
glFrontFace(GL_CCW);
}
As you can see, left image the bug shows and right image shows when I set the texture color to black.
Code:
void Live2dSprite::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
{
this->updatePosition(ccpAdd( getParent()->getPosition(), getPosition()));
kmGLPushMatrix();
kmGLLoadMatrix(&transform);
l2d_model->getLive2DModel()->getDrawParam()->setBaseColor(1.0, 1.0, 1.0, 1.0);
// colors
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
modelUpdate();
kmGLPopMatrix();
glFrontFace(GL_CCW);
}
In code that you have posted the first time in this discussion , What happens if you have modified as follows ? ↓ In the case of Simple project of cocos2d-X Live2D SDK, I was able to change the texture color in setBaseColor().
[SampleLive2DSprite.cpp]
In your program , I think that it probably has been changed texture color in isetTextureColor .
In a program that has been posted on here , I don't know detailed processing of isetTextureColor.
Probably you don't have the same process as setBaseColor?
Or it might be a problem of the model .
How do you Test in Live2D of sample models ?
Live2D Manual - Live2D Sample Model
And I'm sorry if the cause is completely different .
I know it is only this . thanks !
I have made the flowing change in file LAppTextureDesc.cpp.
LAppTextureDesc::LAppTextureDesc(cocos2d::Texture2D* tex,std::string fileName)
{
data=tex;
tex->retain();
textureFileName=fileName;
}
LAppTextureDesc::~LAppTextureDesc()
{
data->release();
if(data->getReferenceCount() == 1)
Director::getInstance()->getTextureCache()->removeTextureForKey(textureFileName);
}