Three.js Threejs多维数据集未显示其边缘
我正潜入三人世界。我选取了一个示例项目并对其进行了修改。我刚刚添加了一些带有颜色的立方体几何体。问题是,立方体几何体显示时没有边。你无法分辨这些脸的尽头,它们都被漂白了。不确定这是照明问题还是材质问题。我的代码如下Three.js Threejs多维数据集未显示其边缘,three.js,Three.js,我正潜入三人世界。我选取了一个示例项目并对其进行了修改。我刚刚添加了一些带有颜色的立方体几何体。问题是,立方体几何体显示时没有边。你无法分辨这些脸的尽头,它们都被漂白了。不确定这是照明问题还是材质问题。我的代码如下 <!DOCTYPE html> <html lang="en"> <head> <title>three.js webgl - cloth simulation</title> <m
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - cloth simulation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
<style>
body {
background-color: #cce0ff;
color: #000;
}
a {
color: #080;
}
</style>
</head>
<body>
<div id="info">Simple Cabinet Box in 3D Space<br/>
</div>
<script type="module">
import * as THREE from '../build/three.module.js';
//import Stats from './jsm/libs/stats.module.js';
import { GUI } from './jsm/libs/dat.gui.module.js';
import { OrbitControls } from './jsm/controls/OrbitControls.js';
function plane( width, height )
{
return function ( u, v, target )
{
const x = ( u - 0.5 ) * width;
const y = ( v + 0.5 ) * height;
const z = 0;
target.set( x, y, z );
};
}
let container;
let camera, scene, renderer;
init();
animate( 0 );
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
// scene
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xffffff );
// camera
camera = new THREE.PerspectiveCamera( 30, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.set( 0, 0, 100 );
// lights
//scene.add( new THREE.AmbientLight( 0x666666 ) );
const light = new THREE.DirectionalLight( 0xdfebff, 1 );
light.position.set( 50, 200, 100 );
light.position.multiplyScalar( 1.3 );
light.castShadow = true;
light.shadow.mapSize.width = 1024;
light.shadow.mapSize.height = 1024;
const d = 300;
light.shadow.camera.left = - d;
light.shadow.camera.right = d;
light.shadow.camera.top = d;
light.shadow.camera.bottom = - d;
light.shadow.camera.far = 1000;
scene.add( light );
//cabinet properties
const c_width = 24;
const c_height = 34.5;
const c_depth = 23.125;
const c_left_side_thickness = 0.75;
//Left End
const geometry = new THREE.BoxGeometry( c_left_side_thickness, c_height, c_depth);
const material = new THREE.MeshBasicMaterial( { color: 0xC2B8B6 } );
const left_side = new THREE.Mesh( geometry, material );
left_side.position.set((c_width/2)*-1 + c_left_side_thickness/2,0,0);
const right_side = new THREE.Mesh( geometry, material );
right_side.position.set(c_width/2 - c_left_side_thickness/2,0,0);
const geometry2 = new THREE.BoxGeometry( c_width - c_left_side_thickness * 2, c_left_side_thickness, c_depth);
const bottom = new THREE.Mesh( geometry2, material );
bottom.position.set(0,(c_height/2)*-1 + c_left_side_thickness/2,0);
const top = new THREE.Mesh( geometry2, material );
top.position.set(0,c_height / 2 - c_left_side_thickness/2,0);
const cabinet = new THREE.Group();
cabinet.add( left_side );
cabinet.add( right_side );
cabinet.add( bottom );
cabinet.add( top );
scene.add( cabinet );
//
// const geometry2 = new THREE.BoxGeometry( 10, 10, 10 );
// const edges = new THREE.EdgesGeometry( geometry2 );
// const line = new THREE.LineSegments( edges, new THREE.LineBasicMaterial( { color: 0xffffff } ) );
// line.position.set(0,100,0);
// scene.add( line );
// ground
const loader = new THREE.TextureLoader();
const groundTexture = loader.load( 'textures/terrain/grasslight-big.jpg' );
groundTexture.wrapS = groundTexture.wrapT = THREE.RepeatWrapping;
groundTexture.repeat.set( 25, 25 );
groundTexture.anisotropy = 16;
groundTexture.encoding = THREE.sRGBEncoding;
const groundMaterial = new THREE.MeshLambertMaterial( { map: groundTexture } );
let mesh = new THREE.Mesh( new THREE.PlaneGeometry( 20000, 20000 ), groundMaterial );
mesh.position.y = - 250;
mesh.rotation.x = - Math.PI / 2;
mesh.receiveShadow = true;
scene.add( mesh );
// renderer
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.shadowMap.enabled = true;
// controls
const controls = new OrbitControls( camera, renderer.domElement );
controls.maxPolarAngle = Math.PI * 0.5;
controls.minDistance = 100;
controls.maxDistance = 500;
window.addEventListener( 'resize', onWindowResize );
if ( typeof TESTING !== 'undefined' )
{
for ( let i = 0; i < 50; i ++ )
{
simulate( 500 - 10 * i );
}
}
}
function onWindowResize()
{
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate( now )
{
requestAnimationFrame( animate );
render();
}
function render()
{
renderer.render( scene, camera );
}
</script>
</body>
three.js webgl-布料模拟
身体{
背景色:#cce0ff;
颜色:#000;
}
a{
颜色:#080;
}
3D空间中的简单机柜盒
从“../build/THREE.module.js”将*作为三导入;
//从“/jsm/libs/Stats.module.js”导入统计信息;
从'./jsm/libs/dat.GUI.module.js'导入{GUI};
从“./jsm/controls/OrbitControls.js”导入{OrbitControls};
功能平面(宽度、高度)
{
返回函数(u、v、目标)
{
常数x=(u-0.5)*宽度;
常数y=(v+0.5)*高度;
常数z=0;
目标设定(x,y,z);
};
}
让容器;
让相机、场景、渲染器;
init();
动画(0);
函数init(){
container=document.createElement('div');
文件.正文.附件(容器);
//场面
场景=新的三个。场景();
scene.background=新的三种颜色(0xffffff);
//摄像机
摄像头=新的三个透视摄像头(30,window.innerWidth/window.innerHeight,11000);
摄像机位置设置(0,0,100);
//灯光
//添加(新的三个环境光(0x666666));
恒光=新的三方向光(0xdfebff,1);
光。位置。设置(50200100);
光、位置、多重刻度(1.3);
light.castShadow=true;
light.shadow.mapSize.width=1024;
light.shadow.mapSize.height=1024;
常数d=300;
light.shadow.camera.left=-d;
light.shadow.camera.right=d;
light.shadow.camera.top=d;
light.shadow.camera.bottom=-d;
light.shadow.camera.far=1000;
场景。添加(灯光);
//橱柜属性
常数c_宽度=24;
常数c_高度=34.5;
常数c_深度=23.125;
常数c_左侧_厚度=0.75;
//左端
const geometry=新的三箱几何(c_左侧厚度、c_高度、c_深度);
const material=new THREE.MeshBasicMaterial({color:0xC2B8B6});
const left_side=新的三个网格(几何体、材质);
左侧位置设置((c_宽度/2)*-1+c_左侧厚度/2,0,0);
const right_side=新的三个网格(几何体、材质);
右侧位置设置(c_宽度/2-c_左侧厚度/2,0,0);
const geometry2=新的三箱几何(c_宽度-c_左侧厚度*2,c_左侧厚度,c_深度);
const bottom=新的三个网格(geometry2,材质);
底部位置设置(0,(c_高度/2)*-1+c_左侧厚度/2,0);
const top=新的三个网格(geometry2,材质);
顶部位置设置(0,c_高度/2-c_左侧厚度/2,0);
const cabinet=new THREE.Group();
机柜。添加(左侧);
机柜。添加(右侧);
柜。添加(底部);
柜。添加(顶部);
场景。添加(橱柜);
//
//const geometry2=新的三箱几何体(10,10,10);
//常数边=新的三边几何(geometry2);
//const line=新的三个.LineSegments(边,新的三个.LineBasicMaterial({color:0xffffff}));
//行位置设置(0100,0);
//场景。添加(行);
//地面
const loader=new THREE.TextureLoader();
const groundTexture=loader.load('textures/terrain/grasslight big.jpg');
groundTexture.wrapps=groundTexture.wrapT=THREE.RepeatWrapping;
地面纹理。重复。设置(25,25);
地面纹理各向异性=16;
groundTexture.encoding=3.sRGBEncoding;
const groundMaterial=new THREE.meshlambertmater({map:groundTexture});
设mesh=new THREE.mesh(new THREE.PlaneGeometry(20000,20000),groundMaterial);
网格位置y=-250;
mesh.rotation.x=-Math.PI/2;
mesh.receiveShadow=true;
场景。添加(网格);
//渲染器
renderer=new THREE.WebGLRenderer({antialas:true});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth、window.innerHeight);
container.appendChild(renderer.doElement);
renderer.outpunecoding=3.sRGBEncoding;
renderer.shadowMap.enabled=true;
//控制
常量控件=新的轨道控件(摄影机、渲染器.doElement);
controls.maxPolarAngle=Math.PI*0.5;
controls.minDistance=100;
控件。最大距离=500;
addEventListener('resize',onWindowResize);
if(测试类型!==“未定义”)
{
for(设i=0;i<50;i++)
{
模拟(500-10*i);
}
}
}
函数onWindowResize()
{
camera.aspect=window.innerWidth/window.innerHeight;
camera.updateProjectMatrix();
renderer.setSize(window.innerWidth、window.innerHeight);
}
函数动画(现在)
{
请求动画帧(动画)