katachi-runtime 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +29 -14
  2. package/package.json +1 -1
  3. package/stage.d.ts +1 -0
package/index.js CHANGED
@@ -1570,6 +1570,7 @@ class Vehicle extends Model {
1570
1570
  this.neon = new THREE4.Mesh(new THREE4.PlaneGeometry(size.x * 1.7, size.z * 1.35), new THREE4.MeshBasicMaterial({ map: glowTexture(), transparent: true, depthWrite: false }));
1571
1571
  this.neon.rotation.x = -Math.PI / 2;
1572
1572
  this.neon.position.set(center.x, box.min.y + size.y * 0.01, center.z);
1573
+ this.neon.userData.decoration = true;
1573
1574
  this.root.add(this.neon);
1574
1575
  }
1575
1576
  setColor(this.neon.material.color, color);
@@ -2145,28 +2146,42 @@ class ThumbnailRenderer {
2145
2146
  this.lighting.fit(radius);
2146
2147
  this.scene.add(model.root);
2147
2148
  try {
2148
- this.draw(model.name);
2149
+ this.draw(model);
2149
2150
  } finally {
2150
2151
  this.scene.remove(model.root);
2151
2152
  this.camera.clearViewOffset();
2152
2153
  }
2153
2154
  return new Promise((resolve, reject) => this.renderer.domElement.toBlob((blob) => blob ? resolve(blob) : reject(new Error(`Could not encode ${model.name}`)), `image/${this.format}`, WEBP_QUALITY));
2154
2155
  }
2155
- draw(name) {
2156
+ draw(model) {
2157
+ const decorations = [];
2158
+ model.root.traverse((object) => {
2159
+ if (object.visible && object.userData.decoration)
2160
+ decorations.push(object);
2161
+ });
2156
2162
  let frame = { x: 0, y: 0, side: this.size };
2157
- for (let pass = 1;; pass++) {
2158
- this.camera.setViewOffset(this.size, this.size, frame.x, frame.y, frame.side, frame.side);
2159
- this.renderer.render(this.scene, this.camera);
2160
- if (pass === FRAMING_PASSES)
2161
- return;
2162
- const fitted = this.fit(frame);
2163
- if (!fitted)
2164
- throw new Error(`${name} has nothing to show`);
2165
- const pixel = frame.side / this.size;
2166
- if (Math.max(Math.abs(fitted.x - frame.x), Math.abs(fitted.y - frame.y), Math.abs(fitted.side - frame.side)) < 2 * pixel)
2167
- return;
2168
- frame = fitted;
2163
+ for (const object of decorations)
2164
+ object.visible = false;
2165
+ try {
2166
+ for (let pass = 1;pass < FRAMING_PASSES; pass++) {
2167
+ this.shoot(frame);
2168
+ const fitted = this.fit(frame);
2169
+ if (!fitted)
2170
+ throw new Error(`${model.name} has nothing to show`);
2171
+ const pixel = frame.side / this.size;
2172
+ if (Math.max(Math.abs(fitted.x - frame.x), Math.abs(fitted.y - frame.y), Math.abs(fitted.side - frame.side)) < 2 * pixel)
2173
+ break;
2174
+ frame = fitted;
2175
+ }
2176
+ } finally {
2177
+ for (const object of decorations)
2178
+ object.visible = true;
2169
2179
  }
2180
+ this.shoot(frame);
2181
+ }
2182
+ shoot({ x, y, side }) {
2183
+ this.camera.setViewOffset(this.size, this.size, x, y, side, side);
2184
+ this.renderer.render(this.scene, this.camera);
2170
2185
  }
2171
2186
  fit(frame) {
2172
2187
  const { size, pixels } = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "katachi-runtime",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Show converted GTA V models in the browser with three.js.",
5
5
  "type": "module",
6
6
  "exports": {
package/stage.d.ts CHANGED
@@ -72,6 +72,7 @@ export declare class ThumbnailRenderer {
72
72
  /** Renders a model from `view`, filling the image. */
73
73
  render(model: Model, view?: readonly [number, number, number]): Promise<Blob>;
74
74
  private draw;
75
+ private shoot;
75
76
  private fit;
76
77
  /** Frees the renderer and its lighting. */
77
78
  dispose(): void;