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

ACCESSOR_VECTOR3_NON_UNIT error on GLTF validator #36

Closed
abrman opened this issue Nov 10, 2022 · 2 comments
Closed

ACCESSOR_VECTOR3_NON_UNIT error on GLTF validator #36

abrman opened this issue Nov 10, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@abrman
Copy link

abrman commented Nov 10, 2022

Hey, I'm generating a single triangle test using the code below and running into ACCESSOR_VECTOR3_NON_UNIT in the glTF validator on https://gltf-viewer.donmccurdy.com/

import fs from "fs";
import {
    Scene, Node, Material, Mesh, Vertex, RGBColor, exportGLB 
 } from "gltf-js-utils";

const asset = new GLTFAsset();
const scene = new Scene();
asset.addScene(scene);

const node = new Node();
node.setTranslation(0, 0, 0);
node.setRotationRadians(0, 0, 0);
node.setScale(1, 1, 1);
scene.addNode(node);

const mesh = new Mesh();
mesh.material = [new Material()];
node.mesh = mesh;

const v1 = new Vertex();
v1.x = 0;
v1.y = 0;
v1.z = 0;
v1.u = 0;
v1.v = 0;

const v2 = new Vertex();
v2.x = 5;
v2.y = 5;
v2.z = 5;
v2.u = 0;
v2.v = 0;

const v3 = new Vertex();
v3.x = 5;
v3.y = 0;
v3.z = 0;
v3.u = 0;
v3.v = 0;

const faceColor = new RGBColor();
faceColor.r = 1.0;
faceColor.g = 1.0;
faceColor.b = 1.0;
const faceMaterialIndex = 0;

mesh.addFace(v1, v2, v3, faceColor, faceMaterialIndex);

( async () => {
    const glbArrayBuffer = await exportGLB(asset);
    fs.writeFileSync('./model.glb', Buffer.from(glbArrayBuffer))
})()

Am I doing something wrong?

Produced *.gltf file extracted using glTF VS code extension:

{
  "asset": {
    "version": "2.0",
    "copyright": "",
    "generator": "glTF-js-utils"
  },
  "scene": 0,
  "buffers": [
    {
      "uri": "model_data.bin",
      "byteLength": 96
    }
  ],
  "scenes": [
    {
      "nodes": [
        0
      ]
    }
  ],
  "nodes": [
    {
      "mesh": 0
    }
  ],
  "meshes": [
    {
      "primitives": [
        {
          "attributes": {
            "POSITION": 0,
            "NORMAL": 1,
            "TEXCOORD_0": 2
          },
          "mode": 4,
          "material": 0
        }
      ]
    }
  ],
  "materials": [
    {}
  ],
  "bufferViews": [
    {
      "buffer": 0,
      "byteLength": 36,
      "byteStride": 12,
      "byteOffset": 0
    },
    {
      "buffer": 0,
      "byteLength": 36,
      "byteStride": 12,
      "byteOffset": 36
    },
    {
      "buffer": 0,
      "byteLength": 24,
      "byteStride": 8,
      "byteOffset": 72
    }
  ],
  "accessors": [
    {
      "bufferView": 0,
      "byteOffset": 0,
      "componentType": 5126,
      "count": 3,
      "type": "VEC3",
      "min": [
        0,
        0,
        0
      ],
      "max": [
        5,
        5,
        5
      ]
    },
    {
      "bufferView": 1,
      "byteOffset": 0,
      "componentType": 5126,
      "count": 3,
      "type": "VEC3",
      "min": [
        0,
        0,
        0
      ],
      "max": [
        0,
        0,
        0
      ]
    },
    {
      "bufferView": 2,
      "byteOffset": 0,
      "componentType": 5126,
      "count": 3,
      "type": "VEC2",
      "min": [
        0,
        0
      ],
      "max": [
        0,
        0
      ]
    }
  ]
}

Error report:

{
    "uri": "model.glb",
    "mimeType": "model/gltf-binary",
    "validatorVersion": "2.0.0-dev.3.8",
    "validatedAt": "2022-11-10T18:22:19.726Z",
    "issues": {
        "numErrors": 3,
        "numWarnings": 0,
        "numInfos": 1,
        "numHints": 3,
        "messages": [
            {
                "code": "BUFFER_VIEW_TARGET_MISSING",
                "message": "bufferView.target should be set for vertex or index data.",
                "severity": 3,
                "pointer": "/meshes/0/primitives/0/attributes/POSITION"
            },
            {
                "code": "BUFFER_VIEW_TARGET_MISSING",
                "message": "bufferView.target should be set for vertex or index data.",
                "severity": 3,
                "pointer": "/meshes/0/primitives/0/attributes/NORMAL"
            },
            {
                "code": "BUFFER_VIEW_TARGET_MISSING",
                "message": "bufferView.target should be set for vertex or index data.",
                "severity": 3,
                "pointer": "/meshes/0/primitives/0/attributes/TEXCOORD_0"
            },
            {
                "code": "UNUSED_OBJECT",
                "message": "This object may be unused.",
                "severity": 2,
                "pointer": "/meshes/0/primitives/0/attributes/TEXCOORD_0"
            },
            {
                "code": "ACCESSOR_VECTOR3_NON_UNIT",
                "message": "Vector3 at accessor indices 0..2 is not of unit length: 0.",
                "severity": 0,
                "pointer": "/meshes/0/primitives/0/attributes/NORMAL"
            },
            {
                "code": "ACCESSOR_VECTOR3_NON_UNIT",
                "message": "Vector3 at accessor indices 3..5 is not of unit length: 0.",
                "severity": 0,
                "pointer": "/meshes/0/primitives/0/attributes/NORMAL"
            },
            {
                "code": "ACCESSOR_VECTOR3_NON_UNIT",
                "message": "Vector3 at accessor indices 6..8 is not of unit length: 0.",
                "severity": 0,
                "pointer": "/meshes/0/primitives/0/attributes/NORMAL"
            }
        ],
        "truncated": false
    },
    "info": {
        "version": "2.0",
        "generator": "glTF-js-utils",
        "resources": [
            {
                "pointer": "/buffers/0",
                "mimeType": "application/gltf-buffer",
                "storage": "glb",
                "byteLength": 96
            }
        ],
        "animationCount": 0,
        "materialCount": 1,
        "hasMorphTargets": false,
        "hasSkins": false,
        "hasTextures": false,
        "hasDefaultScene": true,
        "drawCallCount": 1,
        "totalVertexCount": 3,
        "totalTriangleCount": 1,
        "maxUVs": 1,
        "maxInfluences": 0,
        "maxAttributes": 3
    }
}
@wnayes wnayes added the bug Something isn't working label Nov 11, 2022
@wnayes
Copy link
Owner

wnayes commented Nov 11, 2022

I think this is because normalX, normalY, and normalZ are not specified for any of the vertices, but this library still adds NORMAL data to the model. The normals are supposed to be unit vectors.

This seems like a valid issue report for this project. normalX, normalY, and normalZ should probably be changed to be undefined by default, and if normals are not defined across all vertices, the NORMAL data should be left out.

@abrman
Copy link
Author

abrman commented Nov 11, 2022

That sounds like a great explanation on what needs to be done. I have since reporting figured out a solution using @gltf-transform/core, if I wouldn't have, I'd try make a PR with the fix from your comment. - Needed to build something that could generate a model for web from a LandXML surface (used in civil engineering).
Thank you

@wnayes wnayes closed this as completed in 6dacb78 Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants