Skip to content

Commit

Permalink
use bare "three" imports
Browse files Browse the repository at this point in the history
Previously we were importing from specific three/src files. Why change? Because:
    - we can still tree shake
    - we were actually (indeirectly) using bare imports before, too. E.g., ThreeStrap imports from "three/examples/jsm/controls/OrbitControls", and OrbitControls imports bare "three"
    - "three" seems like the more official import pattern; it's what is documented at https://threejs.org/docs/#manual/en/introduction/Installation

See also unconed/mathbox#49
  • Loading branch information
ChristopherChudzicki committed Jan 7, 2023
1 parent 549f4e6 commit 8c11573
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/binder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventDispatcher } from "three/src/core/EventDispatcher.js";
import { EventDispatcher } from "three";

export class Binder {
static bind(context, globals) {
Expand Down
2 changes: 1 addition & 1 deletion src/controls/VRControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* for more info.
*/

import { Matrix4 } from "three/src/math/Matrix4.js";
import { Matrix4 } from "three";

export class VRControls {
constructor(object, onError) {
Expand Down
4 changes: 1 addition & 3 deletions src/core/camera.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Camera } from "three/src/cameras/Camera.js";
import { OrthographicCamera } from "three/src/cameras/OrthographicCamera.js";
import { PerspectiveCamera } from "three/src/cameras/PerspectiveCamera.js";
import { Camera, OrthographicCamera, PerspectiveCamera } from "three";
import { Bootstrap } from "../bootstrap";

Bootstrap.registerPlugin("camera", {
Expand Down
2 changes: 1 addition & 1 deletion src/core/renderer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WebGL1Renderer } from "three/src/renderers/WebGL1Renderer.js";
import { WebGL1Renderer } from "three";
import { Bootstrap } from "../bootstrap";

Bootstrap.registerPlugin("renderer", {
Expand Down
2 changes: 1 addition & 1 deletion src/core/scene.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Scene } from "three/src/scenes/Scene.js";
import { Scene } from "three";
import { Bootstrap } from "../bootstrap";

Bootstrap.registerPlugin("scene", {
Expand Down
2 changes: 1 addition & 1 deletion src/extra/controls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PerspectiveCamera } from "three/src/cameras/PerspectiveCamera.js";
import { PerspectiveCamera } from "three";
import { Bootstrap } from "../bootstrap";

Bootstrap.registerPlugin("controls", {
Expand Down
3 changes: 1 addition & 2 deletions src/renderers/VRRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* @author wwwtyro https://github.com/wwwtyro
* @author unconed https://github.com/unconed
*/
import { PerspectiveCamera } from "three/src/cameras/PerspectiveCamera.js";
import { Vector3 } from "three/src/math/Vector3.js";
import { PerspectiveCamera, Vector3 } from "three";

export class VRRenderer {
constructor(renderer, hmd) {
Expand Down
3 changes: 1 addition & 2 deletions test/core/camera.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Threestrap from "../../src";
import { OrthographicCamera } from "three/src/cameras/OrthographicCamera.js";
import { PerspectiveCamera } from "three/src/cameras/PerspectiveCamera.js";
import { OrthographicCamera, PerspectiveCamera } from "three";

describe("camera", function () {
it("installs a perspective camera", function () {
Expand Down
4 changes: 1 addition & 3 deletions test/core/render.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as Threestrap from "../../src";
import { Scene } from "three";
import { PerspectiveCamera } from "three/src/cameras/PerspectiveCamera.js";

import { Scene, PerspectiveCamera } from "three";

describe("render", function () {
it("renders the scene on update", function () {
Expand Down
2 changes: 1 addition & 1 deletion test/core/renderer.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Threestrap from "../../src";
import { WebGL1Renderer } from "three/src/renderers/WebGL1Renderer.js";
import { WebGL1Renderer } from "three";

describe("renderer", function () {
it("installs the canvas into the body", function () {
Expand Down
2 changes: 1 addition & 1 deletion test/core/scene.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Threestrap from "../../src";
import { Scene } from "three/src/scenes/Scene.js";
import { Scene } from "three";

describe("scene", function () {
it("makes a scene", function () {
Expand Down
2 changes: 1 addition & 1 deletion test/extra/controls.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Threestrap from "../../src"
import { PerspectiveCamera } from "three/src/cameras/PerspectiveCamera.js";
import { PerspectiveCamera } from "three";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";


Expand Down
4 changes: 0 additions & 4 deletions webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ const library: Configuration = {
},
externals: {
three: "THREE",
"three/src/core/EventDispatcher.js": "THREE",
"three/src/renderers/WebGL1Renderer.js": "THREE",
"three/src/scenes/Scene.js": "THREE",
"three/src/cameras/PerspectiveCamera.js": "THREE",
},
optimization: {
minimize: true,
Expand Down

0 comments on commit 8c11573

Please sign in to comment.