{"size": 836, "ext": "js", "max_stars_repo_path": "old/src/shared/part-brick.js", "max_stars_repo_name": "jsonxr/brickworld", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "old/src/shared/part-brick.js", "max_issues_repo_name": "jsonxr/brickworld", "max_issues_repo_issues_event_min_datetime": "2020-10-04T04:03:42.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T02:03:22.000Z", "max_forks_repo_path": "old/src/shared/part-brick.js", "max_forks_repo_name": "jsonxr/brickworld", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 15, "max_forks_count": null, "avg_line_length": 18.1739130435, "max_line_length": 65, "alphanum_fraction": 0.5789473684}
import PartTemplate from './part-template';

class PartBrick extends PartTemplate {
  constructor(options) {
    super(options);
    this._studs = null;
  }

  get studs() {
    return this._studs;
  }
  set studs(values) {
    if (this._studs) {
      throw new Error('studs have already been set.');
    }
    this._studs = values;
  }

  forEachStud(fn) {
    this._studs.forEach(fn);
  }

  toJSON() {
    const getArray = name => {
      const array = [];
      for (const value of this.geometry.attributes[name].array) {
        array.push(value);
      }
      return array;
    };

    const json = {
      id: this._id,
      name: this._name,
      type: this._type,
      positions: getArray('position'),
      normals: getArray('normal'),
      uvs: getArray('uv'),
    };

    return json;
  }
}

export default PartBrick;
