maximeq / three-js-capsule-geometry

A CapsuleBufferGeometry as a new geometry primitive for THREE.JS
MIT License
33 stars 3 forks source link

Fix request and docs request #2

Open crertel opened 5 years ago

crertel commented 5 years ago

Thank you for making this helper library!

It'd be really great if you updated the readme with how to use it in a project, especially if we're using webpack or ES6-style imports. It'd also be awesome if you published this to npm. :)

One thing that seems to be causing some trouble is here:

CapsuleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );

Does that maybe want to be:

CapsuleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
maximeq commented 5 years ago

Hi !

Thanks for the bug report. It's now fixed with an updated readme and an html example with parameters to play with.

Concerning the npm publish, it should come later. However, since I'm personally relying on three-full, I don't know if it will be suitable for other projects...

Let me know if things are still not clear enough.

crertel commented 5 years ago

I'm using three-full, and I keep having this issue where it's not showing up. Code looks like:

import { CapsuleBufferGeometry } from 'three-js-capsule-geometry/dist/browser/three-js-capsule-geometry.js';

// snip

case "capsule": geometry = new THREE.CapsuleBufferGeometry(body.end_radius,
                                                         body.end_radius,
                                                         body.axial_length,
                                                         1,
                                                         9,
                                                         5,
                                                         5,
                                                         0.0,
                                                         2* Math.PI); break;

But, it throws something like:

TypeError: three__WEBPACK_IMPORTED_MODULE_1__.CapsuleBufferGeometry is not a constructor
crertel commented 5 years ago

Oh, and my package.json bit looks like:

  "dependencies": {
    "phoenix": "file:../deps/phoenix",
    "phoenix_html": "file:../deps/phoenix_html",
    "three": "0.105.2",
    "threejs-orbit-controls": "1.0.3",
    "three-js-capsule-geometry": "maximeq/three-js-capsule-geometry"
  },
maximeq commented 5 years ago

I don't know about webpack, so not sure how to help. You are trying to import from a bundle made to be included in a webpage as standalone script, so I would not be surprise it cannot work.

You can do require("./three-js-capsule-geometry/src/exports.js") or require("./three-js-capsule-geometry"), which will fill THREE with THREE.CapsuleBufferGeometry, and return the object THREE.CapsuleBufferGeometry.

I'm not sure how to use the import syntax. Maybe something like : import * as CapsuleBufferGeometry from './three-js-capsule-geometry/src/exports.js';

maximeq commented 5 years ago

By the way, you're right that things would be easier with a npm published package. I will see if I can do that in the coming weeks.

But you should be able to make it work, worst case for now, you can just copy the CapsuleBufferGeometry file in your project and include it as any other of your own class.

crertel commented 5 years ago

I've got a workaround going, but thank you again for your help! ^_^