Fix editor regressions and add Blender scene and animated material import

This commit is contained in:
emil28092005
2026-09-12 00:53:20 +03:00
parent 1a0bf725fa
commit 6f497d1977
34 changed files with 1241 additions and 213 deletions
+44
View File
@@ -312,3 +312,47 @@ test(
}
},
);
test('changing a parent material or transform does not repaint child entities', async () => {
const r = runtime(), p = defaultProject(true);
const parent = entity('Parent', {mesh:{type:'box'}, material:{color:'#ff0000',alpha:.5}}, [0,0,0], 'parent');
const child = entity('Child', {mesh:{type:'box'}, material:{color:'#00ff00',alpha:1}}, [2,0,0], 'child');
child.parentId = parent.id; activeScene(p).entities = [parent,child];
try {
await r.load(p);
parent.transform.position = [3,0,0]; parent.components.material.roughness = .1;
await r.load(p);
const mat:any = r.nodes.get('child')!.getChildMeshes()[0].material;
assert.deepEqual(mat.albedoColor.asArray(), [0,1,0]); assert.equal(mat.alpha,1);
assert.equal((r.nodes.get('parent')!.getChildMeshes().find(m=>m.metadata.entityId==='parent')!.material as any).roughness,.1);
} finally { r.dispose(); }
});
import { sceneAnimationGlb } from './fixtures.ts';
test('imported material, morph, camera and light animation targets are independent per entity', async () => {
const r=runtime(), p=defaultProject(true), bytes=sceneAnimationGlb();
p.assets=[{id:'scene',name:'scene.glb',kind:'model',uri:'data:model/gltf-binary;base64,'+bytes.toString('base64')}];
activeScene(p).entities=['a','b'].map(id=>entity(id,{mesh:{type:'model',assetId:'scene'},...(id==='a'?{camera:{mode:'imported'},animator:{autoplay:'Scene'}}:{})},[0,0,0],id));
try {
await r.play(p);
assert.ok(!r.logs.some(l=>l.level==='error'),JSON.stringify(r.logs));
const a=r.containers.get('a')!, b=r.containers.get('b')!;
assert.equal(r.scene.activeCamera,a.cameras[0]);
const group=r.animations.get('a')![0];
assert.ok(group.isStarted,'autoplay starts the imported timeline');
group.pause(); group.goToFrame(group.to);
const am:any=a.materials[0], bm:any=b.materials[0];
const close=(value:number,expected:number)=>assert.ok(Math.abs(value-expected)<.0001,`${value} != ${expected}`);
close(am.metallic,.9);close(am.roughness,.8);close(am.albedoColor.b,1);close(am.alpha,.5);
close(bm.metallic,.1);close(bm.roughness,.2);close(bm.albedoColor.r,1);
close(a.cameras[0].fov,1.1);close(b.cameras[0].fov,.7);
close(a.cameras[1].orthoLeft!,-4);close(a.cameras[1].orthoRight!,4);
close(a.cameras[1].orthoBottom!,-3);close(a.cameras[1].orthoTop!,3);
close(a.lights[0].intensity,20);close(b.lights[0].intensity,10);
close(a.morphTargetManagers[0].getTarget(0).influence,1);
close(b.morphTargetManagers[0].getTarget(0).influence,0);
activeScene(p).entities=activeScene(p).entities.filter(n=>n.id==='b');
await r.stop(p);await r.load(p);
assert.equal(r.containers.has('a'),false);assert.equal(r.containers.get('b')!.meshes[0].isDisposed(),false);
} finally {r.dispose();}
});