Fyrestar / THREE.extendMaterial

Extending built-in materials, instances of ShaderMaterial and shader objects of onBeforeCompile.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problems with types

callumacrae opened this issue · comments

Hey!

I've been using and loving this library a tonne recently, but I've actually ended up forking as I was having problems with the types - e.g., if we take this line:

const myMaterial = THREE.extendMaterial(THREE.MeshPhongMaterial, {

This causes a type error, at least with r147, as the function itself doesn't extend THREE.Material (it would have to be an instance of to satisfy that). The below change seemed to fix it:

-function extend<T extends THREE.Material>(source: T, object) {
+function extend<T extends THREE.Material | typeof THREE.Material>(
+  source: T,
+  object
+) {

Also, this line doesn't survive minification:

name = source.prototype.type

After minification (at least with the minifier that I'm using), that value is undefined. I made quite a hacky change (see below), but I'm happy to explore further for a nicer one that doesn't waste CPU cycles!

-    name = source.prototype.type;
+    name = new source().type;

I'm happy to contribute fixes for everything I've found, but I had some questions about the structure of the project - there's three almost identical files in the src.extendMaterial directory, are they programatically built from something else or are changes made to all three files simultaneously? If the latter, is there any reason you've chosen this approach instead of either building the other two files from a typescript file, or having a separately maintained types file for one of the javascript files?

Also happy to add a CONTRIBUTING.md file with the info I find out from these questions haha

Thanks again for the brilliant library 😁