1

I have a simple shape made in 3js with 8 points. The shape is without curves. I am not very good in absarc or curves in Threejs. I have tried to search online but I didn't get exact example.

My shape output:

enter image description here

While I need output like this:

enter image description here

James Z
  • 12,209
  • 10
  • 24
  • 44
USMANHEART
  • 93
  • 1
  • 9

1 Answers1

1

Just an option, using .absarc():

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, innerWidth / innerHeight, 1, 100);
camera.position.set(0, 0, 6);
var renderer = new THREE.WebGLRenderer({
  antialias: true
});
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);

var controls = new THREE.OrbitControls(camera, renderer.domElement);

var grid = new THREE.GridHelper(10, 10);
grid.rotation.x = -Math.PI * 0.5;
grid.position.set(0, 0, -0.01);
scene.add(grid);

var s = new THREE.Shape();
s.absarc(0, 0, 0.5, Math.PI * 0.5, -Math.PI * 0.5, true);
s.lineTo(0, -2);
s.absarc(-1, 0, Math.sqrt(2) * 2, -Math.PI * 0.25, Math.PI * 0.25, false);
s.lineTo(0, 2);

var sGeom = new THREE.ShapeBufferGeometry(s);
var sMat = new THREE.MeshBasicMaterial({
  color: "teal"
});
var shape = new THREE.Mesh(sGeom, sMat);
scene.add(shape);

var lineGeom = new THREE.BufferGeometry().setFromPoints(s.getPoints());
var lineMat = new THREE.LineBasicMaterial({
  color: "orange"
});
var outline = new THREE.LineLoop(lineGeom, lineMat);
scene.add(outline);

renderer.setAnimationLoop(() => {
  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>
prisoner849
  • 16,894
  • 4
  • 34
  • 68
  • the shape is exactly what I need. Can you also explain me absarc function. I can't get it's details. Only Threejs have it's definition but I have many questions. suppose my points are (1,1) and (1,6). I want same curve, how can I know the values of Radius, Starting Angle and Ending angle? I want details of every parameter. I would definitely appereciate you explaination. – USMANHEART Mar 16 '20 at 08:02
  • @USMANHEART I answered several questions of yours and got just more demanding questions in comments, and no reputation points. So the only way I can provide help is just point to other SO answers and papers in the internet. Read this: https://stackoverflow.com/q/22791951/4045502 – prisoner849 Mar 16 '20 at 08:40
  • All your answers I already knew it. I have tried that demos or examples before asking here. I need something else that is not explained in internet. By the way I have solved it. But this method you mentioned I have already tried, not useful in my case – USMANHEART May 18 '20 at 00:50
  • Considering the use of CSG technique is best way. – USMANHEART May 18 '20 at 00:51