<commit_before>import Signal from "signals";
import { aabb } from "pex-geom";

const AttributesMap = {
  positions: "aPosition",
  normals: "aNormal",
  tangents: "aTangent",
  texCoords: "aTexCoord0",
  texCoords1: "aTexCoord1",
  uvs: "aTexCoord0",
  uvs2: "aTexCoord1",
  vertexColors: "aVertexColor",
  offsets: "aOffset",
  scales: "aScale",
  rotations: "aRotation",
  colors: "aColor",
  joints: "aJoint",
  weights: "aWeight",
};

const IndicesMap = {
  indices: "indices",
  cells: "indices",
};

class Geometry {
  constructor(opts) {
    this.type = "Geometry";
    this.enabled = true;
    this.changed = new Signal();
    this.bounds = aabb.create();

    this.primitive = opts.ctx.Primitive.Triangles;

    this.count = undefined;
    this._indices = null;
    this._attributes = {};

    this.set(opts);
  }

  init(entity) {
    this.entity = entity;
  }

  set(opts) {
    const ctx = opts.ctx || this.ctx;

    // This is a bit messy because indices will could ovewrite this.indices
    // so we have to use this._indices internally
    Object.assign(this, opts);

    for (let prop in opts) {
      const val = opts[prop];
      if (AttributesMap[prop]) {
        const attribName = AttributesMap[prop];
        let attrib = this._attributes[attribName];
        if (!attrib) {
          attrib = this._attributes[attribName] = {
            buffer: null,
            offset: 0,
            stride: 0,
            divisor: 0,
            type: undefined,
          };
        }
        const data = val.length !== undefined ? val : val.data;

        // TODO: test different type configurations
        if (data) {
          if (!attrib.buffer) {
            attrib.buffer = ctx.vertexBuffer({
              data,
              type: val.type || attrib.type,
            });
          } else {
            ctx.update(attrib.buffer, {
              data,
              type: val.type || attrib.type,
              offset: attrib.offset || 0,
            });
          }

          if (attribName === "aPosition") {
            // If we have list of vectors we can calculate bounding box otherwise
            // the user has to provide it
            if (data[0].length) {<commit_msg>fix: handle positions data passed as ArrayBuffer<commit_after>import Signal from "signals";
import { aabb } from "pex-geom";

const AttributesMap = {
  positions: "aPosition",
  normals: "aNormal",
  tangents: "aTangent",
  texCoords: "aTexCoord0",
  texCoords1: "aTexCoord1",
  uvs: "aTexCoord0",
  uvs2: "aTexCoord1",
  vertexColors: "aVertexColor",
  offsets: "aOffset",
  scales: "aScale",
  rotations: "aRotation",
  colors: "aColor",
  joints: "aJoint",
  weights: "aWeight",
};

const IndicesMap = {
  indices: "indices",
  cells: "indices",
};

class Geometry {
  constructor(opts) {
    this.type = "Geometry";
    this.enabled = true;
    this.changed = new Signal();
    this.bounds = aabb.create();

    this.primitive = opts.ctx.Primitive.Triangles;

    this.count = undefined;
    this._indices = null;
    this._attributes = {};

    this.set(opts);
  }

  init(entity) {
    this.entity = entity;
  }

  set(opts) {
    const ctx = opts.ctx || this.ctx;

    // This is a bit messy because indices will could ovewrite this.indices
    // so we have to use this._indices internally
    Object.assign(this, opts);

    for (let prop in opts) {
      const val = opts[prop];
      if (AttributesMap[prop]) {
        const attribName = AttributesMap[prop];
        let attrib = this._attributes[attribName];
        if (!attrib) {
          attrib = this._attributes[attribName] = {
            buffer: null,
            offset: 0,
            stride: 0,
            divisor: 0,
            type: undefined,
          };
        }
        const data = val.length !== undefined ? val : val.data;

        // TODO: test different type configurations
        if (data) {
          if (!attrib.buffer) {
            attrib.buffer = ctx.vertexBuffer({
              data,
              type: val.type || attrib.type,
            });
          } else {
            ctx.update(attrib.buffer, {
              data,
              type: val.type || attrib.type,
              offset: attrib.offset || 0,
            });
          }

          if (attribName === "aPosition") {
            // If we have list of vectors we can calculate bounding box otherwise
            // the user has to provide it
            if (data[0]?.length) {
{'fraction_non_alphanumeric': 0.12477477477477478, 'fraction_numerical': 0.004954954954954955, 'mean_word_length': 2.002704530087897, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '854224', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1345, 'n_words': 356}