Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
Is there a way to bind object and pattern in FabricJS

I have two object, a circle and a square with pattern inside on FabricJS canvas.

They're bound together using transformation so when the circle is scaling, rotating and moving the square is synced and do the same (using this tutorial).

bindObjects = (parent, child) => {
  var parentTransform = parent.calcTransformMatrix();
  var invertedParentTransform = fabric.util.invertTransform(parentTransform);
  var desiredTransform = fabric.util.multiplyTransformMatrices(invertedParentTransform, child.calcTransformMatrix());
  child.relationship = desiredTransform;
}

updateObjects = (parent, child) => {
  var newTransform = fabric.util.multiplyTransformMatrices( parent.calcTransformMatrix(), child.relationship);
  opt = fabric.util.qrDecompose(newTransform);
  child.set({
    flipX: false,
    flipY: false,
  });
  child.setPositionByOrigin(
    { x: opt.translateX, y: opt.translateY },
    'center',
    'center'
  );
  child.set(opt);
  child.setCoords();
}

// Main flow of canvas & objects creations

....

bindObjects(circle, square);

circle.on('moving', (e) => {
  updateObjects(circle, square);
})
circle.on('scaling', (e) => {
  updateObjects(circle, square);
})
circle.on('rotating', (e) => {
  updateObjects(circle, square);
})

Now i want to switch the binding, and bind the circle only with the pattern (that's inside the square) - so scaling, rotating and moving will only affect it.

All my try to switch between the square and the pattern, staticCanvas or the pattern image itself didn't work or throw an error of calcTransformMatrix not found in child object)

Is there a way to accomplish it?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!