Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
x3domlet
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Elphel
x3domlet
Commits
65c3858d
Commit
65c3858d
authored
7 years ago
by
Oleg Dzhimiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. update pointer marker pars 2. camera dragging over map != dragging over scene?
parent
760d94bb
master
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
136 deletions
+99
-136
ui_init.js
js/ui_init.js
+22
-20
x3dom_functions.js
js/x3dom_functions.js
+36
-35
x3dom_init.js
js/x3dom_init.js
+41
-81
No files found.
js/ui_init.js
View file @
65c3858d
...
...
@@ -51,7 +51,7 @@ var SETTINGS = {
'moreinfo'
:
true
,
'crosshair'
:
false
,
'shiftspeed'
:
0.01
,
'markersize'
:
2
,
'markersize'
:
1
,
'markercolor'
:
"#1f1"
,
'slidingdrag'
:
true
,
'basepath'
:
"models"
,
...
...
@@ -474,8 +474,7 @@ function x3d_events(){
elem
.
addEventListener
(
'keydown'
,
function
(
e
){
//console.log("scene keydown");
// 'shift' is for shapes toggling
if
((
e
.
key
==
"Shift"
)
||
(
SETTINGS
.
highlight
&&!
SETTINGS
.
pointer
)){
// select shape
var
sr
=
elem
.
runtime
.
shootRay
(
e
.
path
[
0
].
mouse_drag_x
,
e
.
path
[
0
].
mouse_drag_y
);
...
...
@@ -487,8 +486,11 @@ function x3d_events(){
}
// sliding marker
if
(
e
.
key
==
"Control"
){
X3DOMObject
.
PointerMarker
.
updatePars
();
Scene
.
_ctrlKey
=
true
;
var
x
,
y
,
z
;
...
...
@@ -501,7 +503,10 @@ function x3d_events(){
dist
=
parseFloat
(
mouse
.
d_xz
);
X3DOMObject
.
Marker
.
place
(
mouse
.
x
,
mouse
.
y
,
mouse
.
z
,
"sliding_sphere"
);
if
(
Scene
.
highlighted_marker_index
==
null
)
$
(
"#sliding_sphere"
).
find
(
"switch"
).
attr
(
"whichChoice"
,
0
);
if
(
Scene
.
highlighted_marker_index
==
null
)
{
$
(
"#sliding_sphere"
).
find
(
"switch"
).
attr
(
"whichChoice"
,
0
);
}
}
...
...
@@ -513,8 +518,8 @@ function x3d_events(){
elem
.
addEventListener
(
'keyup'
,
function
(
e
){
// 'shift' is for shapes toggling
if
(
e
.
key
==
"Shift"
){
// select shape
var
sr
=
elem
.
runtime
.
shootRay
(
e
.
path
[
0
].
mouse_drag_x
,
e
.
path
[
0
].
mouse_drag_y
);
X3DOMObject
.
Shape
.
dehighlight
(
sr
.
pickObject
);
}
...
...
@@ -558,9 +563,11 @@ function x3d_events(){
//2: new
if
(
!
e
.
target
)
e
.
target
=
Scene
.
element
;
var
mouse_position
=
Scene
.
element
.
runtime
.
mousePosition
(
e
);
var
camera
=
x3dom_getCameraPosOr
(
mouse_position
[
0
],
mouse_position
[
1
],
false
);
// these functions belong to 'leaflet.camera-view-marker.js'
Map
.
marker
.
setAltitude
(
camera
.
y
);
Map
.
marker
.
setElevation
(
camera
.
e
*
Math
.
PI
/
180
);
...
...
@@ -569,6 +576,7 @@ function x3d_events(){
if
(
SETTINGS
.
highlight
&&!
SETTINGS
.
pointer
){
// this is for highlighting, no need to correct zNear bug
var
sr
=
elem
.
runtime
.
shootRay
(
e
.
path
[
0
].
mouse_drag_x
,
e
.
path
[
0
].
mouse_drag_y
);
X3DOMObject
.
Shape
.
highlight
(
sr
.
pickObject
);
...
...
@@ -576,22 +584,14 @@ function x3d_events(){
if
((
Scene
.
_ctrlKey
)
||
(
SETTINGS
.
pointer
)){
// show shadow marker
//1: old
//var mouse = x3dom_getXYPosOr(e.clientX,e.clientY,false);
//2: new
//if (!e.target) e.target = Scene.element;
//var mouse_position = Scene.element.runtime.mousePosition(e);
// sliding marker
var
mouse
=
x3dom_getXYPosOr
(
mouse_position
[
0
],
mouse_position
[
1
],
false
);
var
dist
=
parseFloat
(
mouse
.
d_xz
)
||
1116
;
Map
.
marker
.
placeSlidingMarker
(
mouse
.
a
,
dist
);
}
else
{
// hide s
hadow
marker
// hide s
liding
marker
Map
.
marker
.
removeSlidingMarker
();
}
...
...
@@ -685,6 +685,7 @@ function leaf_events(){
X3DOMObject
.
displayMarkInfo
(
Data
.
markers
.
length
-
1
);
// note: the 2nd place where marker is created is in x3dom_init.js (createNewMarker)
//new X3DOMObject.Marker(mark.x,mark.y,mark.z,true);
new
X3DOMObject
.
Marker
(
mark
.
x
,
mark
.
y
,
mark
.
z
,
false
);
...
...
@@ -731,6 +732,7 @@ function leaf_mouseup(e){
function
leaf_mousemove
(
e
){
var
Camera
=
Map
.
marker
;
if
(
Camera
.
draggedMarker
.
_index
!=
null
){
var
index
=
Camera
.
draggedMarker
.
_index
;
var
elem
=
$
(
"#my-sph-"
+
index
);
...
...
This diff is collapsed.
Click to expand it.
js/x3dom_functions.js
View file @
65c3858d
...
...
@@ -52,23 +52,26 @@ function x3dom_getXYPosOr(cnvx,cnvy,round){
var
elem
=
Scene
.
element
;
var
x
,
y
,
z
;
var
xc
,
yc
,
zc
;
var
az
,
el
,
sk
;
var
id
;
var
dist_xyz
=
1112
;
var
dist_xz
=
1113
;
//console.log("That event:");
//console.log(Scene._stored_x3dom_event);
var
valid_distance
;
// camera coordinates, not correcting with zNear
var
campos
=
x3dom_getCameraPosOr
();
var
xc
=
campos
.
x
;
var
yc
=
campos
.
y
;
var
zc
=
campos
.
z
;
xc
=
campos
.
x
;
yc
=
campos
.
y
;
zc
=
campos
.
z
;
// shoot ray based on canvas coordinates
// if hits a shape > .pickPosition and .pickObject
var
shootRay
=
elem
.
runtime
.
shootRay
(
cnvx
,
cnvy
);
var
valid_distance
=
true
;
// check infinity shape
if
(
shootRay
.
pickPosition
!=
null
){
if
(
$
(
shootRay
.
pickObject
).
hasClass
(
'INFINITY'
)){
...
...
@@ -80,75 +83,70 @@ function x3dom_getXYPosOr(cnvx,cnvy,round){
var
index
=
Scene
.
highlighted_marker_index
;
// didn't hit a marker?
if
(
index
==
null
){
// some marker being dragged but the mouse is not over it. If yes - update index
if
((
Scene
.
draggedTransformNode
!=
undefined
)
&&
(
Scene
.
draggedTransformNode
!=
null
)){
var
sphere
=
Scene
.
draggedTransformNode
.
parent
().
parent
();
index
=
parseInt
(
sphere
.
attr
(
"id"
).
substr
(
7
));
}
}
// didn't hit marker
if
((
index
==
null
)
||
(
Data
.
markers
[
index
]
==
undefined
)){
x
=
shootRay
.
pickPosition
.
x
;
y
=
shootRay
.
pickPosition
.
y
;
z
=
shootRay
.
pickPosition
.
z
;
var
xyz
=
zNear_bug_correction
([
x
,
y
,
z
]);
// needs zNear bug correction
var
xyz
=
zNear_bug_correction
([
shootRay
.
pickPosition
.
x
,
shootRay
.
pickPosition
.
y
,
shootRay
.
pickPosition
.
z
]);
x
=
xyz
[
0
];
y
=
xyz
[
1
];
z
=
xyz
[
2
];
//dist_xz = Math.sqrt(Math.pow(x-xc,2)+Math.pow(z-zc,2));
}
else
{
// zNear bug is already corrected
x
=
Data
.
markers
[
index
].
x
;
y
=
Data
.
markers
[
index
].
y
;
z
=
Data
.
markers
[
index
].
z
;
/*
dist_xz = Data.markers[index].d_x3d;
if (isNaN(dist_xz)){
dist_xz = Math.sqrt(Math.pow(x-xc,2)+Math.pow(z-zc,2));;
}
*/
}
//dist_xyz = Math.sqrt(Math.pow(y-yc,2)+Math.pow(dist_xz,2));
id
=
$
(
shootRay
.
pickObject
).
attr
(
"id"
);
valid_distance
=
true
;
}
else
{
// returns a |1| viewing direction based on canvas coordinates
var
viewingRay
=
elem
.
runtime
.
getViewingRay
(
cnvx
,
cnvy
);
x
=
viewingRay
.
dir
.
x
;
y
=
viewingRay
.
dir
.
y
;
z
=
viewingRay
.
dir
.
z
;
//dist_xz = null;
//dist_xyz = null;
valid_distance
=
false
;
}
// to get XZ(horizontal) distance - convert to real world coordinates
var
R0
=
Data
.
camera
.
Matrices
.
R0
;
var
p_w
=
new
x3dom
.
fields
.
SFVec3f
(
x
-
xc
,
y
-
yc
,
z
-
zc
);
var
p_rw
=
R0
.
multMatrixVec
(
p_w
);
if
(
valid_distance
){
dist_xz
=
Math
.
sqrt
(
p_rw
.
x
*
p_rw
.
x
+
p_rw
.
z
*
p_rw
.
z
);
dist_xyz
=
Math
.
sqrt
(
p_rw
.
y
*
p_rw
.
y
+
dist_xz
*
dist_xz
);
dist_xz
=
Math
.
sqrt
(
Math
.
pow
(
p_rw
.
x
,
2
)
+
Math
.
pow
(
p_rw
.
z
,
2
)
);
dist_xyz
=
Math
.
sqrt
(
Math
.
pow
(
p_rw
.
y
,
2
)
+
Math
.
pow
(
dist_xz
,
2
)
);
}
else
{
dist_xz
=
null
;
dist_xyz
=
null
;
}
// azimuth, elevation and skew are relative to the camera location
az
=
Math
.
atan2
(
p_rw
.
x
,
-
p_rw
.
z
)
*
180
/
Math
.
PI
;
az
=
(
az
+
360
)
%
360
;
el
=
Math
.
atan2
(
p_rw
.
y
,
Math
.
sqrt
(
p_rw
.
x
*
p_rw
.
x
+
p_rw
.
z
*
p_rw
.
z
))
*
180
/
Math
.
PI
;
sk
=
0
;
// fill out the output
var
result
=
{
x
:
!
round
?
x
:
x
.
toFixed
(
2
),
y
:
!
round
?
y
:
y
.
toFixed
(
2
),
...
...
@@ -180,8 +178,6 @@ function x3dom_getXYPosOr(cnvx,cnvy,round){
*/
function
x3dom_getCameraPosOr
(
round
){
//console.log("Getting PosOr");
var
elem
=
Scene
.
element
;
var
m
=
elem
.
runtime
.
viewMatrix
().
inverse
();
...
...
@@ -203,20 +199,24 @@ function x3dom_getCameraPosOr(round){
//x3dom_matrix_test();
var
x
=
tr
.
x
;
var
y
=
tr
.
y
;
var
z
=
tr
.
z
;
if
(
!
round
){
return
{
x
:
tr
.
x
,
y
:
tr
.
y
,
z
:
tr
.
z
,
x
:
x
,
y
:
y
,
z
:
z
,
a
:
ypr
.
yaw
,
e
:
ypr
.
pitch
,
s
:
ypr
.
roll
};
}
else
{
return
{
x
:
tr
.
x
.
toFixed
(
2
),
y
:
tr
.
y
.
toFixed
(
2
),
z
:
tr
.
z
.
toFixed
(
2
),
x
:
x
.
toFixed
(
2
),
y
:
y
.
toFixed
(
2
),
z
:
z
.
toFixed
(
2
),
a
:
ypr
.
yaw
.
toFixed
(
1
),
e
:
ypr
.
pitch
.
toFixed
(
1
),
s
:
ypr
.
roll
.
toFixed
(
1
)
...
...
@@ -244,6 +244,7 @@ function zNear_bug_correction(xyz){
z
=
z1
;
return
[
x
,
y
,
z
];
//return xyz;
}
...
...
This diff is collapsed.
Click to expand it.
js/x3dom_init.js
View file @
65c3858d
...
...
@@ -317,9 +317,7 @@ X3DOMObject.Shape.prototype._registerEvents = function(){
if
(
self
.
_ctrlKey
||
SETTINGS
.
pointer
){
// place pointer marker
$
(
"#sliding_sphere"
).
find
(
'material'
).
attr
(
"diffuseColor"
,
convert_color_l2x
(
SETTINGS
.
markercolor
));
$
(
"#sliding_sphere"
).
find
(
'material'
).
attr
(
"transparency"
,
"0.2"
);
$
(
"#sliding_sphere"
).
find
(
'Sphere'
).
attr
(
"radius"
,
SETTINGS
.
markersize
/
2
);
X3DOMObject
.
PointerMarker
.
updatePars
();
X3DOMObject
.
Marker
.
place
(
x
,
y
,
z
,
"sliding_sphere"
);
$
(
"#sliding_sphere"
).
find
(
"switch"
).
attr
(
"whichChoice"
,
0
);
...
...
@@ -362,7 +360,17 @@ X3DOMObject.Shape.prototype._registerEvents = function(){
if
(
self
.
_ctrlKey
){
X3DOMObject
.
createNewMarker
(
e
.
originalEvent
.
worldX
,
e
.
originalEvent
.
worldY
,
e
.
originalEvent
.
worldZ
);
var
x
=
e
.
originalEvent
.
worldX
;
var
y
=
e
.
originalEvent
.
worldY
;
var
z
=
e
.
originalEvent
.
worldZ
;
var
xyz
=
zNear_bug_correction
([
x
,
y
,
z
]);
x
=
xyz
[
0
];
y
=
xyz
[
1
];
z
=
xyz
[
2
];
X3DOMObject
.
createNewMarker
(
x
,
y
,
z
);
}
...
...
@@ -451,6 +459,9 @@ X3DOMObject.Shape.deselect = function(elem){
}
/**
* Create marker at x,y,z (need global)
*/
X3DOMObject
.
prototype
.
createMarker
=
function
(
x
,
y
,
z
,
id
){
var
self
=
this
;
...
...
@@ -530,6 +541,7 @@ X3DOMObject.Marker = function(x,y,z,ylevel){
X3DOMObject
.
Marker
.
prototype
.
init
=
function
(){
// this branch is experimental and inactive
if
(
this
.
_ylevel
){
//console.log(this._x+" "+this._y+" "+this._z);
...
...
@@ -572,81 +584,6 @@ X3DOMObject.Marker.prototype.init = function(){
}
/*
//var from = new x3dom.fields.SFVec3f(this._x, 100, this._z);
var from = new x3dom.fields.SFVec3f(0, 0, 0);
//var at = new x3dom.fields.SFVec3f(this._x, -100, this._z);
var dir = new x3dom.fields.SFVec3f(0, -0, -1);//at.subtract(from);
// dir gets auto normalized
var vray = new x3dom.fields.Ray(from, dir);
//var vray = Scene.element.runtime.getViewingRay(0,0);
console.log(vray);
var scene = Scene.element.runtime.canvas.doc._scene;
var info = Scene.element.runtime.canvas.doc._viewarea._pickingInfo;
console.log(Scene.element.runtime.pickMode());
//console.log(Scene.element.runtime.changePickMode('idbuf'));
//console.log(Scene.element.runtime.changePickMode('color'));
console.log(Scene.element.runtime.changePickMode('texcoord'));
//console.log(Scene.element.runtime.changePickMode('box'));
console.log(Scene.element.runtime.pickMode());
var isect = scene.doIntersect(vray);
console.log(info);
console.log("vr");
console.log(vray);
if (vray.hitObject!=null){
console.log($(vray.hitObject._xmlNode).parent().find("ImageTexture").attr("url"));
var el = $(vray.hitObject._xmlNode).parent();
var bbox = Scene.element.runtime.getSceneBBox();
console.log(bbox);
this._x = vray.hitPoint.x;
this._y = vray.hitPoint.y;
this._z = vray.hitPoint.z;
}
*/
/*
// sane output
console.log("scene bbox");
var bbox = Scene.element.runtime.getSceneBBox();
console.log(bbox);
*/
/*
var sr = Scene.element.runtime.shootRay(1000,450);
console.log("sr");
console.log(sr);
*/
/*
//while(vray.hitPoint.y>-100){
var n=0;
while(n<1000){
var from = new x3dom.fields.SFVec3f(vray.hitPoint.x,vray.hitPoint.y-0.1,vray.hitPoint.z);
var at = new x3dom.fields.SFVec3f(vray.hitPoint.x, -100, vray.hitPoint.z);
var dir = at.subtract(from).normalize();
var vray = new x3dom.fields.Ray(from, dir);
var isect = scene.doIntersect(vray);
console.log(vray);
n++;
}
*/
//do intersect
//hitobject
//get y
}
this
.
_elem
=
Scene
.
createMarker
(
this
.
_x
,
this
.
_y
,
this
.
_z
);
...
...
@@ -892,6 +829,7 @@ X3DOMObject.Marker.mouseMove = function(event){
var
sphere
=
Scene
.
draggedTransformNode
.
parent
().
parent
();
var
index
=
parseInt
(
sphere
.
attr
(
"id"
).
substr
(
7
));
// zNear bug correction
var
xyz
=
[
sr
.
pickPosition
.
x
,
sr
.
pickPosition
.
y
,
sr
.
pickPosition
.
z
];
xyz
=
zNear_bug_correction
(
xyz
);
...
...
@@ -932,7 +870,13 @@ X3DOMObject.Marker.drag = function(dx,dy){
X3DOMObject
.
Marker
.
slide
=
function
(
index
,
x
,
y
,
z
){
var
da
=
x3dom_getDistAngle
(
x
,
y
,
z
);
// camera coordinates, not correcting with zNear
var
campos
=
x3dom_getCameraPosOr
();
xc
=
campos
.
x
;
yc
=
campos
.
y
;
zc
=
campos
.
z
;
var
da
=
x3dom_getDistAngle
(
x
-
xc
,
y
-
yc
,
z
-
zc
);
var
distance
=
da
[
0
];
var
angle
=
da
[
1
];
...
...
@@ -1013,6 +957,15 @@ X3DOMObject.PointerMarker.prototype._init = function(){
}
X3DOMObject
.
PointerMarker
.
updatePars
=
function
(){
// place pointer marker
$
(
"#sliding_sphere"
).
find
(
'material'
).
attr
(
"diffuseColor"
,
convert_color_l2x
(
SETTINGS
.
markercolor
));
$
(
"#sliding_sphere"
).
find
(
'material'
).
attr
(
"transparency"
,
"0.2"
);
$
(
"#sliding_sphere"
).
find
(
'Sphere'
).
attr
(
"radius"
,
SETTINGS
.
markersize
/
2
);
}
X3DOMObject
.
PointerMarker
.
prototype
.
_registerEvents
=
function
(){
var
self
=
this
;
...
...
@@ -1413,7 +1366,14 @@ X3DOMObject.createNewMarker = function(x,y,z){
// Create marker on the scene
new
X3DOMObject
.
Marker
(
mark
.
x
,
mark
.
y
,
mark
.
z
);
var
da
=
x3dom_getDistAngle
(
mark
.
x
,
mark
.
y
,
mark
.
z
);
// camera coordinates, not correcting with zNear
var
campos
=
x3dom_getCameraPosOr
();
xc
=
campos
.
x
;
yc
=
campos
.
y
;
zc
=
campos
.
z
;
// calculate relative to the camera base
var
da
=
x3dom_getDistAngle
(
mark
.
x
-
xc
,
mark
.
y
-
yc
,
mark
.
z
-
zc
);
var
distance
=
da
[
0
];
var
angle
=
da
[
1
];
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment