Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XCD-147 Implement an example of annotation touch create #1654

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 121 additions & 116 deletions dist/xeokit-sdk.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11353,6 +11353,122 @@ function activateDraggableDots(cfg) {
};
}

const touchPointSelector$1 = function(viewer, pointerCircle, ray2WorldPos) {
return function(onCancel, onChange, onCommit) {
const scene = viewer.scene;
const canvas = scene.canvas.canvas;
const longTouchTimeoutMs = 300;
const moveTolerance = 20;

const copyCanvasPos = (event, vec2) => {
vec2[0] = event.clientX;
vec2[1] = event.clientY;
transformToNode(canvas.ownerDocument.documentElement, canvas, vec2);
return vec2;
};

const pickWorldPos = canvasPos => {
const origin = math.vec3();
const direction = math.vec3();
math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, canvasPos, origin, direction);
return ray2WorldPos(origin, direction);
};

let longTouchTimeout = null;
const nop = () => { };
let onSingleTouchMove = nop;
let startTouchIdentifier;

const resetAction = function() {
pointerCircle.stop();
clearTimeout(longTouchTimeout);
viewer.cameraControl.active = true;
onSingleTouchMove = nop;
startTouchIdentifier = null;
};

const cleanup = function() {
resetAction();
canvas.removeEventListener("touchstart", onCanvasTouchStart);
canvas.removeEventListener("touchmove", onCanvasTouchMove);
canvas.removeEventListener("touchend", onCanvasTouchEnd);
};

const onCanvasTouchStart = function(event) {
const touches = event.touches;

if (touches.length !== 1)
{
resetAction();
onCancel();
}
else
{
const startTouch = touches[0];
const startCanvasPos = copyCanvasPos(startTouch, math.vec2());

const startWorldPos = pickWorldPos(startCanvasPos);
if (startWorldPos)
{
startTouchIdentifier = startTouch.identifier;

onSingleTouchMove = canvasPos => {
if (math.distVec2(startCanvasPos, canvasPos) > moveTolerance)
{
resetAction();
}
};

longTouchTimeout = setTimeout(
function() {
pointerCircle.start(startCanvasPos);

longTouchTimeout = setTimeout(
function() {
pointerCircle.stop();

viewer.cameraControl.active = false;

onSingleTouchMove = canvasPos => {
onChange(canvasPos, pickWorldPos(canvasPos));
};

onSingleTouchMove(startCanvasPos);
},
longTouchTimeoutMs);
},
250);
}
}
};
canvas.addEventListener("touchstart", onCanvasTouchStart, {passive: true});

// canvas.addEventListener("touchcancel", e => console.log("touchcancel", e), {passive: true});

const onCanvasTouchMove = function(event) {
const touch = [...event.changedTouches].find(e => e.identifier === startTouchIdentifier);
if (touch)
{
onSingleTouchMove(copyCanvasPos(touch, math.vec2()));
}
};
canvas.addEventListener("touchmove", onCanvasTouchMove, {passive: true});

const onCanvasTouchEnd = function(event) {
const touch = [...event.changedTouches].find(e => e.identifier === startTouchIdentifier);
if (touch)
{
cleanup();
const canvasPos = copyCanvasPos(touch, math.vec2());
onCommit(canvasPos, pickWorldPos(canvasPos));
}
};
canvas.addEventListener("touchend", onCanvasTouchEnd, {passive: true});

return cleanup;
};
};

/** @private */
class Wire {

Expand Down Expand Up @@ -140519,122 +140635,6 @@ const mousePointSelector = function(viewer, ray2WorldPos) {
};
};

