-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow directional lights to automatically follow shadows #5025
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8351215
rename property
AdaRoseCannon 23d1ffc
fix target updating
AdaRoseCannon fa13819
s/auto/automatic
AdaRoseCannon 9584a46
address feedback
AdaRoseCannon c3177a0
s/p1/pointToTest
AdaRoseCannon 930d269
s/out/resultPoint
AdaRoseCannon File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,39 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Hello, AR World! • A-Frame</title> | ||
<meta name="description" content="Hello, AR World! • A-Frame"> | ||
<script src="../../../dist/aframe-master.js"></script> | ||
<script> | ||
AFRAME.registerComponent('follow-shadow', { | ||
schema: {type: 'selector'}, | ||
init() {this.el.object3D.renderOrder = -1;}, | ||
tick() { | ||
if (this.data) { | ||
this.el.object3D.position.copy(this.data.object3D.position); | ||
this.el.object3D.position.y-=0.001; // stop z-fighting | ||
} | ||
} | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<a-scene | ||
reflection="directionalLight:a-light[type=directional]" | ||
ar-hit-test="target:#objects;" | ||
renderer="physicallyCorrectLights:true;colorManagement:true;exposure:1;toneMapping:ACESFilmic;" | ||
shadow="type:pcfsoft" | ||
> | ||
<a-light type="directional" light="castShadow:true;" position="1 1 1" intensity="0.5" shadow-camera-automatic="#objects"></a-light> | ||
<a-camera position="0 0.4 0" wasd-controls="acceleration:10;"></a-camera> | ||
<a-entity id="objects" scale="0.2 0.2 0.2" position="0 0 -1" shadow> | ||
<a-box position="-1 0.5 1" rotation="0 45 0" color="#4CC3D9"></a-box> | ||
<a-sphere position="0 1.25 -1" radius="1.25" color="#EF2D5E"></a-sphere> | ||
<a-cylinder position="1 0.75 1" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder> | ||
</a-entity> | ||
<a-plane follow-shadow="#objects" material="shader:shadow" shadow="cast:false;" rotation="-90 0 0" width="2" height="2"></a-plane> | ||
<a-sky color="#ECECEC" hide-on-enter-ar></a-sky> | ||
</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
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
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,34 @@ | ||
/** | ||
* Find the disatance from a plane defined by a point on the plane and the normal of the plane to any point. | ||
* @param {THREE.Vector3} positionOnPlane any point on the plane. | ||
* @param {THREE.Vector3} planeNormal the normal of the plane | ||
* @param {THREE.Vector3} p1 point to test | ||
* @returns Number | ||
*/ | ||
function distanceOfPointFromPlane (positionOnPlane, planeNormal, p1) { | ||
// the d value in the plane equation a*x + b*y + c*z=d | ||
var d = planeNormal.dot(positionOnPlane); | ||
|
||
// distance of point from plane | ||
return (d - planeNormal.dot(p1)) / planeNormal.length(); | ||
} | ||
|
||
/** | ||
* Find the point on a plane that lies closest to | ||
* @param {THREE.Vector3} positionOnPlane any point on the plane. | ||
* @param {THREE.Vector3} planeNormal the normal of the plane | ||
* @param {THREE.Vector3} p1 point to test | ||
* @param {THREE.Vector3} out where to store the result. | ||
* @returns | ||
*/ | ||
function nearestPointInPlane (positionOnPlane, planeNormal, p1, out) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
var t = distanceOfPointFromPlane(positionOnPlane, planeNormal, p1); | ||
// closest point on the plane | ||
out.copy(planeNormal); | ||
out.multiplyScalar(t); | ||
out.add(p1); | ||
return out; | ||
} | ||
|
||
module.exports.distanceOfPointFromPlane = distanceOfPointFromPlane; | ||
module.exports.nearestPointInPlane = nearestPointInPlane; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pointToTest
instead of p1