Change image of sky every few seconds with an animation - aframe

I need change the image of sky every few seconds with an animation.
like this. But without the event click, in my case, i need the change of picture with time.
<a-assets>
<img id="water" src="./3D/letras/Agua.jpg"/>
<img id="air" src="./3D/letras/Aire.jpg"/>
<img id="horizont" src="./3D/letras/Horizonte.jpg"/>
<img id="hector" src="./3D/letras/hecxtor.jpg"/>
</a-assets>

How about this.
You make two animations: a fade-in, and a fade-out:
<a-sky foo>
<a-animation id="fadein-animation"></a-animation>
<a-animation id="fadein-animation"></a-animation>
</a-sky>
The idea is to animate the opacity, and when the image is not visible, switch the source:
AFRAME.registerComponent("foo", {
init: function() {
var self = this.el
var fadeInAnim = document.querySelector("#fadein-animation")
var fadeOutAnim = document.querySelector("#fadeout-animation")
var images = ["img1.jpg","img2.jpg"]
var switchflip = 1
fadeOutAnim.addEventListener("animationend", (e) => {
self.setAttribute("material", "src", images[switchflip])
switchflip = switchflip === 1 ? 0 : 1
self.emit('fadein')
})
fadeInAnim.addEventListener("animationend", (e) => {
self.emit('fadeout')
})
}
})
Working fiddle here.

Related

Having some issues in networked-audio-source, networked-vedio-source. (networked-aframe)

I've added video connectivity and audio connectivity in the multi-user part but, having small issues.
When I'm disconnecting it should hide the plane which is there for showing the video and share screen.
When I click on the screen sharing plane it should scale to the whole screen and then we can able to see minimize and close buttons also.
let cameraEnabled = false;
const cameraBtnEle = document.getElementById('camera-btn');
// Screen share status
let screenEnabled = false;
// Screen share button element
const screenBtnEle = document.getElementById('screen-btn');
// On mobile remove elements that are resource heavy
const isMobile = AFRAME.utils.device.isMobile();
function onConnect () {
console.log("onConnect", new Date());
// Handle camera button click (Off and On)
cameraBtnEle.addEventListener('click', function() {
NAF.connection.adapter.enableCamera(!cameraEnabled);
cameraEnabled = !cameraEnabled;
cameraBtnEle.textContent = cameraEnabled ? 'Hide Camera' : 'Show Camera';
});
// Handle screen button click (Off and On)
screenBtnEle.addEventListener('click', function() {
if (screenEnabled) {
NAF.connection.adapter.removeLocalMediaStream("screen");
screenEnabled = false;
if(screenEnabled == false){
console.log("This is for share screen ++++++++++++++++++",shareScreen);
shareScreen.setAttribute("visible","false")
}
screenBtnEle.textContent = 'Share screen';
} else {
navigator.mediaDevices.getDisplayMedia().then((stream) => {
NAF.connection.adapter.addLocalMediaStream(stream, "screen");
screenEnabled = true;
screenBtnEle.textContent = 'Stop Screen';
});
}
});
}
const shareScreen = document.querySelector("#shareScreen")
const videoScreen = document.querySelector("#videoScreen")
console.log("This is for share screen ++++++++++++++++++",videoScreen);
if(!cameraEnabled){
videoScreen.setAttribute("visible",false)
}
This is for onConnect function.
<div class="actions">
<button id="camera-btn" type="button" class="button">Hide Camera</button>
<button id="screen-btn" type="button" class="button">Share screen</button>
</div>
These are the buttons.
<template id="avatar-template">
<a-entity class="avatar" player-info>
<a-plane resize-on-click id="videoScreen" color="#FFF" width="4" height="3" position="0 .6 0" material="side: back" networked-video-source></a-plane>
<a-plane resize-on-click id="shareScreen" color="#FFF" width="2" height="1" position="0 .7 -0.001" material="side: back" networked-video-source="streamName: screen"></a-plane>
This is a-plane I'm using.
Please help me with this.

Hidden when first screen and show random image by click [Web Ar, Aframe, Ar.js ]

i want to hidden this component, and it will be show when i click button take-phot,
because, it always show frame defined by height and width> is blackbefore i click button take-phot
<a-image src="#my-image"
position="-0.05 1.5 -7" height="2" width="2">
</a-image>
<a-entity animation="property: visible; to: true; startEvents: materialtextureloaded"
material="src: #my-image"
visible="true"></a-entity>
</a-scene>
<div class="ui">
<a id="take-phot" title="Take Phot"><i class="material-icons">photo_camera</i></a>
</div>
</body>
</html>
<script>
var video = document.getElementById("vid");
video.play();
/* var pln = document.querySelector("#my-image");
pln.setAttribute('visible', true);*/
var myPix = new Array("ass/5.png", "ass/10.png", "ass/20.png", "ass/30.png");
var take_photo_btn = document.querySelector('#take-phot');
take_photo_btn.addEventListener("click", function (e) {
choosePic();
});
function choosePic() {
var randomNum = Math.floor(Math.random() * myPix.length);
document.getElementById("my-image").src = myPix[randomNum];
take_photo_btn.classList.add("disabled");
}
</script>

Add link to GLTF object in aframe

