Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const customShaderMaterial = new ShaderMaterial({
uniforms: {
color: { value: baseColor },
opacity: { value: 1 },
startAngle: { value: 0 },
endAngle: { value: Math.PI / 2 },
startRadius: { value: 1 },
endRadius: { value: 2 }
},
vertexShader: arcVertexShader,
fragmentShader: arcFragmentShader,
transparent: true
})
const derivedMaterial = createDerivedMaterial(
new MeshStandardMaterial({
transparent: true
}),
// baseMaterial1,
{
uniforms: {
startAngle: { value: 0 },
endAngle: { value: Math.PI / 2 },
startRadius: { value: 1 },
endRadius: { value: 2 }
},
vertexDefs: `
uniform float startAngle;
uniform float endAngle;
uniform float startRadius;
uniform float endRadius;
position = vec3(
cos(angle) * radius,
sin(angle) * radius,
position.z
);
// Rotate the normal by the same angle so lighting is correct
float normalRotZ = angle - PI2;
normal = normalize(vec3(
vec4(normal, 1.0) * mat4( cos(normalRotZ), -sin(normalRotZ), 0, 0, sin(normalRotZ), cos(normalRotZ), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 )
));
`
}
)
const doubleDerivedMaterial = createDerivedMaterial(derivedMaterial, {
vertexDefs: `
varying vec2 vXY;
`,
vertexTransform: `
vXY = vec2(position);
`,
fragmentDefs: `
varying vec2 vXY;
`,
fragmentColorTransform: `
gl_FragColor.x *= 6.0 * (vXY.x + .5);
gl_FragColor.y *= 2.0 * (vXY.y + .5);
if (length(vXY) < 0.2) {
discard;
}
`
// Coords may be from a single 'Polygon' or a 'MultiPolygon', handle either
if (typeof countryCoordData[0][0][0] === 'number') {
handleCoordsGroup(countryCoordData)
} else {
countryCoordData.forEach(handleCoordsGroup)
}
})
})
const countryBordersGeometry = new BufferGeometry()
const positionAttr = new BufferAttribute(new Float32Array(lineSegmentPositions), 3)
countryBordersGeometry.setAttribute('position', positionAttr)
countryBordersGeometry.setAttribute('normal', positionAttr) //positions are based off r=1 so they can be used directly as normals
const sphereGeometry = new SphereBufferGeometry(1, 32, 24)
const sphereMaterial = createDerivedMaterial(new MeshBasicMaterial({
color: 0x6666ff,
transparent: true,
opacity: 0.6,
side: BackSide
}), {
vertexDefs: 'varying vec3 vCameraSpaceNormal;',
vertexMainIntro: `vCameraSpaceNormal = normalize((modelViewMatrix * vec4(normal, 0.0)).xyz);`,
fragmentDefs: 'varying vec3 vCameraSpaceNormal;',
fragmentColorTransform: `gl_FragColor.w = 0.15 + 0.5 * pow(length(cross(vCameraSpaceNormal, vec3(0.,0.,1.))), 8.0);`
})
class Globe extends Object3DFacade {
constructor (parent) {
const lines = new LineSegments(
countryBordersGeometry,
new MeshStandardMaterial({
constructor(parent) {
super(parent)
// If fully hidden by parent clipping rect, cull the whole Group out of the scene
Object.defineProperty(this.threeObject, 'visible', groupVisiblePropDef)
// Anonymous container for bg/border/scrollbar child objects; these live separate
// from the main `children` tree
this.layers = new Group3DFacade(this)
this.layers.children = [null, null, null]
this._sizeVec2 = new Vector2()
this._clipRectVec4 = new Vector4()
this._borderWidthVec4 = new Vector4()
this._borderRadiiVec4 = new Vector4()
;(this._geomBoundingSphere = new Sphere()).version = 0
}
/**
* @override to skip rendering HTML overlays when in immersive mode
*/
_doRenderHtmlItems() {
if (this._isImmersive()) {
if (this.renderHtmlItems) {
this.renderHtmlItems(emptyArray)
}
} else {
super._doRenderHtmlItems()
}
}
}
WorldXRFacade.prototype._notifyWorldHandlers = Object.create(
World3DFacade.prototype._notifyWorldHandlers,
{
// notification to end the XR session
endXRSession: {
value: function(source, data) {
if (this.xrSession) {
this.xrSession.end()
}
}
}
}
)
export default WorldXRFacade
export function createUIBlockLayerDerivedMaterial(baseMaterial, isBorder) {
const material = createDerivedMaterial(baseMaterial, {
defines: {
[`TROIKA_UI_${isBorder ? 'BORDER' : 'BG'}`]: ''
},
extensions: {
derivatives: true
},
uniforms: {
uTroikaBlockSize: {value: new Vector2()},
uTroikaClipRect: {value: new Vector4()},
uTroikaCornerRadii: {value: new Vector4()},
uTroikaBorderWidth: {value: new Vector4()}
},
vertexDefs: VERTEX_DEFS,
vertexTransform: VERTEX_TRANSFORM,
fragmentDefs: FRAGMENT_DEFS,
fragmentColorTransform: FRAGMENT_COLOR_TRANSFORM
Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.
But, in a larger sense, we can not dedicate — we can not consecrate — we can not hallow — this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us — that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion — that we here highly resolve that these dead shall not have died in vain — that this nation, under God, shall have a new birth of freedom — and that government of the people, by the people, for the people, shall not perish from the earth.
Abraham Lincoln
November 19, 1863`,
'ABC123': 'abc def ghi jkl mno pqrs tuv wxyz ABC DEF GHI JKL MNO PQRS TUV WXYZ !"§ $%& /() =?* \'<> #|; ²³~ @`´ ©«» ¤¼× {} abc def ghi jkl mno pqrs tuv wxyz ABC DEF GHI JKL MNO PQRS TUV WXYZ !"§ $%& /() =?* \'<> #|; ²³~ @`´ ©«» ¤¼× {} abc def ghi jkl mno pqrs tuv wxyz ABC DEF GHI JKL MNO PQRS TUV WXYZ !"§ $%& /() =?* \'<> #|; ²³~ @`´ ©«» ¤¼× {} abc def ghi jkl mno pqrs tuv wxyz ABC DEF GHI JKL MNO PQRS TUV WXYZ !"§ $%& /() =?* \'<> #|; ²³~ @`´ ©«» ¤¼× {} abc def ghi jkl mno pqrs tuv wxyz ABC DEF GHI JKL MNO PQRS TUV WXYZ !"§ $%& /() =?* \'<> #|; ²³~ @`´ ©«» ¤¼× {} abc def ghi jkl mno pqrs tuv wxyz ABC DEF GHI JKL MNO PQRS TUV WXYZ !"§ $%& /() =?* \'<> #|; ²³~ @`´ ©«» ¤¼× {}',
[CUSTOM_LBL]: 'Edit me!'
}
const TEXTURE = new TextureLoader().load('shader-anim/lava.jpg')
const MATERIALS = {
'MeshBasicMaterial': new MeshBasicMaterial(),
'MeshStandardMaterial': new MeshStandardMaterial(),
'Custom Vertex Shader': createDerivedMaterial(new MeshStandardMaterial(), {
timeUniform: 'elapsed',
vertexTransform: `
float waveAmplitude = 0.1;
float waveX = uv.x * PI * 4.0 - mod(elapsed / 300.0, PI2);
float waveZ = sin(waveX) * waveAmplitude;
normal.xyz = normalize(vec3(-cos(waveX) * waveAmplitude, 0.0, 1.0));
position.z += waveZ;
`
})
}
const MATERIAL_OPTS = Object.keys(MATERIALS)
Object.keys(MATERIALS).forEach(name => {
MATERIALS[name + '+Texture'] = MATERIALS[name].clone()
MATERIALS[name + '+Texture'].map = TEXTURE
})
xrSupported={xrSupported}
xrSession={xrSession}
onSelectSession={this._onLauncherSelect}
/>
const contextValue = {
worldFacade: WorldXRFacade,
worldProps: {
xrSession,
xrSessionMode,
xrReferenceSpace,
xrReferenceSpaceType
}
}
return React.createElement(Canvas3D.contextType.Provider, {value: contextValue},
React.createElement(
ReactClass,
utils.assign({}, props, {
xrSupported,
xrSupportedSessionModes,
xrSession,
xrSessionMode,
xrReferenceSpace,
xrReferenceSpaceType,
xrLauncher
}),
props.children
)
)
}
}
const VrButtonImpl = options.buttonRenderer
const vrButton =
const contextValue = {
worldFacade: WorldVrFacade,
worldProps: { vrDisplay },
onCanvasRef: this._registerVrCanvas,
canvasStyle: vrDisplay ? vrCanvasStyles[options.screenViewEye] : null
}
return React.createElement(Canvas3D.contextType.Provider, {value: contextValue},
React.createElement(
BaseReactComponent,
utils.assign({}, props, {
vrAvailable,
vrDisplay,
vrButton
}),
props.children
)
)
}
}
const sphereGeom = new SphereBufferGeometry(0.5, 32, 32)
const boxGeom = new BoxBufferGeometry(1, 1, 1)
class WorldTexturedSphere extends Object3DFacade {
constructor(parent, subWorldTexture) {
super(parent, new Mesh(
sphereGeom,
new MeshStandardMaterial({
map: subWorldTexture
})
))
}
}
WorldTexturedSphere = makeWorldTextureProvider(WorldTexturedSphere)
class WorldTexturedBox extends Object3DFacade {
constructor(parent, subWorldTexture) {
super(parent, new Mesh(
boxGeom,
new MeshStandardMaterial({
map: subWorldTexture
})
))
}
}
WorldTexturedBox = makeWorldTextureProvider(WorldTexturedBox)
class AutoUpdatingArcsFacade extends ArcsFacade {
constructor(parent) {