Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if(!addForceToBodyMaterial){
addForceToBodyMaterial = this.materials.addForceToBody = new THREE.ShaderMaterial({
uniforms: {
relativeParticlePosTex: { value: null },
particleForceTex: { value: null }
},
vertexShader: getShader( 'addParticleForceToBodyVert' ),
fragmentShader: getShader( 'addParticleForceToBodyFrag' ),
defines: this.getDefines(),
blending: THREE.AdditiveBlending,
transparent: true
});
// Scene for mapping the particle force to bodies - one GL_POINT for each particle
this.scenes.mapParticlesToBodies = new THREE.Scene();
var mapParticleToBodyGeometry = new THREE.BufferGeometry();
var numParticles = this.textures.particlePosLocal.width;
var bodyIndices = new Float32Array( numParticles * numParticles );
var particleIndices = new Float32Array( numParticles * numParticles );
for(var i=0; i
_setMesh(attributes) {
var geometry = new THREE.BufferGeometry();
// itemSize = 3 because there are 3 values (components) per vertex
geometry.addAttribute('position', new THREE.BufferAttribute(attributes.vertices, 3));
geometry.addAttribute('normal', new THREE.BufferAttribute(attributes.normals, 3));
geometry.addAttribute('color', new THREE.BufferAttribute(attributes.colours, 3));
if (attributes.pickingIds) {
geometry.addAttribute('pickingId', new THREE.BufferAttribute(attributes.pickingIds, 1));
}
geometry.computeBoundingBox();
var material;
if (this._options.material && this._options.material instanceof THREE.Material) {
material = this._options.material;
} else if (!this._world._environment._skybox) {
// Use default geometry if none has been provided or the provided geometry
// isn't valid
if (!this._options.geometry || (!this._options.geometry instanceof THREE.Geometry || !this._options.geometry instanceof THREE.BufferGeometry)) {
// Debug geometry for points is a thin bar
//
// TODO: Allow point geometry to be customised / overridden
var geometryWidth = this._world.metresToWorld(25, this._pointScale);
var geometryHeight = this._world.metresToWorld(200, this._pointScale);
var _geometry = new THREE.BoxGeometry(geometryWidth, geometryHeight, geometryWidth);
// Shift geometry up so it sits on the ground
_geometry.translate(0, geometryHeight * 0.5, 0);
// Pull attributes out of debug geometry
geometry = new THREE.BufferGeometry().fromGeometry(_geometry);
} else {
if (this._options.geometry instanceof THREE.BufferGeometry) {
geometry = this._options.geometry;
} else {
geometry = new THREE.BufferGeometry().fromGeometry(this._options.geometry);
}
}
// For each point
var attributes = this._projectedCoordinates.map(coordinate => {
var _vertices = [];
var _normals = [];
var _colours = [];
var _geometry = geometry.clone();
export function buildFromWorkerData(data: ITileBuffers): void {
const pos: number[] = getTilePosition(data.id);
const tileScale: number = getTileScale(data.id);
const bufferAttributeSize: number = 3;
const geometry: BufferGeometry = new BufferGeometry();
geometry.addAttribute("position", new BufferAttribute(new Float32Array(data.vertexBuffer), bufferAttributeSize));
geometry.addAttribute("color", new BufferAttribute(new Float32Array(data.colorBuffer), bufferAttributeSize));
geometry.addAttribute("normal", new BufferAttribute(new Float32Array(data.normalBuffer), bufferAttributeSize));
const tile: Mesh = new Mesh(geometry, TM.material);
tile.name = data.id;
TM.three_map.add(tile);
tile.scale.set(tileScale, 1, tileScale);
tile.position.set(pos[0], 0, -pos[1]);
TM.events.emit("tileCreated", { tile });
}
this.worker.postMessage(
{
verts,
faces,
params
},
[verts.buffer, faces.buffer]
);
const result = await navMeshPromise;
if (result.error) {
throw new Error(statuses[result.status] || result.error);
}
const navmesh = new BufferGeometry();
navmesh.addAttribute("position", new Float32BufferAttribute(result.verts, 3));
navmesh.setIndex(new Uint16BufferAttribute(result.indices, 1));
return navmesh;
}
}
geometry () {
this._geometry = new THREE.BufferGeometry();
if ( ( THREE.BufferGeometry.MaxIndex > 65535 ) && ( this._indices.length > 65535 ) ) {
this._geometry.setIndex( new THREE.BufferAttribute( new Uint32Array( this._indices ), 1 ) );
} else {
this._geometry.setIndex( new THREE.BufferAttribute( new Uint16Array( this._indices ), 1 ) );
}
if ( this._positions.length ) {
this._geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( this._positions ), 3 ) );
}
if ( this._colors.length ) {
this._geometry.addAttribute( 'color', new THREE.BufferAttribute( new Float32Array( this._colors ), 3 ) );
}
this._geometry.dynamic = false;
private _initHelper () {
const indices = new Uint16Array([
0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6,
6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7
])
const positions = new Float32Array(8 * 3)
const bbGeometry = new BufferGeometry()
bbGeometry.setIndex(new BufferAttribute(indices, 1))
bbGeometry.addAttribute('position', new BufferAttribute(positions, 3))
const bbMaterial = new ShaderMaterial({
uniforms: { 'uColor': { value: new Color('skyblue') } },
vertexShader: getShader('BasicLine.vert'),
fragmentShader: getShader('BasicLine.frag')
})
this.boundingBoxMesh = new LineSegments(bbGeometry, bbMaterial)
this.helperGroup.add(this.boundingBoxMesh)
}
var createPlaneForPostProcess = function() {
var geometry_base = new THREE.PlaneGeometry(2, 2);
var geometry = new THREE.BufferGeometry();
geometry.fromGeometry(geometry_base);
var material = new THREE.ShaderMaterial({
uniforms: {
time: {
type: 'f',
value: 0,
},
resolution: {
type: 'v2',
value: new THREE.Vector2(window.innerWidth, window.innerHeight)
},
acceleration: {
type: 'f',
value: 0
},
texture: {
static mergeStreetsAndAddToScene(scene, streets) {
let colors = [];
let normals = [];
let vertices = [];
let usedGeometries = CodeMapUtilities.generateUsedGeometries();
let originalGeometries = CodeMapUtilities.generateUsedGeometries();
let geometry = new THREE.BufferGeometry();
geometry.dynamic = true;
let mergedGeoId = geometry.id;
let leafs = [];
for (let i = 0; i < streets.length; i ++) {
CodeMapUtilities.extractLeafs(streets[i], leafs);
CodeMapUtilities.mergeObjects(leafs, mergedGeoId, usedGeometries, originalGeometries, colors, normals, vertices);
leafs.length = 0;
}
let positionAttribute = new THREE.Float32BufferAttribute(vertices, 3);
let normalAttribute = new THREE.Int16BufferAttribute(normals, 3);
let colorAttribute = new THREE.Uint8BufferAttribute(colors, 3);
normalAttribute.normalized = true;
colorAttribute .normalized = true;
pushUv(24, 38.5, Side.RIGHT);
positions.push(x + 1, pY, z + 1);
pushUv(24, 23.5, Side.RIGHT);
positions.push(x, pY, z + 1);
pushUv(48, 11.5, Side.RIGHT);
positions.push(x, pY - h, z + 1);
pushUv(48, 26.5, Side.RIGHT);
positions.push(x + 1, pY - h, z + 1);
pushUv(24, 38.5, Side.RIGHT);
}
idx += 1;
}
}
}
const bufferGeometry = new THREE.BufferGeometry();
bufferGeometry.setAttribute(
'position',
new THREE.BufferAttribute(new Float32Array(positions), 3)
);
bufferGeometry.setAttribute(
'uv',
new THREE.BufferAttribute(new Float32Array(uvs), 2)
);
const material = loadForExporting
? new THREE.MeshStandardMaterial({
transparent: true,
map: await convertTextureForExport(library.texture, library.index)
})
: new THREE.RawShaderMaterial({
vertexShader: compile('vert', brick_vertex),
fragmentShader: compile('frag', brick_fragment),