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