Skip to content

Commit

Permalink
Trying to work around Chrome’s stricter Matrix handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh committed May 15, 2018
1 parent c0cad18 commit ffd0a4d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions framer/Layer.coffee
Expand Up @@ -447,7 +447,7 @@ class exports.Layer extends BaseClass
get: -> get: ->
if @force2d if @force2d
return @_matrix2d return @_matrix2d
return new Matrix() return Matrix.identity3d()
.translate(@x, @y, @z) .translate(@x, @y, @z)
.scale(@scale) .scale(@scale)
.scale(@scaleX, @scaleY, @scaleZ) .scale(@scaleX, @scaleY, @scaleZ)
Expand All @@ -463,7 +463,7 @@ class exports.Layer extends BaseClass
# matrix of layer transforms when 2d is forced # matrix of layer transforms when 2d is forced
@define "_matrix2d", @define "_matrix2d",
get: -> get: ->
return new Matrix() return Matrix.identity3d()
.translate(@x, @y) .translate(@x, @y)
.scale(@scale) .scale(@scale)
.scale(@scaleX, @scaleY) .scale(@scaleX, @scaleY)
Expand All @@ -474,7 +474,7 @@ class exports.Layer extends BaseClass
# matrix of layer transforms with transform origin applied # matrix of layer transforms with transform origin applied
@define "transformMatrix", @define "transformMatrix",
get: -> get: ->
return new Matrix() return Matrix.identity3d()
.translate(@originX * @width, @originY * @height) .translate(@originX * @width, @originY * @height)
.multiply(@matrix) .multiply(@matrix)
.translate(-@originX * @width, -@originY * @height) .translate(-@originX * @width, -@originY * @height)
Expand All @@ -484,7 +484,7 @@ class exports.Layer extends BaseClass
get: -> get: ->
parent = @parent or @context parent = @parent or @context
ppm = Utils.perspectiveMatrix(parent) ppm = Utils.perspectiveMatrix(parent)
return new Matrix() return Matrix.identity3d()
.multiply(ppm) .multiply(ppm)
.multiply(@transformMatrix) .multiply(@transformMatrix)


Expand Down
4 changes: 4 additions & 0 deletions framer/Matrix.coffee
Expand Up @@ -16,4 +16,8 @@ WebKitCSSMatrix::point = (point = {}) ->
y: (@m12 * x + @m22 * y + @m32 * z + @m42) / w y: (@m12 * x + @m22 * y + @m32 * z + @m42) / w
z: (@m13 * x + @m23 * y + @m33 * z + @m43) / w z: (@m13 * x + @m23 * y + @m33 * z + @m43) / w



WebKitCSSMatrix.identity3d = ->
return new WebKitCSSMatrix("matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)")

exports.Matrix = WebKitCSSMatrix exports.Matrix = WebKitCSSMatrix
5 changes: 3 additions & 2 deletions framer/Utils.coffee
Expand Up @@ -1325,7 +1325,8 @@ Utils.boundingFrame = (layer, rootContext=true) ->


Utils.perspectiveProjectionMatrix = (element) -> Utils.perspectiveProjectionMatrix = (element) ->
p = element.perspective p = element.perspective
m = new Matrix()
m = Matrix.identity3d()
m.m34 = -1 / p if p? and p isnt 0 m.m34 = -1 / p if p? and p isnt 0
return m return m


Expand All @@ -1334,7 +1335,7 @@ Utils.perspectiveMatrix = (element) ->
ox = element.perspectiveOriginX * element.width ox = element.perspectiveOriginX * element.width
oy = element.perspectiveOriginY * element.height oy = element.perspectiveOriginY * element.height
ppm = Utils.perspectiveProjectionMatrix(element) ppm = Utils.perspectiveProjectionMatrix(element)
return new Matrix() return Matrix.identity3d()
.translate(ox, oy) .translate(ox, oy)
.multiply(ppm) .multiply(ppm)
.translate(-ox, -oy) .translate(-ox, -oy)
Expand Down

0 comments on commit ffd0a4d

Please sign in to comment.