Matter-js: Question: how to texture the cloth/softbody example?

Created on 7 Mar 2017  路  7Comments  路  Source: liabru/matter-js

Hi @liabru,

I am attempting to add texture to each of the squares in the cloth example. I can see from enabling the wireframes that the cloth is actually a series of circles:

Imgur

When I apply a texture, I get:

Imgur

Which adds the textures to the circles with no cropping. The second screenshot highlights what I would like to do. If the cloth is stretched I would like for the texture to be applied to the warped square, not to the circle.

Is there a way to achieve this?

question

All 7 comments

Texturing a 'mesh' like this isn't built in (it's out of the scope of the project), so you'll need to write your own renderer to do this. I suggest reading the rendering wiki page. To render a textured mesh you could either use a 2d canvas with context.fillStyle set to a CanvasPattern (like in this example) or look into something like three.js.

Thanks for your reply, the fill style on the 2d canvas seems to be in the right direction!

Could u please show how to solve?

Perhaps you could use pixi.js as the renderer and matter.js for the physics?

Here is an example of pixi warping a snake texture
https://pixijs.io/examples/?v=next#/basics/textured-mesh.js

I solved it via applying PIXI.mesh.Plane to softBody but FPS became much lower.

@gevgeny can you provide a link to your solve? I鈥檇 like to see how you implemented it. Thanks and nice work!

Sorry I cannot publish source, but basic idea I have found here https://codepen.io/shshaw/pen/JbrQrW.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrspeaker picture mrspeaker  路  3Comments

ShadewEnder picture ShadewEnder  路  3Comments

liabru picture liabru  路  3Comments

kunchenguid picture kunchenguid  路  3Comments

maximilianberndt picture maximilianberndt  路  4Comments