[]角色模型的材质列表切换后,不播放动作了

如何给角色使用自定义的shader、材质后,动作依然正常?
 
这是自定义的shader
        var attributeMap = {
'a_Position': Laya.VertexElementUsage.POSITION0,
'a_Normal': Laya.VertexElementUsage.NORMAL0,
'a_Texcoord': Laya.VertexElementUsage.TEXTURECOORDINATE0
};
var uniformMap = {
'u_MvpMatrix': [Laya.Sprite3D.MVPMATRIX, Laya.Shader3D.PERIOD_SPRITE],
'u_WorldMat': [Laya.Sprite3D.WORLDMATRIX, Laya.Shader3D.PERIOD_SPRITE],
'u_texture': [CustomMaterial.DIFFUSETEXTURE_ID, Laya.Shader3D.PERIOD_MATERIAL]
};
var customShader = Laya.Shader3D.nameKey.add("CustomShader");
var vs = "attribute vec4 a_Position;\n" +
"attribute vec2 a_Texcoord;\n" +
"uniform mat4 u_MvpMatrix;\n" +
"uniform mat4 u_WorldMat;\n" +
"attribute vec3 a_Normal;\n" +
"varying vec3 v_Normal;\n" +
"varying vec2 v_Texcoord;\n" +
"void main(){\n" +
"gl_Position = u_MvpMatrix * a_Position;\n" +
"mat3 worldMat=mat3(u_WorldMat);\n" +
"v_Texcoord=a_Texcoord;\n" +
"v_Normal=worldMat*a_Normal;}";
var ps = "#ifdef FSHIGHPRECISION\n" +
"precision highp float;\n" +
"#else\n" +
"precision mediump float;\n" +
"#endif\n" +
"varying vec3 v_Normal;\n" +
"varying vec2 v_Texcoord;\n" +
"uniform sampler2D u_texture;\n" +
"void main(){\n" +
"gl_FragColor=texture2D(u_texture, v_Texcoord);}\n";
自定义材质
class CustomMaterial extends Laya.BaseMaterial {
static DIFFUSETEXTURE_ID: number = 1;
constructor() {
super();
this.setShaderName("CustomShader");
}

public getDiffuseTexture(): Laya.BaseTexture {
return this._getTexture(CustomMaterial.DIFFUSETEXTURE_ID);
}

public setDiffuseTexture(value: Laya.BaseTexture): void {
this._setTexture(CustomMaterial.DIFFUSETEXTURE_ID, value);
}

}
设置材质
mesh.meshRender.sharedMaterials = mats;

设置了材质后,动作就静止了
已邀请:

Supermang42

赞同来自:

重新添加動作腳本給 Mesh 試試看吧~!

xbgzs2010

赞同来自:

尝试过了,还是一样

183*****755

赞同来自:

你给出的顶点着色器中,没有根据骨骼的索引跟权重,重新计算顶点位置的逻辑,参考下官方边缘光照的shader。
    #ifdef BONE
mat4 skinTransform=mat4(0.0);
skinTransform += u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;
skinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;
skinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;
skinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;
vec4 position = skinTransform * a_Position;
gl_Position=u_MvpMatrix * position;
mat3 worldMat=mat3(u_WorldMat * skinTransform);
#else
gl_Position=u_MvpMatrix * a_Position;
mat3 worldMat=mat3(u_WorldMat);
#endif

要回复问题请先

商务合作
商务合作