英文:
AFrame raycaster `objects` field not working for custom cursor primitive
问题
我正在尝试注册一个自定义光标原语,但是射线投射器似乎无法检测到具有clickable
类的对象。
以下是我的代码:
AFRAME.registerPrimitive('a-animated-cursor', {
defaultComponents: {
raycaster: {
objects: '.clickable',
},
cursor: {
rayOrigin: 'mouse',
fuseTimeout: '500',
},
geometry: {
primitive: 'ring',
radiusOuter: 0.016,
radiusInner: 0.01,
segmentsTheta: 32,
},
material: {
color: 'white',
shader: 'flat',
opacity: 0.8,
},
position: {
x: 0,
y: 0,
z: -1,
},
animation__click: {
property: 'scale',
startEvents: 'click',
easing: 'easeInCubic',
dur: 150,
from: {
x: 0.1,
y: 0.1,
z: 0.1,
},
to: {
x: 1,
y: 1,
z: 1,
},
},
animation__fusing: {
property: 'scale',
startEvents: 'fusing',
easing: 'easeInCubic',
dur: 1500,
from: {
x: 1,
y: 1,
z: 1,
},
to: {
x: 0.1,
y: 0.1,
z: 0.1,
},
},
animation__mouseleave: {
property: 'scale',
startEvents: 'mouseleave',
easing: 'easeInCubic',
dur: 500,
to: {
x: 1,
y: 1,
z: 1,
},
},
},
});
以下是光标的工作方式,它不是一个原语:
<a-cursor
id="cursor"
color="white"
rayOrigin="mouse"
raycaster="objects: .clickable"
fuseTimeout="500"
animation__click="property: scale; startEvents: click; easing: easeInCubic; dur: 150; from: 0.1 0.1 0.1; to: 1 1 1"
animation__fusing="property: scale; startEvents: fusing; easing: easeInCubic; dur: 1500; from: 1 1 1; to: 0.1 0.1 0.1"
animation__mouseleave="property: scale; startEvents: mouseleave; easing: easeInCubic; dur: 500; to: 1 1 1"
></a-cursor>
英文:
I'm trying to register a custom cursor primitive, however, the raycaster doesn't seem to detect objects with the clickable
class
Here's my code:
AFRAME.registerPrimitive('a-animated-cursor', {
defaultComponents: {
raycaster: {
objects: '.clickable',
},
cursor: {
rayOrigin: 'mouse',
fuseTimeout: '500',
},
geometry: {
primitive: 'ring',
radiusOuter: 0.016,
radiusInner: 0.01,
segmentsTheta: 32,
},
material: {
color: 'white',
shader: 'flat',
opacity: 0.8,
},
position: {
x: 0,
y: 0,
z: -1,
},
animation__click: {
property: 'scale',
startEvents: 'click',
easing: 'easeInCubic',
dur: 150,
from: {
x: 0.1,
y: 0.1,
z: 0.1,
},
to: {
x: 1,
y: 1,
z: 1,
},
},
animation__fusing: {
property: 'scale',
startEvents: 'fusing',
easing: 'easeInCubic',
dur: 1500,
from: {
x: 1,
y: 1,
z: 1,
},
to: {
x: 0.1,
y: 0.1,
z: 0.1,
},
},
animation__mouseleave: {
property: 'scale',
startEvents: 'mouseleave',
easing: 'easeInCubic',
dur: 500,
to: {
x: 1,
y: 1,
z: 1,
},
},
},
});
And here's the working of the cursor, which isn't a primitive:
<a-cursor
id="cursor"
color="white"
rayOrigin="mouse"
raycaster="objects: .clickable"
fuseTimeout="500"
animation__click="property: scale; startEvents: click; easing: easeInCubic; dur: 150; from: 0.1 0.1 0.1; to: 1 1 1"
animation__fusing="property: scale; startEvents: fusing; easing: easeInCubic; dur: 1500; from: 1 1 1; to: 0.1 0.1 0.1"
animation__mouseleave="property: scale; startEvents: mouseleave; easing: easeInCubic; dur: 500; to: 1 1 1"
></a-cursor>
答案1
得分: 1
我认为它正在点击,但动画改变了 "to" 对象,所以它卡住了。如果您提供一个字符串比例,它似乎可以工作:
const box = document.querySelector("a-box")
box.addEventListener("click", () => {
// 点击时随机颜色
let hex = '#' + (Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0');
box.setAttribute("color", hex)
})
<script src="https://aframe.io/releases/1.4.1/aframe.min.js"></script>
<script>
AFRAME.registerPrimitive('a-animated-cursor', {
defaultComponents: {
cursor: {
rayOrigin: 'entity',
fuseTimeout: '500',
fuse: true
},
raycaster: {
objects: '.clickable',
},
geometry: {
primitive: 'ring',
radiusOuter: 0.016,
radiusInner: 0.01,
segmentsTheta: 32,
},
material: {
color: 'black',
shader: 'flat',
},
position: { x: 0, y: 0, z: -1 },
animation__fusing: {
property: 'scale',
startEvents: 'fusing',
easing: 'easeInCubic',
dur: 500,
from: "1 1 1",
to: "0.1 0.1 0.1"
},
animation__click: {
property: 'scale',
startEvents: 'click',
easing: 'easeInCubic',
dur: 150,
to: "1 1 1",
from: "0.1 0.1 0.1"
},
animation__mouseleave: {
property: 'scale',
startEvents: 'mouseleave',
easing: 'easeInCubic',
dur: 500,
to: "1 1 1"
}
},
});
</script>
<a-scene>
<a-camera>
<a-animated-cursor></a-animated-cursor>
</a-camera>
<a-box class="clickable" position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"></a-box>
<a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
</a-scene>
请注意,这只是提供了代码的翻译,没有其他内容。
英文:
I think it's clicking, but the animation changes the "to" object, so it gets stuck. If you provide a string scale, it seems to be working:
<!-- begin snippet: js hide: false console: false babel: false -->
<!-- language: lang-js -->
const box = document.querySelector("a-box")
box.addEventListener("click", () => {
// random color on click
let hex = '#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0');
box.setAttribute("color", hex)
})
<!-- language: lang-html -->
<script src="https://aframe.io/releases/1.4.1/aframe.min.js"></script>
<script>
AFRAME.registerPrimitive('a-animated-cursor', {
defaultComponents: {
cursor: {
rayOrigin: 'entity',
fuseTimeout: '500',
fuse: true
},
raycaster: {
objects: '.clickable',
},
geometry: {
primitive: 'ring',
radiusOuter: 0.016,
radiusInner: 0.01,
segmentsTheta: 32,
},
material: {
color: 'black',
shader: 'flat',
},
position: { x: 0, y: 0, z: -1 },
animation__fusing: {
property: 'scale',
startEvents: 'fusing',
easing: 'easeInCubic',
dur: 500,
from: "1 1 1",
to: "0.1 0.1 0.1"
},
animation__click: {
property: 'scale',
startEvents: 'click',
easing: 'easeInCubic',
dur: 150,
to: "1 1 1",
from: "0.1 0.1 0.1"
},
animation__mouseleave: {
property: 'scale',
startEvents: 'mouseleave',
easing: 'easeInCubic',
dur: 500,
to: "1 1 1"
}
},
});
</script>
<a-scene>
<a-camera>
<a-animated-cursor></a-animated-cursor>
</a-camera>
<a-box class="clickable" position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"></a-box>
<a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
</a-scene>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论