Trouble accessing methods in npm/typescript project – Goldberg Mesh

I am super impressed by your Goldberg polyhedra examples, here: https://playground.babylonjs.com/#A8VZGP#9

I would love to start using this in a game project. However, I am struggling to get access to the extended methods in my npm project (I have tried a variety of starter/template projects). Apologies if this is a rudimentary issue with my understanding of typescript, but I thought others may have the same issue.

This code from the playground referenced above is working:

const makeGoldberg = function(m, n) {
        const goldberg = BABYLON.MeshBuilder.CreateGoldberg("g", {m: m, n: n});
	    const colset = [];
	    colset.push([0, 11, new BABYLON.Color4(247 / 255, 150 / 255, 70 / 255, 1)]);
	    for (let k = 0; k < 12; k++) {
		    colset.push([goldberg.relFace(k, 0), goldberg.relFace(k, goldberg.nbFacesAtPole - 1), new BABYLON.Color4(k % 2, Math.floor(k / 2) % 2, Math.floor(k / 4), 1)]); 
	    }

        goldberg.setFaceColors(colset);
        return goldberg;
    }

My code (below) fails to recognize setFaceColors. I have forked and modified a git repo (GitHub - andrewcantos/babylonjs-typescript-webpack-starter: babylonjs-typescript-webpack-starter) to show this error.

The offending lines:

// create goldberg polyhedron
let goldberg = BABYLON.MeshBuilder.CreateGoldberg("goldberg", {m: 12, n: 2});
goldberg.setFaceColors([0, 10, new BABYLON.Color4(1, 0, 0, 1)]);

Error:
Property 'setFaceColors' does not exist on type 'Mesh'.

Babylonjs version: 5.0.0-alpha.65

Would be great if you can provide a repro as your code is also working on the playground: https://playground.babylonjs.com/#A8VZGP#32 so if the first one works in your project the second would normally do as well as they are both relying on the same exact API.

Thanks for the quick reply, the repo is linked in the original post. Cheers!

My bad… I thought you were linking the original template… I ll have a look quickly.

So currently all the Goldberg typings can not provide with what you need in TS. Let me fix that in the next nightly and push a new npm release.

2 Likes

Awesome, thanks very much for taking a look into this. It’s pretty impressive that the project has implemented the Goldberg polyhedrons.

1 Like

The PR is up Goldberg mesh update by sebavan · Pull Request #11684 · BabylonJS/Babylon.js · GitHub but it will require a careful review of @JohnK and I would need to update the doc accordingly

3 Likes

@sebavan has finished updating the code for creating and using Goldberg polys. It has necessitated some changes to how the properties and methods are used. The updated docs will be available available after the next build, which should be done fairly soon.

In the meantime here is a Typescript PG to indicate some of the changes https://playground.babylonjs.com/#A8VZGP#42

2 Likes