Coder Social home page Coder Social logo

Comments (1)

rohan-deshpande avatar rohan-deshpande commented on July 27, 2024

This was causing the following error when using the module via a script tag

Uncaught TypeError: Cannot read property 'type' of undefined
    at WebGLIndexedBufferRenderer.setIndex (three.js:15321)
    at WebGLRenderer.renderBufferDirect (three.js:22689)
    at renderObject (three.js:23343)
    at renderObjects (three.js:23313)
    at WebGLRenderer.render (three.js:23120)

The reason for this is most likely due to two versions of THREE existing, as the module uses it internally but it will also be on the window when included via a script tag.

    <script src="../js/three.min.js"></script>
    <script src="../js/three-proton.js"></script> <!-- three is being used here as well -->

The solution was to import three within the module from an internal compatibility module that will use window.THREE if it exists

const isBrowser = typeof window !== 'undefined' ? true : false;
const THREE = isBrowser && window.THREE ? window.THREE : require('three');

export const {
  BoxGeometry,
  Euler,
  Geometry,
  Mesh,
  MeshBasicMaterial,
  MeshLambertMaterial,
  OctahedronGeometry,
  SphereGeometry,
  Sprite,
  SpriteMaterial,
  Texture,
  TextureLoader,
  Vector3,
  AdditiveBlending,
  CustomBlending,
  MultiplyBlending,
  NoBlending,
  NormalBlending,
  SubtractiveBlending,
} = THREE;

The module will now always import from here internally which will ensure that it works in all of the following situations

  • Both this module and three are included on the page via script tags
  • This module is imported into a transpile target environment (ie., the app is being developed with something like webpack/parcel etc.,) and bundled for production

This has been resolved by #43

from three-nebula.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.