Commit 79420f47 authored by Piotr Bialecki's avatar Piotr Bialecki Committed by Commit Bot

WebXR - AR - move anchor creation from session to frame

Updates the Anchors API to align with changes proposed in the
immersive-web CG repository:
https://github.com/immersive-web/anchors/pull/29

Change-Id: I1ebc332c1f4b00c8912bf132f924ffa3f383dfa8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2051394Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Commit-Queue: Piotr Bialecki <bialpio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740830}
parent 53b01cdf
......@@ -85,7 +85,7 @@ XRViewerPose* XRFrame::getViewerPose(XRReferenceSpace* reference_space,
}
XRAnchorSet* XRFrame::trackedAnchors() const {
return session_->trackedAnchors();
return session_->TrackedAnchors();
}
// Return an XRPose that has a transform of basespace_from_space, while
......@@ -160,6 +160,22 @@ XRFrame::getHitTestResultsForTransientInput(
return hit_test_source->Results();
}
ScriptPromise XRFrame::createAnchor(ScriptState* script_state,
XRRigidTransform* initial_pose,
XRSpace* space,
ExceptionState& exception_state) {
DVLOG(2) << __func__;
if (!is_active_) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
kInactiveFrame);
return {};
}
return session_->CreateAnchor(script_state, initial_pose, space, nullptr,
exception_state);
}
void XRFrame::Trace(blink::Visitor* visitor) {
visitor->Trace(session_);
visitor->Trace(world_information_);
......
......@@ -23,6 +23,7 @@ class XRHitTestSource;
class XRInputSource;
class XRPose;
class XRReferenceSpace;
class XRRigidTransform;
class XRSession;
class XRSpace;
class XRTransientInputHitTestResult;
......@@ -60,6 +61,11 @@ class XRFrame final : public ScriptWrappable {
XRTransientInputHitTestSource* hit_test_source,
ExceptionState& exception_state);
ScriptPromise createAnchor(ScriptState* script_state,
XRRigidTransform* initial_pose,
XRSpace* space,
ExceptionState& exception_state);
private:
std::unique_ptr<TransformationMatrix> GetAdjustedPoseMatrix(XRSpace*) const;
XRPose* GetTargetRayPose(XRInputSource*, XRSpace*) const;
......
......@@ -15,6 +15,7 @@
[RuntimeEnabled=WebXRIncubations] readonly attribute XRWorldInformation worldInformation;
[RuntimeEnabled=WebXRIncubations] readonly attribute XRAnchorSet trackedAnchors;
[RuntimeEnabled=WebXRIncubations, CallWith=ScriptState, RaisesException] Promise<XRAnchor> createAnchor(XRRigidTransform initial_pose, XRSpace space);
[RaisesException] XRViewerPose? getViewerPose(XRReferenceSpace referenceSpace);
[RaisesException] XRPose? getPose(XRSpace space, XRSpace relativeTo);
......
......@@ -379,7 +379,7 @@ const String XRSession::visibilityState() const {
}
}
XRAnchorSet* XRSession::trackedAnchors() const {
XRAnchorSet* XRSession::TrackedAnchors() const {
DVLOG(3) << __func__;
HeapHashSet<Member<XRAnchor>> result;
......@@ -655,15 +655,6 @@ ScriptPromise XRSession::CreateAnchor(
return promise;
}
ScriptPromise XRSession::createAnchor(
ScriptState* script_state,
XRRigidTransform* offset_space_from_anchor_transform,
XRSpace* offset_space,
ExceptionState& exception_state) {
return CreateAnchor(script_state, offset_space_from_anchor_transform,
offset_space, nullptr, exception_state);
}
int XRSession::requestAnimationFrame(V8XRFrameRequestCallback* callback) {
TRACE_EVENT0("gpu", __func__);
// Don't allow any new frame requests once the session is ended.
......
......@@ -108,7 +108,7 @@ class XRSession final
XRRenderState* renderState() const { return render_state_; }
XRWorldTrackingState* worldTrackingState() { return world_tracking_state_; }
XRSpace* viewerSpace() const;
XRAnchorSet* trackedAnchors() const;
XRAnchorSet* TrackedAnchors() const;
bool immersive() const;
......@@ -128,12 +128,6 @@ class XRSession final
const String& type,
ExceptionState&);
// IDL-exposed
ScriptPromise createAnchor(ScriptState* script_state,
XRRigidTransform* initial_pose,
XRSpace* space,
ExceptionState& exception_state);
// helper, not IDL-exposed
ScriptPromise CreateAnchor(ScriptState* script_state,
XRRigidTransform* pose,
......
......@@ -55,9 +55,6 @@ enum XRVisibilityState {
[RuntimeEnabled=WebXRIncubations] readonly attribute XRWorldTrackingState worldTrackingState;
[RuntimeEnabled=WebXRIncubations, RaisesException] void updateWorldTrackingState(optional XRWorldTrackingStateInit state = {});
[RuntimeEnabled=WebXRIncubations] readonly attribute XRAnchorSet trackedAnchors;
[RuntimeEnabled=WebXRIncubations, CallWith=ScriptState, RaisesException] Promise<XRAnchor> createAnchor(XRRigidTransform initial_pose, XRSpace space);
[CallWith=ScriptState, Measure, RaisesException] Promise<void> end();
// https://github.com/immersive-web/hit-test/blob/master/hit-testing-explainer.md
......
......@@ -11193,6 +11193,7 @@ interface XRFrame
getter trackedAnchors
getter worldInformation
method constructor
method createAnchor
method getHitTestResults
method getHitTestResultsForTransientInput
method getPose
......@@ -11327,12 +11328,10 @@ interface XRSession : EventTarget
getter onselectstart
getter onvisibilitychange
getter renderState
getter trackedAnchors
getter visibilityState
getter worldTrackingState
method cancelAnimationFrame
method constructor
method createAnchor
method end
method requestAnimationFrame
method requestHitTest
......
......@@ -347,12 +347,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}
// Creates new anchor for object and places it there.
function addARObjectAt(session, frame, plane, pose, space) {
function addARObjectAt(frame, plane, pose, space) {
console.debug("Creating anchor", pose, space);
if(plane != null) {
plane.createAnchor(pose, space).then(onCreateAnchor);
} else {
session.createAnchor(pose, space).then(onCreateAnchor);
frame.createAnchor(pose, space).then(onCreateAnchor);
}
}
......@@ -361,16 +361,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// If we're using the reticle then we've already got a mesh positioned
// at the latest hit point and we should just use it's matrix to save
// an unnecessary requestHitTest call.
addARObjectAt(event.frame.session,
event.frame,
addARObjectAt(event.frame,
arObject.plane,
new XRRigidTransform(arObject.hitPoint),
arObject.space);
} else {
if(!event.frame.worldInformation.detectedPlanes) {
console.log("No planes detected, placing an anchor at origin.");
addARObjectAt(event.frame.session,
event.frame,
addARObjectAt(event.frame,
null,
new XRRigidTransform({x : 0, y : 0, z : 0, w : 1}),
xrRefSpace);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment