Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
265 additions
and
143 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
File renamed without changes.
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,47 @@ | ||
import THREE from 'three'; | ||
|
||
class GridLine extends THREE.Line { | ||
group = new THREE.Object3D(); | ||
|
||
colorCenterLine = new THREE.Color(0x444444); | ||
colorGrid = new THREE.Color(0x888888); | ||
|
||
constructor(sizeX, stepX, sizeY, stepY) { | ||
let geometry = new THREE.Geometry(); | ||
let material = new THREE.LineBasicMaterial({ | ||
vertexColors: THREE.VertexColors | ||
}); | ||
|
||
super(geometry, material); | ||
|
||
sizeY = (typeof sizeY === 'undefined') ? sizeX : sizeY; | ||
stepY = (typeof stepY === 'undefined') ? stepX : stepY; | ||
|
||
for (let i = -1 * sizeX; i <= sizeX; i += stepX) { | ||
geometry.vertices.push( | ||
new THREE.Vector3(-sizeX, i, 0), | ||
new THREE.Vector3(sizeX, i, 0), | ||
); | ||
|
||
let color = (i === 0) ? this.colorCenterLine : this.colorGrid; | ||
geometry.colors.push(color, color, color, color); | ||
} | ||
|
||
for (let i = -1 * sizeY; i <= sizeY; i += stepY) { | ||
geometry.vertices.push( | ||
new THREE.Vector3(i, -sizeY, 0), | ||
new THREE.Vector3(i, sizeY, 0), | ||
); | ||
|
||
let color = (i === 0) ? this.colorCenterLine : this.colorGrid; | ||
geometry.colors.push(color, color, color, color); | ||
} | ||
} | ||
setColors(colorCenterLine, colorGrid) { | ||
this.colorCenterLine.set(colorCenterLine); | ||
this.colorGrid.set(colorGrid); | ||
this.geometry.colorsNeedUpdate = true; | ||
} | ||
} | ||
|
||
export default GridLine; |
File renamed without changes.
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,61 @@ | ||
import THREE from 'three'; | ||
|
||
// TextSprite | ||
class TextSprite { | ||
// @param {object} options The options object | ||
// @param {number} [options.x] The point on the x-axis | ||
// @param {number} [options.y] The point on the y-axis | ||
// @param {number} [options.z] The point on the z-axis | ||
// @param {string} [options.text] The text string | ||
// @param {number} [options.size] The actual font size | ||
// @param {number|string} [options.color] The color | ||
// @param {number} [options.opacity] The opacity of text [0,1] | ||
constructor(options) { | ||
options = options || {}; | ||
let { opacity = 0.6, size = 10 } = options; | ||
|
||
let textObject = new THREE.Object3D(); | ||
let textHeight = 100; | ||
let textWidth = 0; | ||
|
||
let canvas = document.createElement('canvas'); | ||
let context = canvas.getContext('2d'); | ||
context.font = 'normal ' + textHeight + 'px Arial'; | ||
let metrics = context.measureText(options.text); | ||
textWidth = metrics.width; | ||
|
||
canvas.width = textWidth; | ||
canvas.height = textHeight; | ||
|
||
context.font = 'normal ' + textHeight + 'px Arial'; | ||
context.textAlign = 'center'; | ||
context.textBaseline = 'middle'; | ||
context.fillStyle = options.color; | ||
context.fillText(options.text, textWidth / 2, textHeight / 2); | ||
|
||
let texture = new THREE.Texture(canvas); | ||
texture.needsUpdate = true; | ||
texture.minFilter = THREE.LinearFilter; | ||
|
||
let material = new THREE.SpriteMaterial({ | ||
map: texture, | ||
transparent: true, | ||
opacity: opacity | ||
}); | ||
|
||
textObject.position.x = options.x || 0; | ||
textObject.position.y = options.y || 0; | ||
textObject.position.z = options.z || 0; | ||
textObject.textHeight = size; | ||
textObject.textWidth = (textWidth / textHeight) * textObject.textHeight; | ||
|
||
let sprite = new THREE.Sprite(material); | ||
sprite.scale.set(textWidth / textHeight * size, size, 1); | ||
|
||
textObject.add(sprite); | ||
|
||
return textObject; | ||
} | ||
} | ||
|
||
export default TextSprite; |
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
Oops, something went wrong.