Is it possible to add a link to an GLTF 3d object (which is triggered with a marker?)
I've tried the usual 'a-link' method, the onClick method, even applying an id and using jQuery - all without luck - any help would be appreciated.
<a-scene embedded arjs>
<a-marker id="dragon" preset="custom" type="pattern" url="pattern-dragonfly.patt">
<a-entity animation-mixer="clip: *;" scale="1.5 1.5 1.5" gltf-model-next="src: url(dragon.gltf);"></a-entity>
</a-marker>
<a-entity camera></a-entity>
</a-scene>
To make this work, you need to create a cursor with a raycaster, and a custom component for the gltf.
<a-entity id="mouseCursor" cursor="rayOrigin: mouse" raycaster="objects: .clickable"></a-entity>
<a-entity id="tree" gltf-model="#gltftree" scale="5 5 5" treeman class="clickable" ></a-entity>
Inside the custom component, first you traverse the gltf and store references to the models that you want to be interactive, like this
init: function(){
let el = this.el;
let self = this;
self.trees = [];
el.addEventListener("model-loaded", e =>{
let tree3D = el.getObject3D('mesh');
if (!tree3D){return;}
console.log('tree3D', tree3D);
tree3D.traverse(function(node){
if (node.isMesh){
console.log(node);
self.trees.push(node);
node.material = new THREE.MeshStandardMaterial({color: 0x33aa00});
}
});
});
Then you make event listeners that detect intersection events, and save which object has been intersected, and highlight it, so users know it is live, like this
el.addEventListener('raycaster-intersected', e =>{
self.raycaster = e.detail.el;
let intersection = self.raycaster.components.raycaster.getIntersection(el);
console.log('click', intersection.object.name, self.mouseOverObject,
intersection.object.name != self.mouseOverObject );
if (self.mouseOverObject != intersection.object.name){
intersection.object.material.emissive = new THREE.Color(0xFFFF00);
intersection.object.material.emissiveIntensity = 0.5;
} else {
intersection.object.material.emissive = new THREE.Color(0x000000);
intersection.object.material.emissiveIntensity = 0.0;
}
self.mouseOverObject = intersection.object.name;
});
el.addEventListener('raycaster-intersected-cleared', e =>{
self.trees.forEach(function(tree){
tree.material.emissive = new THREE.Color(0x000000);
tree.material.emissiveIntensity = 0.0;
});
self.mouseOverObject = null;
});
Finally add a click listener that operate the hyperlink, like this
el.addEventListener('click', function(){
console.log(self.mouseOverObject);
if(self.mouseOverObject === "Trunk_A"){
console.log('link');
let url = 'https://supermedium.com/supercraft/';
let win = window.open(url, '_blank');
win.focus();
}
});
glitch here
Click the trunk to activate the hyperlink.

During button press: Move camera into direction of view

I want to create a simple aframe snippet for smartphones which moves the camera in the direction of the current field of view as long as the screen (or a button on it) is touched. I have already found a very useful piece of code here which continuously moves the camera in the direction of the FoV (see below).
Unfortunately, all my attempts to activate this motion only during a button press have failed (many of the examples I found only used instantaneous events, for example a 'click' or facing a certain object for the first time, but not continuous button presses). Is it even possible to do something like I have in mind? If so, what kind of trigger would I require?
<script src="https://cdnjs.cloudflare.com/ajax/libs/aframe/0.5.0/aframe.min.js"></script>
<script src="//cdn.rawgit.com/donmccurdy/aframe-extras/v3.7.0/dist/aframe-extras.min.js"></script>
<html>
<body>
<script type="text/javascript">
AFRAME.registerComponent("listener", {
schema :
{
stepFactor : {
type : "number",
default : 0.05
}
},
tick : function()
{ document.querySelector("a-camera").components.camera.camera.parent.position.add(document.querySelector("a-camera").components.camera.camera.getWorldDirection().multiplyScalar(this.data.stepFactor));
}
});
</script>
<a-scene>
<a-camera position="0 0 30">
<a-entity id="cursor" cursor="fuse: true;fuseTimeout:500"
material="color:black"
geometry="primitive:ring"
position="0 0 -1"
scale="0.01 0.01 0.01"
listener="stepFactor:0.01"
></a-entity>
</a-camera>
<a-grid></a-grid>
<a-box position="0 1 -2" color="blue" move eve></a-box>
</body>
</html>
Try something like this: have a boolean switched by the mouseup and mousedown events, and have the tick execution within a simple if (myBool) condition:
AFRAME.registerComponent("foo", {
init: function() {
this.mousedown = false
window.addEventListener("mouseup", (e)=> {
this.mousedown = false
})
window.addEventListener("mousedown", (e)=> {
this.mousedown = true
})
},
tick: function() {
if (this.mousedown) {
//do stuff
}
}
})
fiddle here, but it only moves the camera in the x/y axis.

adding object dynamically in live a-frame camera view

I am trying to place an image in a-frame camera view. please share an example.
A quick way to do this is to add an invisible "marker" as a child of the camera, and use its position as the spawn point when adding an object.
HTML
<a-scene>
<a-camera>
<a-entity id="marker" position="0 0 -5"></a-entity>
</a-camera>
<a-cylinder id="floor" height="0.1" radius="10" color="green"></a-cylinder>
</a-scene>
JS
var sceneEl = document.querySelector('a-scene');
var markerEl = document.querySelector('#marker');
// Add boxe when spacebar is pressed.
document.addEventListener('keyup', function (e) {
if (e.keyCode !== 32) return;
var newEl = document.createElement('a-box');
newEl.setAttribute('color', 'red');
sceneEl.appendChild(newEl);
var position = markerEl.object3D.getWorldPosition();
position.y = 0.5;
newEl.setAttribute('position', position);
});
Codepen: https://codepen.io/donmccurdy/pen/QOOXbK?editors=1010

Resources