mirror of https://gitee.com/cf-fz/WebCAD.git
parent
df3aa141a4
commit
a35b91fb8d
@ -1,399 +0,0 @@
|
||||
import { Clock, CubeTextureLoader, HemisphereLight, Mesh, MeshStandardMaterial, PlaneGeometry, PointLight, RepeatWrapping, RGBFormat, SphereGeometry, TextureLoader } from 'three';
|
||||
import { begin } from 'xaop';
|
||||
import { app } from '../ApplicationServices/Application';
|
||||
import { Command } from '../Editor/CommandMachine';
|
||||
|
||||
export class DrawFloor implements Command
|
||||
{
|
||||
textureLoader: TextureLoader;
|
||||
|
||||
get scene()
|
||||
{
|
||||
return app.Viewer.Scene;
|
||||
}
|
||||
constructor()
|
||||
{
|
||||
this.textureLoader = new TextureLoader();
|
||||
}
|
||||
async exec()
|
||||
{
|
||||
app.Viewer.Camera.position.set(0, 0, 2);
|
||||
this.drawFloor();
|
||||
|
||||
this.drawLight();
|
||||
this.drawHemiLight();
|
||||
|
||||
// this.drawWall();
|
||||
|
||||
// this.drawBox();
|
||||
// //绘制一个盒子 带反射
|
||||
// this.drawBox2();
|
||||
|
||||
|
||||
this.loadMaterial();
|
||||
|
||||
app.Viewer.Renderer.toneMappingExposure = Math.pow(0.68, 5.0); // to allow for very bright scenes.
|
||||
}
|
||||
|
||||
async loadFbx()
|
||||
{
|
||||
// let obj = await loadFBX("123456.FBX");
|
||||
|
||||
// this.scene.add(obj.object);
|
||||
}
|
||||
|
||||
private drawFloor()
|
||||
{
|
||||
let floorMat = new MeshStandardMaterial({
|
||||
roughness: 0.8,
|
||||
color: 0xffffff,
|
||||
metalness: 0.2,
|
||||
bumpScale: 0.0005,
|
||||
transparent: true,
|
||||
opacity: 0.9
|
||||
});
|
||||
this.materialList.push(floorMat);
|
||||
|
||||
var floorGeometry = new PlaneGeometry(20, 20);
|
||||
var floorMesh = new Mesh(floorGeometry, floorMat);
|
||||
floorMesh.receiveShadow = true;
|
||||
this.scene.add(floorMesh);
|
||||
|
||||
//使用镜子
|
||||
let useRef = false;
|
||||
if (useRef)
|
||||
{
|
||||
floorMat.transparent = true;
|
||||
floorMat.opacity = 0.9;
|
||||
|
||||
// let ref = new Reflector(20, 20, {
|
||||
// clipBias: 0.003,
|
||||
// textureWidth: app.m_Viewer.Width * window.devicePixelRatio,
|
||||
// textureHeight: app.m_Viewer.Height * window.devicePixelRatio,
|
||||
// color: 0x777777
|
||||
// });
|
||||
|
||||
// ref.position.z = -0.1;
|
||||
// this.scene.add(ref);
|
||||
}
|
||||
}
|
||||
materialList = [];
|
||||
loadMaterial()
|
||||
{
|
||||
let self = this;
|
||||
|
||||
this.textureLoader.load("textures/hardwood2_diffuse.jpg", function (map)
|
||||
{
|
||||
map.wrapS = RepeatWrapping;
|
||||
map.wrapT = RepeatWrapping;
|
||||
map.anisotropy = 16;
|
||||
map.repeat.set(10, 24);
|
||||
|
||||
self.materialList.forEach(m =>
|
||||
{
|
||||
m.map = map;
|
||||
m.needsUpdate = true;
|
||||
});
|
||||
});
|
||||
this.textureLoader.load("textures/hardwood2_bump.jpg", function (map)
|
||||
{
|
||||
map.wrapS = RepeatWrapping;
|
||||
map.wrapT = RepeatWrapping;
|
||||
map.anisotropy = 16;
|
||||
map.repeat.set(10, 24);
|
||||
|
||||
self.materialList.forEach(m =>
|
||||
{
|
||||
(<MeshStandardMaterial>m).bumpMap = map;
|
||||
m.needsUpdate = true;
|
||||
});
|
||||
});
|
||||
this.textureLoader.load("textures/hardwood2_roughness.jpg", function (map)
|
||||
{
|
||||
map.wrapS = RepeatWrapping;
|
||||
map.wrapT = RepeatWrapping;
|
||||
map.anisotropy = 16;
|
||||
map.repeat.set(10, 24);
|
||||
|
||||
self.materialList.forEach(m =>
|
||||
{
|
||||
(<MeshStandardMaterial>m).roughnessMap = map;
|
||||
m.needsUpdate = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
drawLight()
|
||||
{
|
||||
var bulbGeometry = new SphereGeometry(0.02, 16, 8);
|
||||
// let bulbLight = new PointLight(0xffee88, 1.5, 100, 1);
|
||||
let bulbLight = new PointLight(0x999999, 1.5, 100, 2);
|
||||
|
||||
let bulbMat = new MeshStandardMaterial({
|
||||
emissive: 0xffffee,
|
||||
emissiveIntensity: 1,
|
||||
color: 0x000000
|
||||
});
|
||||
|
||||
|
||||
bulbLight.add(new Mesh(bulbGeometry, bulbMat));
|
||||
bulbLight.position.set(0, 2, 2);
|
||||
bulbLight.castShadow = true;
|
||||
|
||||
bulbLight.power = 400;
|
||||
bulbMat.emissiveIntensity = bulbLight.intensity / Math.pow(0.02, 2.0); // convert from intensity to irradiance at bulb surface
|
||||
this.scene.add(bulbLight);
|
||||
|
||||
let light2 = bulbLight.clone();
|
||||
|
||||
light2.position.set(-3, -1, 2);
|
||||
this.scene.add(light2);
|
||||
|
||||
|
||||
var clock = new Clock();
|
||||
begin(app.Viewer, app.Viewer.StartRender, () =>
|
||||
{
|
||||
var time = Date.now() * 0.0005;
|
||||
var delta = clock.getDelta();
|
||||
bulbLight.position.z = Math.cos(time) * 0.75 + 1.25;
|
||||
app.Viewer.UpdateRender();
|
||||
});
|
||||
}
|
||||
private drawHemiLight()
|
||||
{
|
||||
//0xddeeff 0x0f0e0d
|
||||
// var hemiLight = new HemisphereLight(0xffffff, 0xffffff, 0.05);
|
||||
var hemiLight = new HemisphereLight(0xddeeff, 0x0f0e0d, 0.05);
|
||||
hemiLight.intensity = 23;
|
||||
this.scene.add(hemiLight);
|
||||
}
|
||||
|
||||
|
||||
drawWall()
|
||||
{
|
||||
// let floorMat = new MeshStandardMaterial({
|
||||
// roughness: 0.8,
|
||||
// color: 0xffffff,
|
||||
// metalness: 0.2,
|
||||
// bumpScale: 0.0005
|
||||
// });
|
||||
|
||||
// this.textureLoader.load("textures/wallmap.png", function (map)
|
||||
// {
|
||||
// map.wrapS = RepeatWrapping;
|
||||
// map.wrapT = RepeatWrapping;
|
||||
// map.anisotropy = 4;
|
||||
// map.repeat.set(10, 24);
|
||||
// floorMat.map = map;
|
||||
// floorMat.needsUpdate = true;
|
||||
// });
|
||||
|
||||
|
||||
// let wallFont = new Solid3d(4, 0.12, 2.8);
|
||||
// let obj = wallFont.Draw(RenderType.Wireframe) as Mesh;
|
||||
// obj.material = floorMat;
|
||||
|
||||
// obj.castShadow = true;
|
||||
// obj.receiveShadow = true;
|
||||
|
||||
// let objLeft = obj.clone();
|
||||
// let objRight = obj.clone();
|
||||
|
||||
|
||||
// obj.applyMatrix(Move(new Vector3(-2.1, 4, 0)));
|
||||
|
||||
// let roMatLeft = new Matrix4();
|
||||
// roMatLeft.makeRotationZ(Math.PI / 2);
|
||||
// objLeft.applyMatrix(roMatLeft);
|
||||
|
||||
// let roMatRight = new Matrix4();
|
||||
// roMatRight.makeRotationZ(Math.PI / 2);
|
||||
// objRight.applyMatrix(roMatRight);
|
||||
|
||||
// objLeft.applyMatrix(Move(new Vector3(-2, 0, 0)))
|
||||
// objRight.applyMatrix(Move(new Vector3(2, 0, 0)))
|
||||
|
||||
|
||||
// this.scene.add(obj);
|
||||
// this.scene.add(objLeft);
|
||||
// this.scene.add(objRight);
|
||||
|
||||
|
||||
// let skyMaterail = new MeshStandardMaterial({
|
||||
// roughness: 0.8,
|
||||
// color: 0xffffff,
|
||||
// metalness: 0.2,
|
||||
// bumpScale: 0.0005
|
||||
// })
|
||||
// //天花板.
|
||||
// let skyWall = new Solid3d(4.12, 4, 0.12);
|
||||
// let skyObj = skyWall.Draw(RenderType.Wireframe) as Mesh;
|
||||
// skyObj.material = skyMaterail;
|
||||
|
||||
// skyObj.applyMatrix(Move(new Vector3(-2.12, 0, 2.8)));
|
||||
|
||||
// this.scene.add(skyObj);
|
||||
}
|
||||
|
||||
drawBox()
|
||||
{
|
||||
// let solid = new Solid3d(1.2, 0.05, 2.4);
|
||||
|
||||
// let obj = solid.Draw(RenderType.Wireframe);
|
||||
|
||||
// obj.castShadow = true;
|
||||
|
||||
// let mat = new MeshStandardMaterial({
|
||||
// roughness: 0.8,
|
||||
// color: 0xffffff,
|
||||
// metalness: 0.2,
|
||||
// bumpScale: 0.0005
|
||||
// });
|
||||
|
||||
// this.textureLoader.load("textures/door.png", function (map)
|
||||
// {
|
||||
// map.wrapS = RepeatWrapping;
|
||||
// map.wrapT = RepeatWrapping;
|
||||
// map.anisotropy = 16;
|
||||
// map.repeat.set(1, 1);
|
||||
// mat.map = map;
|
||||
// mat.needsUpdate = true;
|
||||
// });
|
||||
// (<Mesh>obj).material = mat;
|
||||
|
||||
|
||||
// this.scene.add(obj);
|
||||
}
|
||||
|
||||
|
||||
cubemap()
|
||||
{
|
||||
var path = "textures/cube/Park2/";
|
||||
var format = '.jpg';
|
||||
var urls = [
|
||||
path + 'posx' + format, path + 'negx' + format,
|
||||
path + 'posy' + format, path + 'negy' + format,
|
||||
path + 'posz' + format, path + 'negz' + format
|
||||
];
|
||||
var textureCube = new CubeTextureLoader().load(urls);
|
||||
textureCube.format = RGBFormat;
|
||||
return textureCube;
|
||||
};
|
||||
|
||||
drawBox2()
|
||||
{
|
||||
// let solid = new Solid3d(1, 1, 1);
|
||||
|
||||
// let obj = solid.Draw(RenderType.Wireframe);
|
||||
|
||||
// // obj = new Mesh(new SphereGeometry(1, 32, 32));
|
||||
// obj.position.set(0, 0, 1);
|
||||
|
||||
// obj.castShadow = true;
|
||||
|
||||
// let cubeCamera1 = new CubeCamera(0.1, 15, 1024);
|
||||
// let cubeCamera2 = new CubeCamera(0.1, 15, 1024);
|
||||
// cubeCamera1.position.set(0, 0, 1);
|
||||
// cubeCamera2.position.set(0, 0, 1);
|
||||
// cubeCamera1.renderTarget.texture.minFilter = LinearMipMapLinearFilter;
|
||||
// cubeCamera2.renderTarget.texture.minFilter = LinearMipMapLinearFilter;
|
||||
// cubeCamera1.renderTarget.texture.anisotropy = 16;
|
||||
// cubeCamera2.renderTarget.texture.anisotropy = 16;
|
||||
|
||||
|
||||
// this.scene.add(cubeCamera1);
|
||||
// this.scene.add(cubeCamera2);
|
||||
|
||||
|
||||
|
||||
|
||||
// let mat = new MeshStandardMaterial({
|
||||
// roughness: 0.8,
|
||||
// metalness: 0.8,
|
||||
// // color: 0xffffff,
|
||||
// // emissive: 0x000000,
|
||||
// emissiveIntensity: 0,
|
||||
// envMap: cubeCamera1.renderTarget.texture,
|
||||
// envMapIntensity: 1
|
||||
// });
|
||||
|
||||
// this.textureLoader.load("textures/Metal/130616_header2.jpg", function (map)
|
||||
// {
|
||||
// map.wrapS = RepeatWrapping;
|
||||
// map.wrapT = RepeatWrapping;
|
||||
// map.anisotropy = 16;
|
||||
// map.repeat.set(1, 1);
|
||||
// mat.map = map;
|
||||
// mat.needsUpdate = true;
|
||||
// });
|
||||
|
||||
// this.textureLoader.load("textures/Metal/Titanium-Scuffed_basecolor.png", function (map)
|
||||
// {
|
||||
// map.wrapS = RepeatWrapping;
|
||||
// map.wrapT = RepeatWrapping;
|
||||
// map.anisotropy = 16;
|
||||
// map.repeat.set(1, 1);
|
||||
// mat.map = map;
|
||||
// mat.needsUpdate = true;
|
||||
// });
|
||||
// this.textureLoader.load("textures/Metal/Titanium-Scuffed_roughness.png", function (map)
|
||||
// {
|
||||
// map.wrapS = RepeatWrapping;
|
||||
// map.wrapT = RepeatWrapping;
|
||||
// map.anisotropy = 16;
|
||||
// map.repeat.set(1, 1);
|
||||
// mat.roughnessMap = map;
|
||||
// mat.needsUpdate = true;
|
||||
// });
|
||||
// this.textureLoader.load("textures/Metal/Titanium-Scuffed_normal.png", function (map)
|
||||
// {
|
||||
// map.wrapS = RepeatWrapping;
|
||||
// map.wrapT = RepeatWrapping;
|
||||
// map.anisotropy = 16;
|
||||
// map.repeat.set(1, 1);
|
||||
// mat.normalMap = map;
|
||||
// mat.needsUpdate = true;
|
||||
// });
|
||||
// this.textureLoader.load("textures/Metal/Titanium-Scuffed_metallic.png", function (map)
|
||||
// {
|
||||
// map.wrapS = RepeatWrapping;
|
||||
// map.wrapT = RepeatWrapping;
|
||||
// map.anisotropy = 16;
|
||||
// map.repeat.set(1, 1);
|
||||
// mat.metalnessMap = map;
|
||||
// mat.needsUpdate = true;
|
||||
// });
|
||||
|
||||
// let isOne = false;
|
||||
// // begin(app.m_Viewer, app.m_Viewer.StartRender, () =>
|
||||
// // {
|
||||
// // obj.visible = false;
|
||||
// // let render = app.m_Viewer.m_Render;
|
||||
// // let scene = app.m_Viewer.Scene;
|
||||
|
||||
// // render.autoClear = true;
|
||||
// // // render.clear();
|
||||
// // if (isOne)
|
||||
// // {
|
||||
// // mat.envMap = cubeCamera2.renderTarget.texture;
|
||||
// // cubeCamera2.position.copy(obj.position);
|
||||
// // cubeCamera2.update(render, scene);
|
||||
// // }
|
||||
// // else
|
||||
// // {
|
||||
// // mat.envMap = cubeCamera1.renderTarget.texture;
|
||||
// // cubeCamera1.position.copy(obj.position);
|
||||
// // cubeCamera1.update(render, scene);
|
||||
// // }
|
||||
// // obj.visible = true;
|
||||
// // isOne = !isOne;
|
||||
// // });
|
||||
// (<Mesh>obj).material = mat;
|
||||
// this.scene.add(obj);
|
||||
}
|
||||
|
||||
|
||||
loadMaterialNode()
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in new issue