const touchPointSelector = function(viewer, pointerCircle, ray2WorldPos) {
return function(onCancel, onChange, onCommit) {
const scene = viewer.scene;
const canvas = scene.canvas.canvas;
const longTouchTimeoutMs = 300;
const moveTolerance = 20;

const copyCanvasPos = (event, vec2) => {
vec2[0] = event.clientX;
vec2[1] = event.clientY;
transformToNode(canvas.ownerDocument.documentElement, canvas, vec2);
return vec2;
};

const pickWorldPos = canvasPos => {
const origin = math.vec3();
const direction = math.vec3();
math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, canvasPos, origin, direction);
return ray2WorldPos(origin, direction);
};

let longTouchTimeout = null;
const nop = () => { };
let onSingleTouchMove = nop;
let startTouchIdentifier;

const resetAction = function() {
pointerCircle.stop();
clearTimeout(longTouchTimeout);
viewer.cameraControl.active = true;
onSingleTouchMove = nop;
startTouchIdentifier = null;
};

const cleanup = function() {
resetAction();
canvas.removeEventListener("touchstart", onCanvasTouchStart);
canvas.removeEventListener("touchmove", onCanvasTouchMove);
canvas.removeEventListener("touchend", onCanvasTouchEnd);
};

const onCanvasTouchStart = function(event) {
const touches = event.touches;

if (touches.length !== 1)
{
resetAction();
onCancel();
}
else
{
const startTouch = touches[0];
const startCanvasPos = copyCanvasPos(startTouch, math.vec2());

const startWorldPos = pickWorldPos(startCanvasPos);
if (startWorldPos)
{
startTouchIdentifier = startTouch.identifier;

onSingleTouchMove = canvasPos => {
if (math.distVec2(startCanvasPos, canvasPos) > moveTolerance)
{
resetAction();
}
};

longTouchTimeout = setTimeout(
function() {
pointerCircle.start(startCanvasPos);

longTouchTimeout = setTimeout(
function() {
pointerCircle.stop();

viewer.cameraControl.active = false;

onSingleTouchMove = canvasPos => {
onChange(canvasPos, pickWorldPos(canvasPos));
};

onSingleTouchMove(startCanvasPos);
},
longTouchTimeoutMs);
},
250);
}
}
};
canvas.addEventListener("touchstart", onCanvasTouchStart, {passive: true});

// canvas.addEventListener("touchcancel", e => console.log("touchcancel", e), {passive: true});

const onCanvasTouchMove = function(event) {
const touch = [...event.changedTouches].find(e => e.identifier === startTouchIdentifier);
if (touch)
{
onSingleTouchMove(copyCanvasPos(touch, math.vec2()));
}
};
canvas.addEventListener("touchmove", onCanvasTouchMove, {passive: true});

const onCanvasTouchEnd = function(event) {
const touch = [...event.changedTouches].find(e => e.identifier === startTouchIdentifier);
if (touch)
{
cleanup();
const canvasPos = copyCanvasPos(touch, math.vec2());
onCommit(canvasPos, pickWorldPos(canvasPos));
}
};
canvas.addEventListener("touchend", onCanvasTouchEnd, {passive: true});

return cleanup;
};
};

const planeIntersect = function(p0, n, origin, direction) {
const t = - (math.dotVec3(origin, n) - p0) / math.dotVec3(direction, n);
{
Expand Down Expand Up @@ -142010,6 +142010,7 @@ exports.DistanceMeasurementsControl = DistanceMeasurementsControl;
exports.DistanceMeasurementsMouseControl = DistanceMeasurementsMouseControl;
exports.DistanceMeasurementsPlugin = DistanceMeasurementsPlugin;
exports.DistanceMeasurementsTouchControl = DistanceMeasurementsTouchControl;
exports.Dot3D = Dot3D;
exports.DotBIMDefaultDataSource = DotBIMDefaultDataSource;
exports.DotBIMLoaderPlugin = DotBIMLoaderPlugin;
exports.EdgeMaterial = EdgeMaterial;
Expand Down Expand Up @@ -142152,6 +142153,8 @@ exports.ZonesPlugin = ZonesPlugin;
exports.ZonesPolysurfaceMouseControl = ZonesPolysurfaceMouseControl;
exports.ZonesPolysurfaceTouchControl = ZonesPolysurfaceTouchControl;
exports.ZonesTouchControl = ZonesTouchControl;
exports.activateDraggableDot = activateDraggableDot;
exports.activateDraggableDots = activateDraggableDots;
exports.buildBoxGeometry = buildBoxGeometry;
exports.buildBoxLinesGeometry = buildBoxLinesGeometry;
exports.buildBoxLinesGeometryFromAABB = buildBoxLinesGeometryFromAABB;
Expand All @@ -142178,6 +142181,8 @@ exports.rtcToWorldPos = rtcToWorldPos;
exports.sRGBEncoding = sRGBEncoding;
exports.setFrustum = setFrustum;
exports.stats = stats;
exports.touchPointSelector = touchPointSelector$1;
exports.transformToNode = transformToNode;
exports.utils = utils;
exports.worldToRTCPos = worldToRTCPos;
exports.worldToRTCPositions = worldToRTCPositions;
Loading
Loading