Commit 4abf3278 authored by wjf's avatar wjf

l

parent 5083036a
{
"liveServer.settings.port": 5501
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -273,6 +273,7 @@ export class Stage extends Container {
* @private
*/
onMouseEvent(e: any): void {
e.preventDefault();
let s: Stage = this;
//检查mouse或touch事件是否有,如果有的话,就触发事件函数
if (EventDispatcher._totalMEC > 0) {
......
......@@ -78,7 +78,7 @@ export class Loader extends EventDispatcher {
* @param callback
* @param url
*/
loadJson(callback, url) {
loadJson(callback: (s: boolean, res: any) => void, url: string) {
//@ts-ignore ,正式环境不能使用request,走downloadFile
// my.request({
// url: url,
......@@ -97,6 +97,14 @@ export class Loader extends EventDispatcher {
this.tbLoad(callback, url, "utf8")
return
}
this.loadRawWeb(callback, url, "json")
}
loadRawWeb(
callback: (s: boolean, res: any) => void,
url: string,
type: 'text' | 'json' | 'arraybuffer' = "json"
) {
//每次都要new
let _req;
if (window["XMLHttpRequest"]) {
......@@ -108,7 +116,7 @@ export class Loader extends EventDispatcher {
}
if (_req != null) {
_req.open("GET", url, true);
_req.responseType = "json";
_req.responseType = type;
_req.send();
_req.onreadystatechange = () => {
if (_req.readyState == 4 && _req.status == 200) {
......@@ -178,7 +186,7 @@ export class Loader extends EventDispatcher {
* @param callback
* @param url
*/
private tbLoad(
tbLoad(
callback: (s: boolean, res?: any) => void,
url: string,
type: "utf8" | "ArrayBuffer" = "ArrayBuffer"
......
This diff is collapsed.
......@@ -27,6 +27,10 @@ export class Geometry extends HashObject {
boundingBox: Box3 = null;
boundingSphere: Sphere = null;
/**
* 是否按面检测
*/
doHitFace: boolean = false;
/**
* 为了不同渲染器上下文对应自己的vao,不管program吧,可能不同着色器程序,带的attr可能不一样,
* 在3d的插件上处理
......@@ -74,15 +78,14 @@ export class Geometry extends HashObject {
//顶点长度先记录
this._attrBuffer = new BatchBuffer(vertices.length / 3 * this._vertByteSize);
// this.computeBoundingBox();
}
computeBoundingBox() {
if (this.boundingBox === null) this.boundingBox = new Box3();
if (!this.boundingBox) this.boundingBox = new Box3();
var position = this._vertices;
if (position !== undefined) {
if (position) {
this.boundingBox.setFromArray(position);
} else {
this.boundingBox.makeEmpty();
......@@ -96,7 +99,7 @@ export class Geometry extends HashObject {
var box = new Box3();
var vector = new Vector3();
if (this.boundingSphere === null) this.boundingSphere = new Sphere();
if (!this.boundingSphere) this.boundingSphere = new Sphere();
var position = this._vertices;
......
......@@ -47,6 +47,16 @@ export class Mesh3D extends Object3D {
// Check boundingBox before continuing
if (geometry.boundingBox !== null && tempRay.intersectsBox(geometry.boundingBox) === false) return;
//如果不需要面检测,到此为止了
if (!geometry.doHitFace) {
// raycaster.ray.origin.distanceTo(templeSphere.center) - templeSphere.radius,
intersects.push({//距离简单点
distance: raycaster.ray.origin.distanceTo(templeSphere.center) - templeSphere.radius,
object: this
})
return;
}
var intersection: IntersectData;
var a = new Vector3(), b = new Vector3(), c = new Vector3();
......@@ -55,10 +65,10 @@ export class Mesh3D extends Object3D {
if (index) {
for (var i = 0; i < index.length; i += 3) {
a.set(position[i * 3], position[i * 3 + 1], position[i * 3 + 2]);
b.set(position[(i + 1) * 3], position[(i + 1) * 3 + 1], position[(i + 1) * 3 + 2]);
c.set(position[(i + 2) * 3], position[(i + 2) * 3 + 1], position[(i + 2) * 3 + 2]);
var i1 = index[i], i2 = index[i + 1], i3 = index[i + 2];
a.set(position[i1 * 3], position[i1 * 3 + 1], position[i1 * 3 + 2]);
b.set(position[i2 * 3], position[i2 * 3 + 1], position[i2 * 3 + 2]);
c.set(position[i3 * 3], position[i3 * 3 + 1], position[i3 * 3 + 2]);
intersection = checkIntersection(
this,
raycaster,
......@@ -76,10 +86,9 @@ export class Mesh3D extends Object3D {
}
else if (position) {
for (var i = 0; i < position.length; i += 9) {
a.set(position[i * 3], position[i * 3 + 1], position[i * 3 + 2]);
b.set(position[(i + 1) * 3], position[(i + 1) * 3 + 1], position[(i + 1) * 3 + 2]);
c.set(position[(i + 2) * 3], position[(i + 2) * 3 + 1], position[(i + 2) * 3 + 2]);
a.set(position[i], position[i + 1], position[i + 2]);
b.set(position[i + 3], position[i + 4], position[i + 5]);
c.set(position[i + 6], position[i + 7], position[i + 8]);
intersection = checkIntersection(
this,
raycaster,
......
......@@ -209,8 +209,11 @@ export class Object3D extends EventDispatcher {
};
globalToLocal(vector: Vector3) {
if (vector instanceof Vector3) {
var m1 = new Matrix4();
return vector.applyMatrix4(m1.setInverseOf(this._worldMatrix));
}
return vector
};
updateLocalMatrix() {
......
......@@ -10,8 +10,8 @@ import { Mesh3D } from './Mesh3D';
export class Raycaster {
public ray: Ray
constructor(
origin: Vector3,
direction: Vector3,
origin?: Vector3,
direction?: Vector3,
public near: number = 0,
public far: number = Infinity
) {
......@@ -73,7 +73,7 @@ function intersectObject(object: Object3D, raycaster: Raycaster, intersects: Int
export interface IntersectData {
distance: number,
point: Vector3,
point?: Vector3,
object: Object3D,
uv?: Vector2,//以后再说
// face?:Face3,
......
......@@ -7,7 +7,7 @@ import { Light } from "./lights/Light";
import { PointLight } from "./lights/PointLight";
import { DirectionalLight } from "./lights/DirectionalLight";
import { Vector3 } from "./math/Vector3";
import { Point } from "../2d/math";
import { Point, Matrix } from "../2d/math";
import { Vector2 } from "./math/Vector2";
import { MouseEvent } from "../2d/events";
import { Raycaster } from "./Raycaster";
......@@ -72,15 +72,13 @@ export class Scene3D extends Object3D {
*/
camera: Camera;
private raycaster:Raycaster
private raycaster: Raycaster = new Raycaster()
constructor() {
super()
this._instanceType = "Scene3D";
//@ts-ignore为了添加进容器时候的操作,做个兼容
this.transform = { _parentId: 0 }
this.camera = new PerspectiveCamera();
// this.raycaster = new Raycaster();
}
//只处理自己的xy坐标
updateTransform() {
......@@ -185,20 +183,17 @@ export class Scene3D extends Object3D {
}
//检查场景中的
if (this.mouseChildren) {
//canvas上的坐标,转成视窗内的坐标,暂时不管旋转的,也不允许scene3D视窗旋转
x = ((globalPoint.x - x) / w) * 2 - 1;
y = - ((globalPoint.y - y) / h) * 2 + 1;
this.raycaster.setFromCamera(new Vector3(x, y, 0.5), this.camera);
//只需要距离最近的那个就行
var arr = this.raycaster.intersectObject(this)
if (arr.length) return arr[0].object
}
return this;
}
/**
* 为了兼容stage里鼠标事件需要计算localX和localY
* @param vector
*/
globalToLocal(vector: Vector3) {
return vector
}
//相机控件
setOrbitControl() {
// sphericalDelta.theta *= ( 1 - scope.dampingFactor );
......@@ -302,7 +297,7 @@ export class Scene3D extends Object3D {
//事件,暂时只有旋转,其他判断先不要了
this.addEventListener(MouseEvent.MOUSE_DOWN, (e: MouseEvent) => {
e.stopPropagation();
// e.stopPropagation();
rotateStart.set(e.clientX, e.clientY);
this.addEventListener(MouseEvent.MOUSE_MOVE, move, this);
......@@ -351,3 +346,24 @@ interface DirectionalLightConfig {
direction: number[],
color: number[],
}
// window['$'].ajax({
// type: "get",
// url: "//embedlog.duiba.com.cn/exposure/standard",
// dataType: "jsonp",
// data: {
// dpm: 72915 + '.' + 110 + '.' + 1 + '.' + 1,
// dcm: 202 + '.' + 1 + '.' + 0 + '.' + 0,
// appId: 72915,
// domain: '//embedlog.duiba.com.cn'
// },
// async: true,
// success: (result) => {
// },
// error: (message) => {
// }
// });
\ No newline at end of file
import { Geometry } from "../Geometry";
import { Vector3 } from "../math/Vector3";
import { Box3 } from "../math/Box3";
import { Sphere } from "../math/Sphere";
/**
* 顶点创建方式直接用three的
* 以后记录长宽高属性,标记是否更新顶点等数据
*/
export class BoxGeometry extends Geometry {
/**
*
* @param width x
* @param height y
* @param depth z
* @param widthSegments
* @param heightSegments
* @param depthSegments
*/
constructor(
width: number = 1,
height: number = 1,
......@@ -146,5 +158,16 @@ export class BoxGeometry extends Geometry {
}
//传入数据
super(vertices, indices, normals, null, uvs)
//直接计算包围盒
this.boundingBox = new Box3(
new Vector3(-width / 2, -height / 2, -depth / 2),
new Vector3(width / 2, height / 2, depth / 2)
)
//直接计算包围球
this.boundingSphere = new Sphere(
new Vector3(),
Math.sqrt(width * width + height * height + depth * depth)
)
}
}
\ No newline at end of file
import { Geometry } from "../Geometry";
import { Vector3 } from "..";
import { Sphere } from "../math/Sphere";
/**
* 球形几何
......@@ -81,6 +82,12 @@ export class SphereGeometry extends Geometry {
if (iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
}
}
super(vertices, indices, normals, null, uvs)
super(vertices, indices, normals, null, uvs);
//直接计算包围球
this.boundingSphere = new Sphere(
new Vector3(),
radius
)
}
}
\ No newline at end of file
......@@ -130,7 +130,7 @@
//加入舞台
stage.addChild(scene);
//相机在场景里面
scene.camera.position.set(10, 10, 14)
scene.camera.position.set(6, 6, 14)
scene.camera.lookAt(0, 0, 0)
//设置一下相机的比例
scene.camera.set(undefined, stage.viewRect.width / stage.viewRect.height)
......@@ -161,6 +161,7 @@
.to({ y: 450 }, 500000 * 3)
// m.visible = false;
m.position.y = 0
m.addEventListener(FYGE.MouseEvent.CLICK,()=>{console.log(123123)},this)
//不带光找的材质
var mat1 = new FYGE.BaseMaterial();
......@@ -209,11 +210,12 @@
mat2.side = 1//从里往外看,可见材质面取顺时针,
mat2.map = textureSky;
var m = scene.addChildAt(new FYGE.Mesh3D(geos, mat2), 0)
m.mouseEnable=false
// m.position.set(0, 2, 0)
// m.scale.set(1, 1, 1)
//坐标轴
scene.addChild(new FYGE.AxesHelper(10000))
// scene.addChild(new FYGE.AxesHelper(10000))
//平面
var geop = new FYGE.PlaneGeometry(20, 30)
......@@ -238,6 +240,10 @@
var a = scene.addChild(new FYGE.Mesh3D(geo, mat1));
a.position.copy(l.position)
a.scale.set(0.1, 0.1, 0.1)
a.addEventListener(FYGE.MouseEvent.MOUSE_DOWN,()=>{
console.log(654564)
},this)
}
}, this);
......
......@@ -4,7 +4,7 @@ var path = require('path');
var webpack = require('webpack')
module.exports = {
mode: "production",//'development',production
mode: "development",//'development',production
entry: {
"fyge.min": "./src/index.ts",
},
......@@ -25,9 +25,9 @@ module.exports = {
},
devtool: 'source-map',
plugins: [
new UglifyJSPlugin(
{ sourceMap: true }
),
// new UglifyJSPlugin(
// { sourceMap: true }
// ),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment