Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function ADT(data) {
var _this = this;
_classCallCheck(this, ADT);
this.data = data;
this.geometry = new THREE.Geometry();
var faces = this.geometry.faces = [];
var vertices = this.geometry.vertices = [];
var size = 33.333333;
var step = size / 8;
// See: http://www.pxr.dk/wowdev/wiki/index.php?title=ADT#MCVT_sub-chunk
for (var cy = 0; cy < 16; ++cy) {
var _loop = function () {
var cindex = cy * 16 + cx;
var chunk = _this.data.MCNKs[cindex];
chunk.MCVT.heights.forEach(function (height, index) {
var y = index; // 17
var x = index % 17;
if (x > 8) {
let defaults = {
mass: 0,
position: mesh.position,
friction: 0.3
};
options = Utils.setDefaults(options, defaults);
this.options = options;
let mat = new CANNON.Material("convMat");
mat.friction = options.friction;
// mat.restitution = 0.7;
if (this.mesh.geometry.isBufferGeometry)
{
this.mesh.geometry = new THREE.Geometry().fromBufferGeometry(this.mesh.geometry);
}
let cannonPoints = this.mesh.geometry.vertices.map((v) => {
return new CANNON.Vec3( v.x, v.y, v.z );
});
let cannonFaces = this.mesh.geometry.faces.map((f) => {
return [f.a, f.b, f.c];
});
let shape = new CANNON.ConvexPolyhedron(cannonPoints, cannonFaces);
// shape.material = mat;
// Add phys sphere
let physBox = new CANNON.Body({
mass: options.mass,
function drawPoint(entity, data) {
var geometry, material, point;
geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(entity.position.x, entity.position.y, entity.position.z));
// TODO: could be more efficient. PointCloud per layer?
var numPoints = 1;
var color = getColor(entity, data);
var colors = new Float32Array( numPoints*3 );
colors[0] = color.r;
colors[1] = color.g;
colors[2] = color.b;
geometry.colors = colors;
geometry.computeBoundingBox();
var postProcessWorld = function (json) {
var loader = new THREE.ObjectLoader();
var obj = loader.parse(json);
var mergedMeshesGeometry = new THREE.Geometry();
var mergedMaterialsCollection = [];
var entitiesCollection = new THREE.Object3D(),
ents = [];
entitiesCollection.name = 'Entities';
obj.traverse(function (child) {
if (child.userData.entity) {
if (obj.userData.entity) {
// Only if the parent is an entity, we save the uuid
// Otherwise it would be no use since the parent will be merged into one world mesh
child.parentUuid = obj.uuid;
}
// store to array for later (don't mess with the tree during traversal)
ents.push(child);
function getGeometry(solid) {
const truncated = getTruncated(solid, 0)
solid = getTruncated(solid, 1)
console.log(truncated, solid)
const geometry = new THREE.Geometry()
solid.vertices.forEach(vertex =>
geometry.vertices.push(new THREE.Vector3(...vertex)),
)
_.flatten(solid.faces.map(toTriangles)).forEach(face =>
geometry.faces.push(new THREE.Face3(...face)),
)
geometry.computeVertexNormals()
console.log('solid vertices', solid.vertices)
console.log('geometry vertices', geometry.vertices)
console.log(
'truncated vertices',
truncated.vertices.map(vertex => new THREE.Vector3(...vertex)),
)
geometry.morphTargets.push({
name: 'truncated',
vertices: truncated.vertices.map(vertex => new THREE.Vector3(...vertex)),
scene.add(new THREE.AmbientLight(0xffffff, 0.97));
const factory = new BlockModelFactory(textReg);
const o = factory.getObject(grassBlock);
scene.add(o);
const control = new THREE.OrbitControls(camera, renderer.domElement);
control.enableDamping = true;
control.dampingFactor = 0.2
control.zoomSpeed = 1.4
control.rotateSpeed = 0.6
control.enableKeys = false
{
const grid = new THREE.Geometry();
const gMat = new THREE.LineBasicMaterial({ color: 0xafafaf });
for (let i = -8; i < 8; ++i) {
grid.vertices.push(new THREE.Vector3(-8, -8, i));
grid.vertices.push(new THREE.Vector3(8, -8, i));
grid.vertices.push(new THREE.Vector3(i, -8, -8));
grid.vertices.push(new THREE.Vector3(i, -8, 8));
}
grid.vertices.push(new THREE.Vector3(-1, -8, 9));
grid.vertices.push(new THREE.Vector3(1, -8, 9));
grid.vertices.push(new THREE.Vector3(1, -8, 9));
grid.vertices.push(new THREE.Vector3(0, -8, 10));
grid.vertices.push(new THREE.Vector3(0, -8, 10));
grid.vertices.push(new THREE.Vector3(-1, -8, 9));
if (this.m_boundLines[i] !== undefined) {
this.m_scene.remove(this.m_boundLines[i].getRenderObject());
}
}
for (let i = 0; i < this.m_meshes.length; ++i) {
if (this.m_meshes[i] !== undefined) {
this.m_scene.remove(this.m_meshes[i]);
}
}
this.clearControlLines();
this.m_geo[PROJECTION_X].dispose();
this.m_geo[PROJECTION_Y].dispose();
this.m_geo[PROJECTION_Z].dispose();
this.m_geo[PROJECTION_X] = new THREE.Geometry();
this.m_geo[PROJECTION_Y] = new THREE.Geometry();
this.m_geo[PROJECTION_Z] = new THREE.Geometry();
this.m_material[PROJECTION_X] = null;
this.m_material[PROJECTION_Y] = null;
this.m_material[PROJECTION_Z] = null;
this.m_meshes.fill(undefined);
}
/**
_createController() {
if (this._mesh) {
return;
}
const beamGeom = new THREE.Geometry();
beamGeom.vertices.push(
new THREE.Vector3(-0.01, 0.01, 0),
new THREE.Vector3(0.01, 0.01, 0),
new THREE.Vector3(0.01, 0.01, -1),
new THREE.Vector3(-0.01, 0.01, -1),
new THREE.Vector3(-0.01, -0.01, 0),
new THREE.Vector3(0.01, -0.01, 0),
new THREE.Vector3(0.01, -0.01, -1),
new THREE.Vector3(-0.01, -0.01, -1),
);
beamGeom.faces.push(
new THREE.Face3(0, 1, 3),
new THREE.Face3(1, 2, 3),
new THREE.Face3(1, 5, 2),
new THREE.Face3(5, 6, 2),
const step = 360 / subdivisions;
const cutIndexStart = Math.floor((cutStart.longitude + 180) / step);
const cutIndexEnd = Math.ceil((cutEnd.longitude + 180) / step);
for (let i = cutIndexStart + 1; i < cutIndexEnd; i++) {
points.push(new GeoCoordinates(poleLat, i * step - 180, 0));
}
points.push(cutEnd);
if (inPointD) {
points.push(d);
}
}
const g = new THREE.Geometry();
for (const point of points) {
const projected = dstProjection.projectPoint(point, new THREE.Vector3());
g.vertices.push(projected.sub(tile.center));
}
for (let i = 1; i < points.length - 1; i++) {
g.faces.push(isNorthPole ? new THREE.Face3(0, i, i + 1) : new THREE.Face3(0, i + 1, i));
}
const geometry = new THREE.BufferGeometry();
geometry.fromGeometry(g);
g.dispose();
const mesh = new THREE.Mesh(geometry, material);
mesh.userData = {
_drawGrid() {
var gridGeometry, gridMaterial, mainGridZ, planeFragmentShader, planeGeometry, planeMaterial, subGridGeometry, subGridMaterial, subGridZ;
//offset to avoid z fighting
mainGridZ = -0.05;
gridGeometry = new THREE.Geometry();
gridMaterial = new THREE.LineBasicMaterial({
color: new THREE.Color().setHex(this.color),
opacity: this.opacity,
linewidth: 2,
transparent: true
});
subGridZ = -0.05;
subGridGeometry = new THREE.Geometry();
subGridMaterial = new THREE.LineBasicMaterial({
color: new THREE.Color().setHex(this.color),
opacity: this.opacity / 2,
transparent: true
});
var step = this.step;