forked from aframevr/aframe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request aframevr#2679 from dmarcos/cachObjectSetAttribute
Skip type checking if an object is passed through setAttribute twice
- Loading branch information
Showing
10 changed files
with
339 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* global AFRAME, THREE */ | ||
function randomIncRad (multiplier) { | ||
return multiplier * Math.random(); | ||
} | ||
|
||
function randomIncDeg (multiplier) { | ||
return randomIncRad(multiplier) * THREE.Math.RAD2DEG; | ||
} | ||
|
||
// COMPONENTS | ||
// ------------------ | ||
AFRAME.registerComponent('rotate-obj3d', { | ||
tick: function () { | ||
var el = this.el; | ||
el.object3D.rotation.x += randomIncRad(0.1); | ||
el.object3D.rotation.y += randomIncRad(0.2); | ||
el.object3D.rotation.z += randomIncRad(0.3); | ||
} | ||
}); | ||
|
||
AFRAME.registerComponent('rotate-get-obj3d', { | ||
tick: function () { | ||
var el = this.el; | ||
var rotation = el.getAttribute('rotation'); | ||
|
||
rotation.x += randomIncRad(0.1); | ||
rotation.y += randomIncRad(0.2); | ||
rotation.z += randomIncRad(0.3); | ||
|
||
el.object3D.rotation.x = rotation.x; | ||
el.object3D.rotation.y = rotation.y; | ||
el.object3D.rotation.z = rotation.z; | ||
} | ||
}); | ||
|
||
AFRAME.registerComponent('rotate-obj3d-set', { | ||
tick: function () { | ||
var el = this.el; | ||
var rotation = el.getAttribute('rotation'); | ||
|
||
rotation.x += randomIncDeg(0.1); | ||
rotation.y += randomIncDeg(0.2); | ||
rotation.z += randomIncDeg(0.3); | ||
|
||
el.setAttribute('rotation', rotation); | ||
} | ||
}); | ||
|
||
AFRAME.registerComponent('rotate-get-set', { | ||
tick: function () { | ||
var el = this.el; | ||
var rotationAux = this.rotationAux = this.rotationAux || {x: 0, y: 0, z: 0}; | ||
var rotation = el.getAttribute('rotation'); | ||
rotationAux.x = rotation.x + randomIncDeg(0.1); | ||
rotationAux.y = rotation.y + randomIncDeg(0.2); | ||
rotationAux.z = rotation.z + randomIncDeg(0.3); | ||
el.setAttribute('rotation', rotationAux); | ||
} | ||
}); | ||
|
||
AFRAME.registerComponent('rotate-get-settext', { | ||
tick: function () { | ||
var el = this.el; | ||
var rotation = el.getAttribute('rotation'); | ||
|
||
rotation.x += randomIncDeg(0.1); | ||
rotation.y += randomIncDeg(0.2); | ||
rotation.z += randomIncDeg(0.3); | ||
|
||
el.setAttribute('rotation', rotation.x + ' ' + rotation.y + ' ' + rotation.z); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Rotating Cubes Performance Test - A-Frame</title> | ||
<meta name="description" content=""> | ||
<script src="../../../dist/aframe-master.js"></script> | ||
<script src="utils.js"></script> | ||
<script src="components.js"></script> | ||
<script src="main.js"></script> | ||
</head> | ||
<style> | ||
body { | ||
color: #cccccc; | ||
font-family: Monospace; | ||
font-size: 13px; | ||
text-align: center; | ||
margin: 0px; | ||
overflow: hidden; | ||
} | ||
|
||
#info { | ||
background-color: #000; | ||
position: absolute; | ||
top: 0px; | ||
width: 100%; | ||
padding: 5px; | ||
z-index: 9999; | ||
} | ||
#info a { | ||
color: #fff; | ||
} | ||
</style> | ||
<body> | ||
<div id="info"> | ||
<a href="?numobjects=5000">none</a> | ||
<a href="?component=rotate-obj3d&numobjects=5000">rotate-obj3d</a> | ||
<a href="?component=rotate-get-obj3d&numobjects=5000">rotate-get-obj3d</a> | ||
<a href="?component=rotate-obj3d-set&numobjects=5000">rotate-obj3d-set</a> | ||
<a href="?component=rotate-get-set&numobjects=5000">rotate-get-set</a> | ||
<a href="?component=rotate-get-settext&numobjects=5000">rotate-get-settext</a> | ||
</div> | ||
<a-scene stats main></a-scene> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* global AFRAME */ | ||
AFRAME.registerComponent('main', { | ||
init: function () { | ||
var urlParams = this.getUrlParams(); | ||
var defaultNumObjects = 5000; | ||
var numObjects = urlParams.numobjects || defaultNumObjects; | ||
this.cubeDistributionWidth = 100; | ||
for (var i = 0; i < numObjects; i++) { | ||
var cubeEl = document.createElement('a-entity'); | ||
|
||
if (urlParams.component) { | ||
cubeEl.setAttribute(urlParams.component, ''); | ||
} | ||
cubeEl.setAttribute('position', this.getRandomPosition()); | ||
cubeEl.setAttribute('geometry', {primitive: 'box'}); | ||
cubeEl.setAttribute('material', {color: this.getRandomColor(), shader: 'flat'}); | ||
this.el.sceneEl.appendChild(cubeEl); | ||
} | ||
}, | ||
|
||
getUrlParams: function () { | ||
var match; | ||
var pl = /\+/g; // Regex for replacing addition symbol with a space | ||
var search = /([^&=]+)=?([^&]*)/g; | ||
var decode = function (s) { return decodeURIComponent(s.replace(pl, ' ')); }; | ||
var query = window.location.search.substring(1); | ||
var urlParams = {}; | ||
|
||
match = search.exec(query); | ||
while (match) { | ||
urlParams[decode(match[1])] = decode(match[2]); | ||
match = search.exec(query); | ||
} | ||
return urlParams; | ||
}, | ||
|
||
getRandomPosition: function () { | ||
var cubeDistributionWidth = this.cubeDistributionWidth; | ||
return { | ||
x: Math.random() * cubeDistributionWidth - cubeDistributionWidth / 2, | ||
y: Math.random() * cubeDistributionWidth - cubeDistributionWidth / 2, | ||
z: Math.random() * cubeDistributionWidth - cubeDistributionWidth | ||
}; | ||
}, | ||
|
||
getRandomColor: function () { | ||
return '#' + ('000000' + Math.random().toString(16).slice(2, 8).toUpperCase()).slice(-6); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.