fix: outfit texture swap via internalModel.textures array
model.internalModel.coreModel.setTexture() expects a raw WebGL texture, not a PixiJS Texture. Instead, set the new PixiJS Texture directly on the model's internalModel.textures[2] array. The render loop's bindTexture() call extracts the WebGL handle from the PixiJS BaseTexture and passes it to the Cubism core. This eliminates the cascade of try-catch fallbacks and the 'coreModel.setTexture is not a function' TypeError.
This commit is contained in:
@@ -169,19 +169,14 @@ export default function KiraAvatar(props: Props) {
|
|||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const { Assets, Texture } = await import('pixi.js');
|
const { Assets } = await import('pixi.js');
|
||||||
const tex = await Assets.load(outfitUrl);
|
const tex = await Assets.load(outfitUrl);
|
||||||
// Swap texture slot 2 (clothing layer)
|
// Swap texture slot 2 (clothing layer) in the model's texture array.
|
||||||
if ((model as any).setTexture) {
|
// The render loop automatically binds WebGL textures from PixiJS textures.
|
||||||
(model as any).setTexture(2, tex);
|
if ((model as any).internalModel?.textures) {
|
||||||
|
(model as any).internalModel.textures[2] = tex;
|
||||||
} else {
|
} else {
|
||||||
// Fallback: try internal model
|
console.warn('[Outfit] cannot swap — no textures array');
|
||||||
try {
|
|
||||||
(model.internalModel as any).setTexture(2, tex);
|
|
||||||
} catch {
|
|
||||||
// Fallback: direct core model
|
|
||||||
(model.internalModel.coreModel as any).setTexture(2, tex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('[Outfit] texture swap failed:', e);
|
console.warn('[Outfit] texture swap failed:', e);
|
||||||
|
|||||||
Reference in New Issue
Block a user