admin管理员组文章数量:1403516
I have polygon/polyhedron created with three.js? Is it possible to set border width and color for it? Here is my example code, you may see a figure in it. How to set borders? May be there are other ways to create polygons?
<html>
<head>
<title>Моё</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="../build/three.min.js"></script>
<script src=".js/js/OrbitControls.js"></script>
<script>
var phi = 0;
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 3000 );
//var camera = new THREE.OrthographicCamera( window.innerWidth / - 200, window.innerWidth / 200, window.innerHeight / 200, window.innerHeight / - 200, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var polyhedronShape, polyhedronPts = [], cube, mesh;
var container, scene, camera, renderer, controls, stats;
// CONTROLS
controls = new THREE.OrbitControls( camera, renderer.domElement );
polyhedronPts.push( new THREE.Vector2 ( 0, 60) );
polyhedronPts.push( new THREE.Vector2 ( 60, 60) );
polyhedronPts.push( new THREE.Vector2 ( 60, 0) );
polyhedronShape = new THREE.Shape( polyhedronPts );
var extrudeSettings = {amount: 20}; // bevelSegments: 2, steps: 2 , bevelSegments: 5, bevelSize: 8, bevelThickness:5
var geometry = new THREE.ExtrudeGeometry( polyhedronShape, extrudeSettings );
mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 0x00cc00 } ) );
//mesh.position.set( 0, 0, 0 );
//mesh.rotation.set( 0, 0, 100 );
//mesh.scale.set( 1, 1, 1 );
scene.add( mesh );
camera.position.z = 111;
//cube.position.x += 2;
var cam_z = 0.1, cam_max = 9, cam_min = 2;
function render() {
requestAnimationFrame( render );
controls.update();
if (Math.random() > 0.2) {
renderer.render( scene, camera );
//camera.position.z += cam_z;
}
}
render();
</script>
</body>
</html>
I have polygon/polyhedron created with three.js? Is it possible to set border width and color for it? Here is my example code, you may see a figure in it. How to set borders? May be there are other ways to create polygons?
<html>
<head>
<title>Моё</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="../build/three.min.js"></script>
<script src="http://stemkoski.github.io/Three.js/js/OrbitControls.js"></script>
<script>
var phi = 0;
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 3000 );
//var camera = new THREE.OrthographicCamera( window.innerWidth / - 200, window.innerWidth / 200, window.innerHeight / 200, window.innerHeight / - 200, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var polyhedronShape, polyhedronPts = [], cube, mesh;
var container, scene, camera, renderer, controls, stats;
// CONTROLS
controls = new THREE.OrbitControls( camera, renderer.domElement );
polyhedronPts.push( new THREE.Vector2 ( 0, 60) );
polyhedronPts.push( new THREE.Vector2 ( 60, 60) );
polyhedronPts.push( new THREE.Vector2 ( 60, 0) );
polyhedronShape = new THREE.Shape( polyhedronPts );
var extrudeSettings = {amount: 20}; // bevelSegments: 2, steps: 2 , bevelSegments: 5, bevelSize: 8, bevelThickness:5
var geometry = new THREE.ExtrudeGeometry( polyhedronShape, extrudeSettings );
mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 0x00cc00 } ) );
//mesh.position.set( 0, 0, 0 );
//mesh.rotation.set( 0, 0, 100 );
//mesh.scale.set( 1, 1, 1 );
scene.add( mesh );
camera.position.z = 111;
//cube.position.x += 2;
var cam_z = 0.1, cam_max = 9, cam_min = 2;
function render() {
requestAnimationFrame( render );
controls.update();
if (Math.random() > 0.2) {
renderer.render( scene, camera );
//camera.position.z += cam_z;
}
}
render();
</script>
</body>
</html>
Share
Improve this question
asked Jan 30, 2015 at 9:34
SomerussianSomerussian
3915 silver badges17 bronze badges
3
- WHat do you mean "you may see a figure in it"? Do you mean you want the edges of your polyhedron highlighted? Or do you want the outline effect described by @Wilt? – Bob Woodley Commented Jan 30, 2015 at 13:07
- I want to highlight edges – Somerussian Commented Feb 3, 2015 at 11:21
- Was my answer not what you were looking for? – Wilt Commented Jan 29, 2016 at 19:20
1 Answer
Reset to default 5I am not sure if this outline effect is what you are looking for, but it is a nice way to put a border around your objects:
Here a similar question where you find more examples and a working fiddle to fool around with.
It uses some WebGL native shader effect if I am not mistaken it is this part:
vertex_shader: [
"uniform float offset;",
"void main() {",
"vec4 pos = modelViewMatrix * vec4( position + normal * offset, 1.0 );",
"gl_Position = projectionMatrix * pos;",
"}"
].join("\n"),
本文标签: javascriptThreejshow to set borders to objectsStack Overflow
版权声明:本文标题:javascript - Three.js - how to set borders to objects? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744767555a2624133.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论