Skip to content

Commit 6626bdc

Browse files
author
Aaron Sillus
committed
AframeRelation(Highl./Transp./Con.)Controller working
AframeRelationConnectorController: -implemented a function to determine intersections of cylinders with any object (objects of any shape and also its parents) by raycasting function calculateBorderPosition(THREE.Vector3 sourceOfRay, THREE.Vector3 targetOfRay, model.entity entity) : returns THREE.Vector3 if intersection was found struggles with current aframe RD Bank Model since it consists of 2D shapes where no intersection can be found -fixPositionZ made no sense; renamed it to fixPositionY setting the y coordinates of source and target to the lower one of both -added colors for connector and endPoints to the controllerConfig -objects created in this controller are not contained in the model which may cause errors in other controllers (e.g. hoverController) -the config parameter elementShape was removed due to the original RelationConnectorController only implementing the function for circle (assuming circle and square refer to the (related)Entities shape RelationConnectorController: -corrected some typos RelationHighlightController: -added a controllerConfig -corrected some typos -changed color(0, 0, 0) to "black" which is aframe compatible RelationTransparencyController: -corrected some typos -removed unused variable noFadeValue
1 parent b94044b commit 6626bdc

5 files changed

Lines changed: 127 additions & 145 deletions

File tree

ui/scripts/RelationConnector/AframeRelationConnectorController.js

Lines changed: 85 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,22 @@ var relationConnectorController = function(){
55

66
var connectors = new Array();
77
var relations = new Array();
8-
9-
var loadedMin = new Map();
10-
var loadedMax = new Map();
11-
var loadedPositions = new Map();
12-
var loadedDistances = new Map();
138

149
var activated = false;
1510

1611

1712
//config parameters
1813
var controllerConfig = {
14+
fixPositionY : false,
1915
fixPositionZ : false,
2016
showInnerRelations : false,
21-
elementShape : "", //circle, square
2217
sourceStartAtParentBorder : false,
2318
targetEndAtParentBorder : false,
2419
sourceStartAtBorder: false,
2520
targetEndAtBorder: false,
2621
createEndpoints : false,
22+
connectorColor : {r: 1, g: 0, b: 0},
23+
endpointColor : {r: 0, g: 0, b: 0}
2724
}
2825

2926

@@ -201,21 +198,55 @@ var relationConnectorController = function(){
201198
if( targetPosition === null ){
202199
return;
203200
}
201+
202+
if(controllerConfig.sourceStartAtParentBorder){
203+
let sourceParent = entity.belongsTo;
204+
let targetParent = relatedEntity.belongsTo;
205+
if(sourceParent != targetParent){
206+
if(controllerConfig.targetEndAtParentBorder) {
207+
targetPosition = canvasManipulator.getCenterOfEntity(targetParent);
208+
}
209+
let intersection = calculateBorderPosition(targetPosition, canvasManipulator.getCenterOfEntity(sourceParent), sourceParent);
210+
if(intersection != undefined) {
211+
sourcePosition = intersection;
212+
} else console.debug("raycasting found no intersection with parent objects surface");
213+
}
214+
}
215+
216+
if(controllerConfig.targetEndAtParentBorder){
217+
let targetParent = relatedEntity.belongsTo;
218+
if(targetParent != entity.belongsTo) {
219+
let intersection = calculateBorderPosition(sourcePosition, canvasManipulator.getCenterOfEntity(targetParent), targetParent);
220+
if(intersection != undefined) {
221+
targetPostion = intersection;
222+
} else console.debug("raycasting found no intersection with parent objects surface");
223+
}
224+
}
225+
204226
if( controllerConfig.sourceStartAtBorder ) {
205-
sourcePosition = calculateBorderPosition(targetPosition, sourcePosition, entity);
227+
if(controllerConfig.targetEndAtBorder) {
228+
targetPosition = canvasManipulator.getCenterOfEntity(relatedEntity);
229+
}
230+
// getCenterOfEntity again in-case it got overwritten for sourceStartAtParentBorder
231+
sourcePosition = calculateBorderPosition(targetPosition, canvasManipulator.getCenterOfEntity(entity), entity);
206232
}
207233
if( controllerConfig.targetEndAtBorder ) {
208-
targetPosition = calculateBorderPosition(sourcePosition, targetPosition, relatedEntity);
234+
// getCenterOfEntity again in-case it got overwritten for targetEndAtParentBorder
235+
targetPosition = calculateBorderPosition(sourcePosition, canvasManipulator.getCenterOfEntity(relatedEntity), relatedEntity);
209236
}
210-
211-
var connectorColor = {r:1, g:1, b:0};
237+
212238
var connectorSize = 0.05;
213239

214-
//config
215-
if(controllerConfig.fixPositionZ) {
216-
sourcePosition[z] = controllerConfig.fixPositionZ;
217-
targetPosition[z] = controllerConfig.fixPositionZ;
218-
}
240+
// This function made no sense and doesn't seem to work on x3dom either
241+
/*if(controllerConfig.fixPositionZ) {
242+
sourcePosition.z = controllerConfig.fixPositionZ;
243+
targetPosition.z = controllerConfig.fixPositionZ;
244+
}*/
245+
// suggestion for city model: draw horizontal cylinders on the lower positions level
246+
if(controllerConfig.fixPositionY) {
247+
sourcePosition.y = Math.min(sourcePosition.y, targetPosition.y);
248+
targetPosition.y = sourcePosition.y;
249+
}
219250

220251

221252
let deltaX = targetPosition.x - sourcePosition.x;
@@ -225,13 +256,13 @@ var relationConnectorController = function(){
225256
let distance = sourcePosition.distanceTo(targetPosition);
226257
let direction = new THREE.Vector3(deltaX, deltaY, deltaZ).normalize();
227258

228-
//create element
259+
//create connector
229260
var connector = document.createElement("a-cylinder");
230261
connector.addEventListener("loaded", function() {
231262
let threeMesh = this.object3DMap.mesh;
232263

233264
threeMesh.scale.set(connectorSize, distance, connectorSize);
234-
threeMesh.material.color.setRGB(connectorColor.r, connectorColor.g, connectorColor.b);
265+
threeMesh.material.color.setRGB(controllerConfig.connectorColor.r, controllerConfig.connectorColor.g, controllerConfig.connectorColor.b);
235266
threeMesh.position.set(sourcePosition.x+deltaX/2,
236267
sourcePosition.y+deltaY/2,
237268
sourcePosition.z+deltaZ/2);
@@ -240,134 +271,76 @@ var relationConnectorController = function(){
240271
var quaternion = threeMesh.quaternion;
241272
quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), direction);
242273
});
274+
connector.setAttribute("flat-shading", true);
275+
connector.setAttribute("shader", "flat");
243276

244277

245278

246279
let scene = document.querySelector("a-scene");
247280
scene.appendChild(connector);
248281
var connectorElements = [];
249282
connectorElements.push(connector);
283+
284+
// create Endpoints
250285
if(controllerConfig.createEndpoints) {
251286
var size = connectorSize*1.5;
252287
var length = size * 6;
253-
var sourceEndPoint = document.createElement("a-cylinder");
254-
sourceEndPoint.addEventListener("loaded", function() {
288+
var sourceEndpoint = document.createElement("a-cylinder");
289+
sourceEndpoint.addEventListener("loaded", function() {
255290
let threeMesh = this.object3DMap.mesh;
256-
threeMesh.material.color.setRGB(connectorColor.r, connectorColor.g, connectorColor.b);
291+
threeMesh.material.color.setRGB(controllerConfig.endpointColor);
257292
threeMesh.scale.set(size, length, size);
258293
threeMesh.position.set(sourcePosition.x, sourcePosition.y, sourcePosition.z);
259294
var quaternion = threeMesh.quaternion;
260295
quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), direction);
261296
});
262-
var targetEndPoint = document.createElement("a-cylinder");
263-
targetEndPoint.addEventListener("loaded", function() {
297+
sourceEndpoint.setAttribute("flat-shading", true);
298+
sourceEndpoint.setAttribute("shader", "flat");
299+
300+
var targetEndpoint = document.createElement("a-cylinder");
301+
targetEndpoint.addEventListener("loaded", function() {
264302
let threeMesh = this.object3DMap.mesh;
265-
threeMesh.material.color.setRGB(connectorColor.r, connectorColor.g, connectorColor.b);
266-
threeMesh.material.needsUpdate = true;
267-
console.debug(threeMesh.material);
303+
threeMesh.material.color.setRGB(controllerConfig.endpointColor);
268304
threeMesh.scale.set(size, length, size);
269305
threeMesh.position.set(targetPosition.x, targetPosition.y, targetPosition.z);
270306
var quaternion = threeMesh.quaternion;
271307
quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), direction.normalize());
272308
});
273-
scene.appendChild(sourceEndPoint);
274-
scene.appendChild(targetEndPoint);
275-
connectorElements.push(sourceEndPoint);
276-
connectorElements.push(targetEndPoint);
309+
targetEndpoint.setAttribute("shader", "flat");
310+
311+
scene.appendChild(sourceEndpoint);
312+
scene.appendChild(targetEndpoint);
313+
connectorElements.push(sourceEndpoint);
314+
connectorElements.push(targetEndpoint);
277315

278316
}
279317
return connectorElements;
280318
}
281-
282-
function isTargetChildOfSourceParent(target, source){
283-
284-
var targetParent = target.belongsTo;
285-
var sourceParent = source.belongsTo;
286-
287-
while(targetParent !== undefined) {
288-
289-
if(targetParent == sourceParent){
290-
return true;
291-
}
292-
293-
targetParent = targetParent.belongsTo;
294-
}
295-
296-
return false;
297-
}
298319

299-
function calculateBorderPosition(sourcePosition, targetPosition, entity){
320+
function isTargetChildOfSourceParent(target, source){
321+
322+
var targetParent = target.belongsTo;
323+
var sourceParent = source.belongsTo;
324+
325+
while(targetParent !== undefined) {
326+
327+
if(targetParent == sourceParent){
328+
return true;
329+
}
330+
331+
targetParent = targetParent.belongsTo;
332+
}
333+
334+
return false;
335+
}
336+
337+
function calculateBorderPosition(sourceOfRay, targetOfRay, entity){
300338
let object = document.getElementById(entity.id);
301339
let raycaster = new THREE.Raycaster();
302340
raycaster.set(sourcePosition, targetPosition.subVectors(targetPosition, sourcePosition).normalize());
303341
let intersection = raycaster.intersectObject(object.object3DMap.mesh);
304342
return intersection[0].point;
305343
}
306-
307-
/*function calculatePositionFromParent(sourcePosition, targetPosition, sourceParent){
308-
if(controllerConfig.elementShape == "circle"){
309-
return calculateCirclePositionFromParent(sourcePosition, targetPosition, sourceParent);
310-
}
311-
if(controllerConfig.elementShape == "square"){
312-
return calculateSquarePositionFromParent(sourcePosition, targetPosition, sourceParent);
313-
}
314-
return sourcePosition;
315-
}
316-
317-
function calculateSquarePositionFromParent(sourcePosition, targetPosition, sourceParent){
318-
// To implement...
319-
}
320-
321-
function calculateCirclePositionFromParent(sourcePosition, targetPosition, sourceParent){
322-
//calculation derived from http://www.3d-meier.de/tut6/XPresso53.html
323-
324-
var parentPosition = getObjectPosition(sourceParent.id);
325-
326-
var parentRadius = loadedDistances.get(sourceParent.id);
327-
var parentX = parentPosition[0];
328-
var parentY = parentPosition[1];
329-
330-
331-
var targetX = targetPosition[0];
332-
var targetY = targetPosition[1];
333-
334-
var sourceX = sourcePosition[0];
335-
var sourceY = sourcePosition[1];
336-
337-
var deltaX = targetX - sourceX;
338-
var deltaY = targetY - sourceY;
339-
340-
var a = deltaY / deltaX;
341-
var b = (targetY - parentY) - ( a * (targetX - parentX) );
342-
343-
var r = parentRadius[0];
344-
345-
346-
var AA = 1 + Math.pow(a, 2);
347-
var BB = (2 * a * b)
348-
var CC = Math.pow(b, 2) - Math.pow(r, 2);
349-
350-
var XX = Math.pow(BB, 2) - 4 * AA * CC;
351-
352-
353-
var x1 = (-BB + Math.sqrt( XX, 2 )) / ( 2 * AA );
354-
var x2 = (-BB - Math.sqrt( XX, 2 )) / ( 2 * AA );
355-
356-
var y1 = a * x1 + b;
357-
var y2 = a * x2 + b;
358-
359-
360-
var newSourcePosition;
361-
if( (targetY > sourceY && targetX < sourceX) ||
362-
(targetY < sourceY && targetX < sourceX) ){
363-
newSourcePosition = [x2+parentX, y2+parentY, sourcePosition[2]];
364-
} else {
365-
newSourcePosition = [x1+parentX, y1+parentY, sourcePosition[2]];
366-
}
367-
368-
return newSourcePosition;
369-
}*/
370-
371344

372345
return {
373346
initialize : initialize,

ui/scripts/RelationConnector/RelationConnectorController.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ var relationConnectorController = function(){
2323
targetEndAtParentBorder : false,
2424
sourceStartAtBorder: false,
2525
targetEndAtBorder: false,
26-
createEndpoints : false,
27-
}
26+
createEndpoints : false
27+
};
2828

2929

3030
function initialize(setupConfig){
@@ -116,7 +116,7 @@ var relationConnectorController = function(){
116116

117117
removeAllConnectors();
118118

119-
//get related entites
119+
//get related entities
120120
sourceEntity = applicationEvent.entities[0];
121121

122122
events.log.info.publish({ text: "connector - onRelationsChanged - selected Entity - " + sourceEntity.name});
@@ -145,7 +145,7 @@ var relationConnectorController = function(){
145145
return;
146146
}
147147

148-
events.log.info.publish({ text: "connector - onRelationsChanged - related Entites - " + relatedEntities.length});
148+
events.log.info.publish({ text: "connector - onRelationsChanged - related Entities - " + relatedEntities.length});
149149

150150
if(relatedEntities.length == 0) {
151151
return;
@@ -160,10 +160,10 @@ var relationConnectorController = function(){
160160

161161
function createRelatedConnections(){
162162

163-
var relatedEntitesMap = new Map();
163+
var relatedEntitiesMap = new Map();
164164

165165
relatedEntities.forEach(function(relatedEntity){
166-
if(relatedEntitesMap.has(relatedEntity)){
166+
if(relatedEntitiesMap.has(relatedEntity)){
167167
events.log.info.publish({ text: "connector - onRelationsChanged - multiple relation"});
168168
return;
169169
}
@@ -202,11 +202,11 @@ var relationConnectorController = function(){
202202

203203
relations.push(relation);
204204

205-
relatedEntitesMap.set(relatedEntity, relatedEntity);
205+
relatedEntitiesMap.set(relatedEntity, relatedEntity);
206206
});
207207

208208

209-
if(relatedEntitesMap.size != 0){
209+
if(relatedEntitiesMap.size != 0){
210210

211211
var applicationEvent = {
212212
sender: relationConnectorController,
@@ -238,7 +238,7 @@ var relationConnectorController = function(){
238238
sourcePosition[2] = controllerConfig.fixPositionZ;
239239
targetPosition[2] = controllerConfig.fixPositionZ;
240240
}
241-
241+
242242
//create element
243243
var transform = document.createElement('Transform');
244244

0 commit comments

Comments
 (0)