Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

282
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda