How to group Buffer Geometry Object in Autodesk Forge - three.js

I wondering is it posssible to add group of model group from scenebuilder. Initially I used a overlay.addMesh but I wanted to interact with a custom object that I created. Unfortunately the object must be a grouping. This is my code. Nothing appear on my Viewer.
this.sceneBuilder = await this.viewer.loadExtension(
"Autodesk.Viewing.SceneBuilder"
);
this.modelBuilder = await this.sceneBuilder.addNewModel({
modelNameOverride: "Beacon",
conserveMemory: false,
});
const sphereGeometry = new THREE.BufferGeometry().fromGeometry(
new THREE.SphereGeometry(5, 8, 8)
);
const sphereMaterial = new THREE.MeshPhongMaterial({
color: new THREE.Color(0.647, 0.165, 0.165),
});
this.meshBeacon = new THREE.Mesh(sphereGeometry, sphereMaterial);
this.meshBeacon2 = new THREE.Mesh(sphereGeometry, sphereMaterial);
this.meshBeacon.matrix = new THREE.Matrix4().compose(
position1,
quaternion,
scale
);
this.meshBeacon2.matrix = new THREE.Matrix4().compose(
position2,
quaternion,
scale
);
this.group = new THREE.Group();
this.group.add(this.meshBeacon);
this.group.add(this.meshBeacon2);
console.log(this.group);
this.group.dbId = 666666;
this.modelBuilder.addMesh(this.group);

We need to create single Geometry first. All done by this code.
let modelGeometry = new THREE.Geometry();
const globalMaterial = new THREE.MeshBasicMaterial({ color: 0xff0000 });
const head = new THREE.SphereGeometry(0.5, 32, 16);
const body = new THREE.SphereGeometry(0.5, 32, 16);
const textGeometry = new THREE.TextGeometry("text ID", {
font: "monaco",
size: 1,
height: 0,
curveSegments: 3,
});
textGeometry.computeBoundingBox();
const textMaterial = new THREE.MeshBasicMaterial({ color: 0xff0000 });
const workerId = new THREE.Mesh(textGeometry, textMaterial);
const headMesh = new THREE.Mesh(head, globalMaterial);
const bodyMesh = new THREE.Mesh(body, globalMaterial);
headMesh.matrix.setPosition(new THREE.Vector3(0, 0, 3));
bodyMesh.matrix.scale(new THREE.Vector3(1, 1, 4));
// bodyMesh.matrix.scale(new THREE.Vector3(0.1, 0.1, 0.1));
modelGeometry.merge(headMesh.geometry, headMesh.matrix);
modelGeometry.merge(bodyMesh.geometry, bodyMesh.matrix);
modelGeometry.merge(workerId.geometry, workerId.matrix);

Related

How to keep separate materials of merged Geometry

I managed to merge 2 pieces of geometry, namely plane and text. But the two materials must be separated at the end. How to do this ?
const globalMaterial = new THREE.MeshBasicMaterial({ color: 0xff0000 });
const texture = THREE.ImageUtils.loadTexture(
"http://127.0.0.1:8080/pin_png/img_gps_dasloop_online.png"
);
texture.minFilter = THREE.LinearFilter;
const workerMaterial = new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
});
const planeGeometry = new THREE.PlaneGeometry(1, 1);
const textGeometry = new THREE.TextGeometry(`Id : ${dbId}`, {
font: "monaco",
size: 1,
height: 0,
curveSegments: 3,
});
textGeometry.computeBoundingBox();
const workerIdMesh = new THREE.Mesh(textGeometry, globalMaterial);
const workerMesh = new THREE.Mesh(planeGeometry, workerMaterial);
// Merging
modelGeometry.merge(workerMesh.geometry, workerMesh.matrix);
modelGeometry.merge(workerIdMesh.geometry, workerIdMesh.matrix);
modelGeometry.computeVertexNormals();
const workerBufferGeometry = new THREE.BufferGeometry().fromGeometry(
modelGeometry
);
this.humanModel = new THREE.Mesh(workerBufferGeometry, workerMaterial);

How to access camera three.js editor?

How do I access the standard camera in the three.js editor? I am trying to make a scene with a portal, in the scene I have two cameras (one inside the cube map) to project the image into the portal. In the case of a local project, everything works fine for me, but in the case of creating a similar scene in the editor, everything goes down a bad path. It seems to me that the reason is that when you click on PLAY, a new camera is created. I attach the script of the scene below. I hope that a solution will be found.
var mainMover, otherMover;
var otherCamera;
var portalA, portalB;
var portalRing;
function init() {
otherCamera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000);
//console.log(this.children[3].children[0]);
let ambientLight = new THREE.AmbientLight(0xcccccc, 1.00);
scene.add(ambientLight);
deltaTime = 0;
totalTime = 0;
let loader = new THREE.TextureLoader();
let defaultMaterial = new THREE.MeshBasicMaterial({
map: loader.load("https://raw.githubusercontent.com/stemkoski/AR-Examples/master/images/sphere-colored.png"),
color: 0x444444,
side: THREE.DoubleSide,
transparent: true
});
// Portal A ================================
portalA = new THREE.Mesh(
new THREE.CircleGeometry(1, 64),
defaultMaterial.clone()
);
portalA.material.opacity = 0.5;
portalA.position.set(-22, 0.5, -3);
portalA.rotation.y = Math.PI / 4;
portalA.layers.set(1);
scene.add(portalA);
portalRing = new THREE.Mesh(
new THREE.RingGeometry(1, 1.1, 64),
new THREE.MeshBasicMaterial({ color: 0xffff00, side: THREE.DoubleSide, transparent: true })
);
portalRing.position.copy(portalA.position);
portalRing.rotation.copy(portalA.rotation);
portalRing.layers.set(0);
scene.add(portalRing);
mainMover = new THREE.Group();
mainMover.position.set(-21, 0.5, 0);
mainMover.add(camera);
mainMover.name = "mainMover";
scene.add(mainMover);
// Portal B - ================================
let skyMaterialArray2 = [
new THREE.MeshBasicMaterial({ map: loader.load("https://raw.githubusercontent.com/stemkoski/AR-Examples/master/images/mountain/posx.jpg"), side: THREE.BackSide }),
new THREE.MeshBasicMaterial({ map: loader.load("https://raw.githubusercontent.com/stemkoski/AR-Examples/master/images/mountain/negx.jpg"), side: THREE.BackSide }),
new THREE.MeshBasicMaterial({ map: loader.load("https://raw.githubusercontent.com/stemkoski/AR-Examples/master/images/mountain/posy.jpg"), side: THREE.BackSide }),
new THREE.MeshBasicMaterial({ map: loader.load("https://raw.githubusercontent.com/stemkoski/AR-Examples/master/images/mountain/negy.jpg"), side: THREE.BackSide }),
new THREE.MeshBasicMaterial({ map: loader.load("https://raw.githubusercontent.com/stemkoski/AR-Examples/master/images/mountain/posz.jpg"), side: THREE.BackSide }),
new THREE.MeshBasicMaterial({ map: loader.load("https://raw.githubusercontent.com/stemkoski/AR-Examples/master/images/mountain/negz.jpg"), side: THREE.BackSide }),
];
let skyMesh2 = new THREE.Mesh(
new THREE.BoxGeometry(30, 30, 30),
skyMaterialArray2);
skyMesh2.position.x = 20;
scene.add(skyMesh2);
portalB = new THREE.Mesh(
new THREE.CircleGeometry(1, 64),
defaultMaterial.clone()
);
portalB.material.opacity = 0.5;
portalB.position.set(24, 0.5, -5);
portalB.rotation.y = -Math.PI / 4;
portalB.layers.set(2);
scene.add(portalB);
otherMover = new THREE.Group();
otherMover.add(otherCamera);
scene.add(otherMover);
}
function update() {
portalRing.material.color.setHSL(totalTime / 10 % 1, 1, 0.75);
let relativePosition = portalA.worldToLocal(mainMover.position.clone());
otherMover.position.copy(portalB.localToWorld(relativePosition));
let relativeRotation = mainMover.quaternion.clone().multiply(portalA.quaternion.clone().invert());
otherMover.quaternion.copy(relativeRotation.multiply(portalB.quaternion));
otherCamera.rotation.x = camera.rotation.x;
render()
}
function render() {
camera.layers.enable(0);
camera.layers.enable(1);
renderer.render(scene, camera);
let gl = renderer.getContext();
renderer.clear(true, true, true);
renderer.autoClear = false;
// FIRST PASS (enable stencil buffer)
gl.enable(gl.STENCIL_TEST);
camera.layers.set(1);
gl.stencilFunc(gl.ALWAYS, 1, 0xff);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.REPLACE);
gl.stencilMask(0xff);
gl.colorMask(false, false, false, false);
gl.depthMask(false);
renderer.render(scene, camera);
//SECOND PASS
let portalToCamera = new THREE.Vector3().subVectors(mainMover.position.clone(), portalA.position.clone()); // applyQuaternion( mainMover.quaternion );
let normalPortal = new THREE.Vector3(0, 0, 1).applyQuaternion(portalA.quaternion);
let clipSide = -Math.sign(portalToCamera.dot(normalPortal));
let clipNormal = new THREE.Vector3(0, 0, clipSide).applyQuaternion(portalB.quaternion);
let clipPoint = portalB.position;
let clipPlane = new THREE.Plane().setFromNormalAndCoplanarPoint(clipNormal, clipPoint);
renderer.clippingPlanes = [clipPlane];
gl.colorMask(true, true, true, true);
gl.depthMask(true);
gl.stencilFunc(gl.EQUAL, 1, 0xff);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
otherCamera.layers.set(0);
renderer.render(scene, otherCamera);
renderer.clippingPlanes = [];
//THIRD PASS
gl.disable(gl.STENCIL_TEST);
gl.colorMask(false, false, false, false);
gl.depthMask(true);
renderer.clear(false, true, false);
renderer.render(scene, camera);
//FINAL PASS
gl.colorMask(true, true, true, true);
gl.depthMask(true);
camera.layers.set(0);
renderer.render(scene, camera);
renderer.autoClear = true;
}
UPDATE:
I added a helper for the camera, so the main camera should be in place of the cube. But, for some reason, when PLAYING, I find myself not in the place of this cube... (just create a mesh: let mainCameraMesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), new THREE.MeshBasicMaterial());
When you create a script in the three.js editor, you have access to certain global variables within the update() function. Next to the renderer and scene, you can also access the perspective camera. Just try this:
function update( event ) {
console.log( camera );
}

three js - How a sphere can shine inside it emitting light to all directions

How to make the sun as a sphere shine inside it and radiate light in all directions?
thanks in advance
I have only this rendering at screen the SUN in the center and a box to see how light reflects to it.
// create a geometry
const radius = 2;
const widthSegments = 100;
const heightSegments = 96;
const geometry = new THREE.SphereBufferGeometry(
radius,
widthSegments,
heightSegments
);
const geometry1 = new THREE.BoxBufferGeometry(3, 13, 3);
//create texture loader
const textureLoader = new THREE.TextureLoader();
const texture = textureLoader.load("https://i.ibb.co/3srcxqp/Sol.jpg");
texture.encoding = THREE.sRGBEncoding;
texture.anisotropy = 16;
const material = new THREE.MeshStandardMaterial({
map: texture,
color: "#ffffff",
specular: "#ffffff",
transparent: true,
side: THREE.DoubleSide,
alphaTest: 0.5,
opacity: 1,
roughness: 1,
});
material.alphaMap = texture;
material.alphaMap.magFilter = THREE.NearestFilter;
material.alphaMap.wrapT = THREE.RepeatWrapping;
material.alphaMap.repeat.y = 1;
var material1 = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
mesh = new THREE.Mesh(geometry, material);
const mesh1 = new THREE.Mesh(geometry1, material1);
scene.add(mesh);
scene.add(mesh1);
mesh1.position.set(-10, -10, -10);
mesh1.updateMatrix();

ThreeJS: How to clone the rotation of one object to another

I have two canvas where two canvas has two different objects. I'm trying to set the rotation of one object to another. Here the second canvas object acts as a viewcube where it should only rotate when the object_1 gets rotated.
I have tried by set the rotation of the one camera to another but I can't seem to achieve it.
Here's the fiddle link https://jsfiddle.net/jvy396x8/2/
var cube = document.querySelector('.cube');
// var container = document.getElementById('container');
var scene_1Rotation;
var scene = new THREE.Scene();
var scene_1 = new THREE.Scene();
var object;
var w = window.innerWidth;
var h = window.innerHeight;
var viewSize = h;
var aspectRatio = w / h;
_viewport = {
viewSize: viewSize,
aspectRatio: aspectRatio,
left: (-aspectRatio * viewSize) / 2,
right: (aspectRatio * viewSize) / 2,
top: viewSize / 2,
bottom: -viewSize / 2,
near: -10000,
far: 10000
}
var camera = new THREE.OrthographicCamera(
_viewport.left,
_viewport.right,
_viewport.top,
_viewport.bottom,
_viewport.near,
_viewport.far
);
camera.zoom = 25;
var camera_1 = new THREE.PerspectiveCamera(100, window.innerWidth / window.innerHeight, 0.001, 1000000);
// var camera = new THREE.OrthographicCamera(window.innerWidth / -30, window.innerWidth / 30, window.innerHeight / 30, window.innerHeight / -30, 1, 1000)
camera.position.set(20, 0, 0);
var renderer = new THREE.WebGLRenderer({
antialias: true
});
var renderer_1 = new THREE.WebGLRenderer({
antialias: true
});
$('#container').append(renderer_1.domElement);
$('#scene').html(renderer_1.domElement);
// var zoom = orthoWidth / meshWidth;
// _Camera.setZoom(zoom);
object = new THREE.Group();
scene.background = new THREE.Color(0xffffff0);
console.log(scene);
scene_1.background = new THREE.Color(0xffffff);
console.log(scene_1);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var controls = new THREE.OrbitControls(camera, renderer.domElement);
var controls_1 = new THREE.OrbitControls(camera_1, renderer_1.domElement);
var geometry_1 = new THREE.BoxGeometry();
var material_1 = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
var cube_1 = new THREE.Mesh(geometry_1, material_1);
scene_1.add(cube_1);
var geometry_2 = new THREE.BoxGeometry();
var material_2 = new THREE.MeshBasicMaterial({ color: 0x00fff0 });
var cube_2 = new THREE.Mesh(geometry_2, material_2);
cube_2.position.x = 1;
scene_1.add(cube_2);
controls_1.noPan = true;
controls_1.noZoom = true;
camera_1.position.z = 2;
var material = new THREE.LineBasicMaterial({
color: 0x0000ff
});
var geometry = new THREE.Geometry();
geometry.vertices.push(
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, 7, 0),
new THREE.Vector3(0, 0, 0)
);
var line = new THREE.Line(geometry, material);
object.add(line)
scene.add(object);
var material = new THREE.LineBasicMaterial({
color: 0xcc0000
});
var geometry = new THREE.Geometry();
geometry.vertices.push(
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(7, 0, 0)
);
var line = new THREE.Line(geometry, material);
object.add(line)
scene.add(object);
var material = new THREE.LineBasicMaterial({
color: 0x008900
});
var geometry = new THREE.Geometry();
geometry.vertices.push(
new THREE.Vector3(0, 0, 7),
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, 0, 0)
);
var line = new THREE.Line(geometry, material);
object.add(line)
scene.add(object);
// ' X ' AXIS dashed material |
var xPlaneDashedMaterial = new THREE.LineDashedMaterial({ color: 0x00008b, dashSize: Math.PI * 2 / 20, gapSize: Math.PI * 2 / 20, linewidth: 10 }),
xPlaneDashedCircleGeometry = new THREE.CircleGeometry(7, 75, 69.9, 5);
xPlaneDashedCircleGeometry.vertices.shift();
var xPlaneDashedGeomtry = new THREE.Line(xPlaneDashedCircleGeometry, xPlaneDashedMaterial);
xPlaneDashedGeomtry.computeLineDistances();
object.add(xPlaneDashedGeomtry)
scene.add(object);
var xPlanePlainMaterial = new THREE.MeshBasicMaterial({ color: 0x00008b });
var xplanePlainCirleGeometry = new THREE.CircleGeometry(7, 75, 18.3, 1.3);
xplanePlainCirleGeometry.vertices.shift();
var xPlanePlainGeomtry = new THREE.Line(xplanePlainCirleGeometry, xPlanePlainMaterial);
object.add(xPlanePlainGeomtry)
scene.add(object);
// ' Y ' AXIS dashed material -
var yPlaneDashedMaterial = new THREE.LineDashedMaterial({ color: 0xcc0000, dashSize: Math.PI * 2 / 20, gapSize: 1 * Math.PI * 2 / 20, linewidth: 10 });
var yPlaneDashedCircleGeometry = new THREE.CircleGeometry(7, 30, 7., 4.8);
yPlaneDashedCircleGeometry.vertices.shift();
var yPlaneDashedGeomtry = new THREE.Line(yPlaneDashedCircleGeometry, yPlaneDashedMaterial);
yPlaneDashedGeomtry.computeLineDistances();
yPlaneDashedGeomtry.rotation.x = 17.27;
object.add(yPlaneDashedGeomtry)
scene.add(object);
var yPlanePlainMaterial = new THREE.MeshBasicMaterial({ color: 0xcc0000 });
var yPlanePlainCirleGeometry = new THREE.CircleGeometry(7, 75, 18.1, 1.5);
yPlanePlainCirleGeometry.vertices.shift();
var yPlanePlainGeomtry = new THREE.Line(yPlanePlainCirleGeometry, yPlanePlainMaterial);
yPlanePlainGeomtry.rotation.x = 17.27;
object.add(yPlanePlainGeomtry)
scene.add(object);
// ' Z ' AXIS material /
var zPlanePlainMaterial = new THREE.LineDashedMaterial({ color: 0x008900, dashSize: 1 * Math.PI * 4 / 40, gapSize: 1 * Math.PI * 4 / 40, linewidth: 10 });
var zPlanePlainCirleGeometry = new THREE.CircleGeometry(7, 75, 69.9, 10);
zPlanePlainCirleGeometry.vertices.shift();
var zPlanePlainGeomtry = new THREE.Line(zPlanePlainCirleGeometry, zPlanePlainMaterial);
zPlanePlainGeomtry.computeLineDistances();
zPlanePlainGeomtry.rotation.y = 17.27;
object.add(zPlanePlainGeomtry)
scene.add(object);
// ' X 'CONE geomtry|
var xPlaneConeGeometry = new THREE.ConeGeometry(0.2, 1, 32);
var xPlaneConeGeomtryMaterial = new THREE.MeshBasicMaterial({ color: 0x00008b });
var xPlaneConeGeometryLeft = new THREE.Mesh(xPlaneConeGeometry, xPlaneConeGeomtryMaterial);
object.add(xPlaneConeGeometryLeft)
scene.add(object);
//' X ' CONE
xPlaneConeGeometryLeft.position.y = 6.5;
//' Y 'CONE geomtry
var yPlaneConeGeometry = new THREE.ConeGeometry(0.2, 1, 32);
var yPlaneConeGeomtryMaterial = new THREE.MeshBasicMaterial({ color: 0xcc0000 });
var zPlaneConeGeometry = new THREE.ConeGeometry(0.2, 1, 32);
var zPlaneConeGeomtryMaterial = new THREE.MeshBasicMaterial({ color: 0x008900 });
var yPlaneConeGeometryLeft = new THREE.Mesh(yPlaneConeGeometry, yPlaneConeGeomtryMaterial);
object.add(yPlaneConeGeometryLeft);
scene.add(object);
var zPlaneConeGeometryRight = new THREE.Mesh(zPlaneConeGeometry, zPlaneConeGeomtryMaterial);
object.add(zPlaneConeGeometryRight)
scene.add(object);
console.log("object");
console.log(object.children.rotation);
// ' Y ' CONE
yPlaneConeGeometryLeft.position.x = 6.5;
yPlaneConeGeometryLeft.rotation.z = 4.7;
zPlaneConeGeometryRight.position.z = 6.5;
zPlaneConeGeometryRight.rotation.x = 1.6;
var mat = new THREE.Matrix4();
renderer_1.setAnimationLoop(() => {
mat.extractRotation(camera_1.matrixWorldInverse);
renderer_1.render(scene_1, camera_1);
camera_1.updateProjectionMatrix();
});
renderer.setAnimationLoop(() => {
mat.extractRotation(camera.matrixWorldInverse);
renderer.render(scene, camera);
camera.updateProjectionMatrix();
});
I have tried by set the rotation of the one camera to another by I can't able to achieve it.
To replicate the intended behavior in the second scene, it's not sufficient to just copy the rotation. Orbiting also transforms the position of the camera. Hence I suggest that you use a single camera for both scenes.
Also note that it's not necessary to update the projection matrix of your camera per frame. In your use case, do it once right after changing the zoom property.
Updated fiddle: https://jsfiddle.net/s0wzdm32/1/

How to draw Shape geometry with 3d points(x,y,z) using threejs which is not flat shape(surface)

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.set(0, 10, 300);
var renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var controls = new THREE.TrackballControls(camera, renderer.domElement);
var light = new THREE.DirectionalLight(0xffffff, 0.5);
light.position.setScalar(100);
scene.add(light);
scene.add(new THREE.AmbientLight(0xffffff, 0.5));
var closedSpline = new THREE.CatmullRomCurve3([
new THREE.Vector3(-60, -100, -10),
new THREE.Vector3(-60, 20, 0),
new THREE.Vector3(-60, 120, -20),
new THREE.Vector3(60, 120, 0),
new THREE.Vector3(60, -100, 10)
]);
closedSpline.curveType = 'catmullrom';
closedSpline.closed = true;
var closedSpline1 = new THREE.CatmullRomCurve3([
new THREE.Vector3(-50, -90, -10),
new THREE.Vector3(-50, 10, 0),
new THREE.Vector3(-50, 110, -20),
new THREE.Vector3(50, 110, 0),
new THREE.Vector3(50, -90, 10)
]);
closedSpline1.curveType = 'catmullrom';
closedSpline1.closed = true;
var tubeGeometry = new THREE.TubeBufferGeometry(closedSpline, 100, 1, 5, true);
var material = new THREE.MeshLambertMaterial({
color: 0xb00000,
wireframe: false
});
var mesh = new THREE.Mesh(tubeGeometry, material);
scene.add(mesh);
var tubeGeometry1 = new THREE.TubeBufferGeometry(closedSpline1, 100, 1, 5,true);
var material1 = new THREE.MeshLambertMaterial({
color: 0xb00000,
wireframe: false
});
var mesh1 = new THREE.Mesh(tubeGeometry1, material1);
scene.add(mesh1);
// magic starts here
var shape = new THREE.Shape(closedSpline1.getPoints(100)); // make a shape
shape.holes.push(new THREE.Path(closedSpline1.getPoints(100))); // add a hole
var shapeGeometry = new THREE.ShapeGeometry(shape); // create a geometry
var track = new THREE.Mesh(shapeGeometry, new THREE.MeshLambertMaterial({
color: "yellow",
side:THREE.DoubleSide,
})); // create a track from the geometry
scene.add(track);
render();
function render() {
requestAnimationFrame(render);
controls.update();
renderer.render(scene, camera);
}
Above is my code which draw two tube geometry using THREE.CatmullRomCurve3 points and surface between those two tubes. Issue i am facing is surface between those two tubes(Track in above code) is always flat(2d) instead of 3d. I think THREE.Shape() are not using z axis values to draw surface. Can anybody guide me to right direction or some related samples. Thanks
You can do the trick, using concatenated sets of points from curves and THREE.PlaneGeometry():
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.set(0, 10, 300);
var renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var controls = new THREE.OrbitControls(camera, renderer.domElement);
var light = new THREE.DirectionalLight(0xffffff, 0.5);
light.position.setScalar(100);
scene.add(light);
scene.add(new THREE.AmbientLight(0xffffff, 0.5));
var closedSpline = new THREE.CatmullRomCurve3([
new THREE.Vector3(-60, -100, -10),
new THREE.Vector3(-60, 20, 0),
new THREE.Vector3(-60, 120, -20),
new THREE.Vector3(60, 120, 0),
new THREE.Vector3(60, -100, 10)
]);
closedSpline.curveType = 'catmullrom';
closedSpline.closed = true;
var closedSpline1 = new THREE.CatmullRomCurve3([
new THREE.Vector3(-50, -90, -10),
new THREE.Vector3(-50, 10, 0),
new THREE.Vector3(-50, 110, -20),
new THREE.Vector3(50, 110, 0),
new THREE.Vector3(50, -90, 10)
]);
closedSpline1.curveType = 'catmullrom';
closedSpline1.closed = true;
var tubeGeometry = new THREE.TubeBufferGeometry(closedSpline, 100, 1, 5, true);
var material = new THREE.MeshLambertMaterial({
color: 0xb00000,
wireframe: false
});
var mesh = new THREE.Mesh(tubeGeometry, material);
scene.add(mesh);
var tubeGeometry1 = new THREE.TubeBufferGeometry(closedSpline1, 100, 1, 5,
true);
var material1 = new THREE.MeshLambertMaterial({
color: 0xb00000,
wireframe: false
});
var mesh1 = new THREE.Mesh(tubeGeometry1, material1);
scene.add(mesh1);
// magic starts here
var points1 = closedSpline.getPoints(100); // get the first set of points
var points2 = closedSpline1.getPoints(100); // get the second set of points
var allPoints = points1.concat(points2); // concatenate them
var planeGeom = new THREE.PlaneGeometry(1, 1, 100, 1); // create a plane geometry
planeGeom.vertices = allPoints; // replace its vertices with the previously concatenated array of points
planeGeom.computeFaceNormals();
planeGeom.computeVertexNormals();
var track = new THREE.Mesh(planeGeom, new THREE.MeshLambertMaterial({
color: "yellow",
wireframe: false
}));
scene.add(track);
render();
function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
body {
overflow: hidden;
margin: 0;
}
<script src="https://threejs.org/build/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>

Resources