Skip to content

Commit

Permalink
[functions] Add tests for listTextureChannels, listTextureSlots (donm…
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored Apr 7, 2022
1 parent 1b32fe0 commit 7379982
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
45 changes: 43 additions & 2 deletions packages/functions/test/list-texture-channels.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
require('source-map-support').install();

import test from 'tape';
import { Document, TextureChannel } from '@gltf-transform/core';
import { listTextureChannels, getTextureChannelMask } from '@gltf-transform/functions';
import { MaterialsSheen } from '@gltf-transform/extensions';

const { R, G, B, A } = TextureChannel;

test('@gltf-transform/functions::listTextureChannels', (t) => {
// TODO(test)
const document = new Document();
const textureA = document.createTexture();
const textureB = document.createTexture();
const sheenExtension = document.createExtension(MaterialsSheen);
const sheen = sheenExtension.createSheen().setSheenRoughnessTexture(textureB);
const material = document
.createMaterial()
.setAlphaMode('BLEND')
.setBaseColorTexture(textureA)
.setExtension('KHR_materials_sheen', sheen);

t.deepEquals(listTextureChannels(document, textureA), [R, G, B, A], 'baseColorTexture RGBA');
t.deepEquals(listTextureChannels(document, textureB), [A], 'sheenColorTexture A');

material.setAlphaMode('OPAQUE');
t.deepEquals(listTextureChannels(document, textureA), [R, G, B], 'baseColorTexture RGB');

sheen.setSheenColorTexture(textureB);
t.deepEquals(listTextureChannels(document, textureB), [R, G, B, A], 'sheenColorTexture RGBA');
t.end();
});

test('@gltf-transform/functions::getTextureChannelMask', (t) => {
// TODO(test)
const document = new Document();
const textureA = document.createTexture();
const textureB = document.createTexture();
const sheenExtension = document.createExtension(MaterialsSheen);
const sheen = sheenExtension.createSheen().setSheenRoughnessTexture(textureB);
const material = document
.createMaterial()
.setAlphaMode('BLEND')
.setBaseColorTexture(textureA)
.setExtension('KHR_materials_sheen', sheen);

t.equals(getTextureChannelMask(document, textureA), R | G | B | A, 'baseColorTexture RGBA');
t.equals(getTextureChannelMask(document, textureB), A, 'sheenColorTexture A');

material.setAlphaMode('OPAQUE');
t.equals(getTextureChannelMask(document, textureA), R | G | B, 'baseColorTexture RGB');

sheen.setSheenColorTexture(textureB);
t.equals(getTextureChannelMask(document, textureB), R | G | B | A, 'sheenColorTexture RGBA');
t.end();
});
12 changes: 11 additions & 1 deletion packages/functions/test/list-texture-slots.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
require('source-map-support').install();

import test from 'tape';
import { Document } from '@gltf-transform/core';
import { listTextureSlots } from '@gltf-transform/functions';
import { MaterialsSheen } from '@gltf-transform/extensions';

test('@gltf-transform/functions::listTextureSlots', (t) => {
// TODO(test)
const document = new Document();
const textureA = document.createTexture();
const textureB = document.createTexture();
const sheenExtension = document.createExtension(MaterialsSheen);
const sheen = sheenExtension.createSheen().setSheenColorTexture(textureB);
document.createMaterial().setBaseColorTexture(textureA).setExtension('KHR_materials_sheen', sheen);
t.deepEquals(listTextureSlots(document, textureA), ['baseColorTexture'], 'baseColorTexture');
t.deepEquals(listTextureSlots(document, textureB), ['sheenColorTexture'], 'sheenColorTexture');
t.end();
});

0 comments on commit 7379982

Please sign in to comment.