Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: custom vertex attributes #971

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 21 additions & 193 deletions samples/test_e2e/FastestInstancedDrawingWebGL1/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,8 @@ declare const Rn: typeof _Rn;
const indices = new Uint16Array([
// 0, 1, 2, 2, 3, 0

3,
1,
0,
2,
1,
3,
4,
5,
7,
7,
5,
6,
8,
9,
11,
11,
9,
10,
15,
13,
12,
14,
13,
15,
19,
17,
16,
18,
17,
19,
20,
21,
23,
23,
21,
22,
3, 1, 0, 2, 1, 3, 4, 5, 7, 7, 5, 6, 8, 9, 11, 11, 9, 10, 15, 13, 12, 14,
13, 15, 19, 17, 16, 18, 17, 19, 20, 21, 23, 23, 21, 22,
]);

const positions = new Float32Array([
Expand All @@ -73,174 +39,38 @@ declare const Rn: typeof _Rn;
// -1, 1, 0.0

// upper
-1,
1,
-1,
1,
1,
-1,
1,
1,
1,
-1,
1,
1,
-1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1,
// lower
-1,
-1,
-1,
1,
-1,
-1,
1,
-1,
1,
-1,
-1,
1,
-1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1,
// front
-1,
-1,
1,
1,
-1,
1,
1,
1,
1,
-1,
1,
1,
-1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1,
// back
-1,
-1,
-1,
1,
-1,
-1,
1,
1,
-1,
-1,
1,
-1,
-1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1,
// right
1,
-1,
-1,
1,
-1,
1,
1,
1,
1,
1,
1,
-1,
1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1,
// left
-1,
-1,
-1,
-1,
-1,
1,
-1,
1,
1,
-1,
1,
-1,
-1, -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1,
]);

const colors = new Float32Array([
0.0,
1.0,
1.0,
1.0,
1.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,

0.0,
1.0,
1.0,
1.0,
1.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,

0.0,
1.0,
1.0,
1.0,
1.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,

0.0,
1.0,
1.0,
1.0,
1.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,

0.0,
1.0,
1.0,
1.0,
1.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,

0.0,
1.0,
1.0,
1.0,
1.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,

0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,

0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,

0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,

0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,

0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
]);

const primitive = Rn.Primitive.createPrimitive({
indices: indices,
attributeCompositionTypes: [
Rn.CompositionType.Vec3,
Rn.CompositionType.Vec3,
],
attributeSemantics: [
Rn.VertexAttribute.Position,
Rn.VertexAttribute.Color0,
Rn.VertexAttribute.Position.XYZ,
Rn.VertexAttribute.Color0.XYZ,
],
attributes: [positions, colors],
primitiveMode: Rn.PrimitiveMode.Triangles,
Expand Down Expand Up @@ -360,7 +190,5 @@ declare const Rn: typeof _Rn;
})();

window.exportGltf2 = function () {


Rn.Gltf2Exporter.export('Rhodonite');
};
4 changes: 3 additions & 1 deletion samples/test_e2e/GltfImporter-morphing/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ declare const Rn: typeof _Rn;
Rn.LightComponent,
]);
lightEntity.getLight().intensity = Rn.Vector3.fromCopyArray([0.4, 0.9, 0.7]);
lightEntity.getTransform().translate = Rn.Vector3.fromCopyArray([4.0, 0.0, 5.0]);
lightEntity.getTransform().translate = Rn.Vector3.fromCopyArray([
4.0, 0.0, 5.0,
]);

let count = 0;
Rn.AnimationComponent.globalTime = 3.6;
Expand Down
22 changes: 22 additions & 0 deletions src/foundation/definitions/CompositionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,27 @@ function fromString(str: string): CompositionTypeEnum {
return _fromString({typeList, str}) as CompositionTypeEnum;
}

function vectorFrom(componentN: number): CompositionTypeEnum {
let str = '';
switch (componentN) {
case 1:
str = 'scalar';
break;
case 2:
str = 'vec2';
break;
case 3:
str = 'vec3';
break;
case 4:
str = 'vec4';
break;
default:
console.error('not found appropreate Vectors');
}
return _fromString({typeList, str}) as CompositionTypeEnum;
}

function fromGlslString(str_: string): CompositionTypeEnum {
let str = str_;
switch (str_) {
Expand Down Expand Up @@ -441,6 +462,7 @@ export const CompositionType = Object.freeze({
TextureCube,
from,
fromString,
vectorFrom,
fromGlslString,
isArray,
isTexture,
Expand Down
13 changes: 6 additions & 7 deletions src/foundation/definitions/ShaderSemantics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export interface ShaderSemanticsEnum extends EnumIO {

export class ShaderSemanticsClass
extends EnumClass
implements ShaderSemanticsEnum {
implements ShaderSemanticsEnum
{
private static __indexCount = -1;
static readonly _scale = 10000;
private static __classes: ShaderSemanticsClass[] = [];
Expand Down Expand Up @@ -153,9 +154,8 @@ const SkinningMode: ShaderSemanticsEnum = new ShaderSemanticsClass({
const GeneralTexture: ShaderSemanticsEnum = new ShaderSemanticsClass({
str: 'generalTexture',
});
const VertexAttributesExistenceArray: ShaderSemanticsEnum = new ShaderSemanticsClass(
{str: 'vertexAttributesExistenceArray'}
);
const VertexAttributesExistenceArray: ShaderSemanticsEnum =
new ShaderSemanticsClass({str: 'vertexAttributesExistenceArray'});
const BoneQuaternion: ShaderSemanticsEnum = new ShaderSemanticsClass({
str: 'boneQuaternion',
});
Expand Down Expand Up @@ -216,9 +216,8 @@ const EntityUID: ShaderSemanticsEnum = new ShaderSemanticsClass({
const MorphTargetNumber: ShaderSemanticsEnum = new ShaderSemanticsClass({
str: 'morphTargetNumber',
});
const DataTextureMorphOffsetPosition: ShaderSemanticsEnum = new ShaderSemanticsClass(
{str: 'dataTextureMorphOffsetPosition'}
);
const DataTextureMorphOffsetPosition: ShaderSemanticsEnum =
new ShaderSemanticsClass({str: 'dataTextureMorphOffsetPosition'});
const MorphWeights: ShaderSemanticsEnum = new ShaderSemanticsClass({
str: 'morphWeights',
});
Expand Down
9 changes: 3 additions & 6 deletions src/foundation/definitions/VertexAttribute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ test('Vertex Attributes with Positions', async () => {
expect(position3).toStrictEqual(['POSITION.X', 'POSITION.Y', 'POSITION.Z']);

const position4 = VertexAttribute.Position.XYZW;
expect(position4).toStrictEqual([
'POSITION.X',
'POSITION.Y',
'POSITION.Z',
'POSITION.W',
]);
expect(position4).toStrictEqual(
'POSITION.X,POSITION.Y,POSITION.Z,POSITION.W'
);
});

test('Custom Vertex Layout contains Positions, Normals and Texcoords', async () => {
Expand Down
Loading