Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

279
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda