Changeset 271941 in webkit
- Timestamp:
- Jan 27, 2021 3:04:16 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r271940 r271941 1 2021-01-27 Imanol Fernandez <ifernandez@igalia.com> 2 3 Complete WebXRRigidTransform implementation 4 https://bugs.webkit.org/show_bug.cgi?id=220732 5 <rdar://problem/73617302> 6 7 Reviewed by Sergio Villar Senin. 8 9 Enable XRRigidTransform WebXR tests. 10 11 * platform/wpe/TestExpectations: 12 1 13 2021-01-27 Youenn Fablet <youenn@apple.com> 2 14 -
trunk/LayoutTests/imported/w3c/ChangeLog
r271936 r271941 1 2021-01-27 Imanol Fernandez <ifernandez@igalia.com> 2 3 Complete WebXRRigidTransform implementation 4 https://bugs.webkit.org/show_bug.cgi?id=220732 5 <rdar://problem/73617302> 6 7 Reviewed by Sergio Villar Senin. 8 9 Enable XRRigidTransform WebXR tests. 10 11 * web-platform-tests/webxr/xrRigidTransform_inverse.https-expected.txt: Added. 12 * web-platform-tests/webxr/xrRigidTransform_matrix.https-expected.txt: Added. 13 1 14 2021-01-27 Youenn Fablet <youenn@apple.com> 2 15 -
trunk/LayoutTests/platform/wpe/TestExpectations
r271671 r271941 641 641 imported/w3c/web-platform-tests/webxr/xrFrame_session_sameObject.https.html [ Pass ] 642 642 imported/w3c/web-platform-tests/webxr/xrRigidTransform_constructor.https.html [ Pass ] 643 imported/w3c/web-platform-tests/webxr/xrRigidTransform_inverse.https.html [ Pass ] 644 imported/w3c/web-platform-tests/webxr/xrRigidTransform_matrix.https.html [ Pass ] 643 645 imported/w3c/web-platform-tests/webxr/xrSession_prevent_multiple_exclusive.https.html [ Pass ] 644 646 imported/w3c/web-platform-tests/webxr/render_state_vertical_fov_immersive.https.html [ Pass ] -
trunk/Source/WebCore/ChangeLog
r271939 r271941 1 2021-01-27 Imanol Fernandez <ifernandez@igalia.com> 2 3 Complete WebXRRigidTransform implementation 4 https://bugs.webkit.org/show_bug.cgi?id=220732 5 <rdar://problem/73617302> 6 7 Reviewed by Sergio Villar Senin. 8 9 - Implement XRRigidTransform.inverse(). 10 - Expose raw matrix to be used in other WebXR math calculations (e.g pose composition). 11 - Correctly lazily initialize and reuse the Float32Array matrixData. 12 13 Tested by the WebXR platform tests. 14 15 * Modules/webxr/WebXRRigidTransform.cpp: 16 (WebCore::normalizeQuaternion): 17 (WebCore::WebXRRigidTransform::create): 18 (WebCore::WebXRRigidTransform::WebXRRigidTransform): 19 (WebCore::m_orientation): 20 (WebCore::m_rawTransform): 21 (WebCore::WebXRRigidTransform::matrix): 22 (WebCore::WebXRRigidTransform::inverse): 23 (WebCore::WebXRRigidTransform::rawTransform const): 24 * Modules/webxr/WebXRRigidTransform.h: 25 * platform/graphics/transforms/TransformationMatrix.cpp: 26 (WebCore::TransformationMatrix::fromQuaternion): 27 * platform/graphics/transforms/TransformationMatrix.h: 28 1 29 2021-01-27 Andy Estes <aestes@apple.com> 2 30 -
trunk/Source/WebCore/Modules/webxr/WebXRRigidTransform.cpp
r258498 r271941 36 36 namespace WebCore { 37 37 38 static bool normalizeQuaternion(DOMPointInit& q) 39 { 40 const double length = std::sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w); 41 if (WTF::areEssentiallyEqual<double>(length, 0)) 42 return false; 43 q.x /= length; 44 q.y /= length; 45 q.z /= length; 46 q.w /= length; 47 return true; 48 } 49 38 50 WTF_MAKE_ISO_ALLOCATED_IMPL(WebXRRigidTransform); 39 51 … … 42 54 return adoptRef(*new WebXRRigidTransform({ }, { })); 43 55 } 56 57 Ref<WebXRRigidTransform> WebXRRigidTransform::create(const TransformationMatrix& transform) 58 { 59 return adoptRef(*new WebXRRigidTransform(transform)); 60 } 61 44 62 45 63 ExceptionOr<Ref<WebXRRigidTransform>> WebXRRigidTransform::create(const DOMPointInit& position, const DOMPointInit& orientation) … … 59 77 // 7. Normalize x, y, z, and w components of transform’s orientation. 60 78 DOMPointInit orientationInit { orientation.x, orientation.y, orientation.z, orientation.w }; 61 { 62 double length = std::sqrt(orientationInit.x * orientationInit.x + orientationInit.y * orientationInit.y 63 + orientationInit.z * orientationInit.z + orientationInit.w * orientationInit.w); 64 if (WTF::areEssentiallyEqual<double>(length, 0)) 65 return Exception { InvalidStateError }; 66 67 orientationInit= { 68 orientationInit.x / length, orientationInit.y / length, 69 orientationInit.z / length, orientationInit.w / length, 70 }; 71 } 79 if (!normalizeQuaternion(orientationInit)) 80 return Exception { InvalidStateError }; 72 81 73 82 // 8. Return transform. … … 79 88 , m_orientation(DOMPointReadOnly::create(orientation)) 80 89 { 81 // FIXME: implement properly, per spec. 82 TransformationMatrix matrix; 83 auto matrixData = matrix.toColumnMajorFloatArray(); 84 m_matrix = Float32Array::create(matrixData.data(), matrixData.size()); 90 TransformationMatrix translation; 91 translation.translate3d(position.x, position.y, position.z); 92 auto rotation = TransformationMatrix::fromQuaternion(orientation.x, orientation.y, orientation.z, orientation.w); 93 m_rawTransform = translation * rotation; 94 } 95 96 WebXRRigidTransform::WebXRRigidTransform(const TransformationMatrix& transform) 97 : m_position(DOMPointReadOnly::create({ })) 98 , m_orientation(DOMPointReadOnly::create({ })) 99 , m_rawTransform(transform) 100 { 101 if (transform.isIdentity()) { 102 // TransformationMatrix::decompose returns a empty quaternion instead of unit quaternion for Identity. 103 // WebXR tests expect a unit quaternion for this case. 104 return; 105 } 106 107 TransformationMatrix::Decomposed4Type decomp = { }; 108 transform.decompose4(decomp); 109 110 m_position = DOMPointReadOnly::create(decomp.translateX, decomp.translateY, decomp.translateZ, 1.0f); 111 112 DOMPointInit orientationInit { -decomp.quaternionX, -decomp.quaternionY, -decomp.quaternionZ, decomp.quaternionW }; 113 normalizeQuaternion(orientationInit); 114 m_orientation = DOMPointReadOnly::create(orientationInit); 85 115 } 86 116 … … 97 127 } 98 128 99 Ref<Float32Array> WebXRRigidTransform::matrix() const 129 const Float32Array& WebXRRigidTransform::matrix() 100 130 { 101 auto matrix = Float32Array::create(16); 102 matrix->zeroFill(); 103 return matrix; 131 if (m_matrix && !m_matrix->isDetached()) 132 return *m_matrix; 133 134 // Lazily create matrix Float32Array. 135 auto matrixData = m_rawTransform.toColumnMajorFloatArray(); 136 m_matrix = Float32Array::create(matrixData.data(), matrixData.size()); 137 138 return *m_matrix; 104 139 } 105 140 106 Ref<WebXRRigidTransform> WebXRRigidTransform::inverse() const 141 const WebXRRigidTransform& WebXRRigidTransform::inverse() 107 142 { 108 // FIXME: implement properly. 109 return WebXRRigidTransform::create(); 143 // The inverse of a inverse object should return the original object. 144 if (m_parentInverse) 145 return *m_parentInverse; 146 147 // Inverse should always return the same object. 148 if (m_inverse) 149 return *m_inverse; 150 151 auto inverseTransform = m_rawTransform.inverse(); 152 ASSERT(!!inverseTransform); 153 154 m_inverse = WebXRRigidTransform::create(*inverseTransform); 155 // The inverse of a inverse object should return the original object. 156 m_inverse->m_parentInverse = makeWeakPtr(this); 157 158 return *m_inverse; 159 } 160 161 const TransformationMatrix& WebXRRigidTransform::rawTransform() const 162 { 163 return m_rawTransform; 110 164 } 111 165 -
trunk/Source/WebCore/Modules/webxr/WebXRRigidTransform.h
r270067 r271941 29 29 30 30 #include "ExceptionOr.h" 31 #include "TransformationMatrix.h" 31 32 #include <JavaScriptCore/Float32Array.h> 32 33 #include <wtf/IsoMalloc.h> 33 34 #include <wtf/RefCounted.h> 35 #include <wtf/WeakPtr.h> 34 36 35 37 namespace WebCore { … … 38 40 class DOMPointReadOnly; 39 41 40 class WebXRRigidTransform : public RefCounted<WebXRRigidTransform> {42 class WebXRRigidTransform : public RefCounted<WebXRRigidTransform>, public CanMakeWeakPtr<WebXRRigidTransform> { 41 43 WTF_MAKE_ISO_ALLOCATED_EXPORT(WebXRRigidTransform, WEBCORE_EXPORT); 42 44 public: 43 45 static Ref<WebXRRigidTransform> create(); 46 static Ref<WebXRRigidTransform> create(const TransformationMatrix&); 44 47 WEBCORE_EXPORT static ExceptionOr<Ref<WebXRRigidTransform>> create(const DOMPointInit&, const DOMPointInit&); 45 48 WEBCORE_EXPORT ~WebXRRigidTransform(); … … 47 50 const DOMPointReadOnly& position() const; 48 51 const DOMPointReadOnly& orientation() const; 49 Ref<Float32Array> matrix() const; 50 Ref<WebXRRigidTransform> inverse() const; 52 const Float32Array& matrix(); 53 const WebXRRigidTransform& inverse(); 54 const TransformationMatrix& rawTransform() const; 51 55 52 56 private: 53 57 WebXRRigidTransform(const DOMPointInit&, const DOMPointInit&); 58 WebXRRigidTransform(const TransformationMatrix&); 54 59 55 60 Ref<DOMPointReadOnly> m_position; 56 61 Ref<DOMPointReadOnly> m_orientation; 62 TransformationMatrix m_rawTransform; 57 63 RefPtr<Float32Array> m_matrix; 64 RefPtr<WebXRRigidTransform> m_inverse; 65 WeakPtr<WebXRRigidTransform> m_parentInverse; 58 66 }; 59 67 -
trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp
r270801 r271941 579 579 { 580 580 setMatrix(t.a(), t.b(), t.c(), t.d(), t.e(), t.f()); 581 } 582 583 584 // FIXME: Once https://bugs.webkit.org/show_bug.cgi?id=220856 is addressed we can reuse this function in TransformationMatrix::recompose4(). 585 TransformationMatrix TransformationMatrix::fromQuaternion(double qx, double qy, double qz, double qw) 586 { 587 const double xx = qx * qx; 588 const double yy = qy * qy; 589 const double zz = qz * qz; 590 const double xz = qx * qz; 591 const double xy = qx * qy; 592 const double yz = qy * qz; 593 const double xw = qw * qx; 594 const double yw = qw * qy; 595 const double zw = qw * qz; 596 597 return TransformationMatrix(1 - 2 * (yy + zz), 2 * (xy + zw), 2 * (xz - yw), 0, 598 2 * (xy - zw), 1 - 2 * (xx + zz), 2 * (yz + xw), 0, 599 2 * (xz + yw), 2 * (yz - xw), 1 - 2 * (xx + yy), 0, 600 0, 0, 0, 1); 581 601 } 582 602 -
trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h
r266513 r271941 119 119 120 120 WEBCORE_EXPORT TransformationMatrix(const AffineTransform&); 121 122 static TransformationMatrix fromQuaternion(double qx, double qy, double qz, double qw); 121 123 122 124 static const TransformationMatrix identity;
Note: See TracChangeset
for help on using the changeset viewer.