Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
fyge_for_tb
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王剑峰
fyge_for_tb
Commits
950374dc
Commit
950374dc
authored
Oct 22, 2020
by
wjf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
l
parent
21161f6a
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
381 additions
and
56 deletions
+381
-56
fyge.min.js
build/fyge.min.js
+137
-13
fyge.min.js.map
build/fyge.min.js.map
+1
-1
D3Renderer.ts
src/3D/D3Renderer.ts
+197
-32
Geometry.ts
src/3D/Geometry.ts
+1
-1
Mesh3D.ts
src/3D/Mesh3D.ts
+18
-7
VertexArrayObject.ts
src/glCore/VertexArrayObject.ts
+1
-1
test.html
test/test.html
+26
-1
No files found.
build/fyge.min.js
View file @
950374dc
...
@@ -16211,9 +16211,9 @@ var D3Renderer = (function (_super) {
...
@@ -16211,9 +16211,9 @@ var D3Renderer = (function (_super) {
glVaoBuffer
.
indexBuffer
=
glCore_1
.
GLBuffer
.
createIndexBuffer
(
gl
,
null
,
gl
.
STATIC_DRAW
);
glVaoBuffer
.
indexBuffer
=
glCore_1
.
GLBuffer
.
createIndexBuffer
(
gl
,
null
,
gl
.
STATIC_DRAW
);
if
(
geo
.
_morphPositions
)
{
if
(
geo
.
_morphPositions
)
{
glVaoBuffer
.
morphTargetBuffers
=
[];
glVaoBuffer
.
morphTargetBuffers
=
[];
for
(
var
m
=
0
;
m
<
geo
.
_morphPositions
.
length
;
m
++
)
{
}
glVaoBuffer
.
morphTargetBuffers
.
push
(
glCore_1
.
GLBuffer
.
createVertexBuffer
(
gl
,
null
,
gl
.
STATIC_DRAW
));
if
(
geo
.
_morphNormals
)
{
}
glVaoBuffer
.
morphNormalBuffers
=
[];
}
}
packGeometry
(
geo
);
packGeometry
(
geo
);
}
}
...
@@ -16228,19 +16228,29 @@ var D3Renderer = (function (_super) {
...
@@ -16228,19 +16228,29 @@ var D3Renderer = (function (_super) {
vao
.
addAttribute
(
glVaoBuffer
.
attrBuffer
,
attrs
.
aNormal
,
gl
.
FLOAT
,
false
,
geo
.
_vertByteSize
,
8
*
4
);
vao
.
addAttribute
(
glVaoBuffer
.
attrBuffer
,
attrs
.
aNormal
,
gl
.
FLOAT
,
false
,
geo
.
_vertByteSize
,
8
*
4
);
if
(
geo
.
_indices
)
if
(
geo
.
_indices
)
vao
.
addIndex
(
glVaoBuffer
.
indexBuffer
);
vao
.
addIndex
(
glVaoBuffer
.
indexBuffer
);
var
uploadBufferDatas
;
if
(
mesh
.
morphTargetInfluences
&&
mat
.
morphTargets
)
{
uploadBufferDatas
=
addMorphtargetsAttr
(
mesh
.
morphTargetInfluences
,
geo
,
glVaoBuffer
,
vao
,
curShader
,
gl
);
}
this
.
renderer
.
bindVao
(
vao
);
this
.
renderer
.
bindVao
(
vao
);
glVaoBuffer
.
attrBuffer
.
upload
(
geo
.
_attrBuffer
.
vertices
,
0
,
false
);
glVaoBuffer
.
attrBuffer
.
upload
(
geo
.
_attrBuffer
.
vertices
,
0
,
false
);
if
(
geo
.
_indices
)
if
(
geo
.
_indices
)
glVaoBuffer
.
indexBuffer
.
upload
(
geo
.
_indices
,
0
,
false
);
glVaoBuffer
.
indexBuffer
.
upload
(
geo
.
_indices
,
0
,
false
);
if
(
geo
.
_morphPositions
)
{
if
(
uploadBufferDatas
)
var
len
=
geo
.
_morphNormals
?
4
:
8
;
uploadBufferDatas
.
forEach
(
function
(
e
)
{
for
(
var
n
=
0
;
n
<
len
;
n
++
)
{
e
.
buffer
.
upload
(
e
.
data
,
0
,
false
);
glVaoBuffer
.
morphTargetBuffers
[
n
];
});
}
}
}
}
else
{
else
{
var
uploadBufferDatas
;
if
(
mesh
.
morphTargetInfluences
&&
mat
.
morphTargets
)
{
uploadBufferDatas
=
addMorphtargetsAttr
(
mesh
.
morphTargetInfluences
,
geo
,
glVaoBuffer
,
vao
,
curShader
,
gl
);
}
this
.
renderer
.
bindVao
(
vao
);
this
.
renderer
.
bindVao
(
vao
);
if
(
uploadBufferDatas
)
uploadBufferDatas
.
forEach
(
function
(
e
)
{
e
.
buffer
.
upload
(
e
.
data
,
0
,
true
);
});
}
}
if
(
mat
.
side
==
BaseMaterial_1
.
RenderSideType
.
DoubleSide
)
{
if
(
mat
.
side
==
BaseMaterial_1
.
RenderSideType
.
DoubleSide
)
{
this
.
renderer
.
state
.
setCullFace
(
0
);
this
.
renderer
.
state
.
setCullFace
(
0
);
...
@@ -16273,6 +16283,91 @@ function packGeometry(geo) {
...
@@ -16273,6 +16283,91 @@ function packGeometry(geo) {
float32View
[
count
++
]
=
geo
.
_normals
[
j
*
3
+
2
];
float32View
[
count
++
]
=
geo
.
_normals
[
j
*
3
+
2
];
}
}
}
}
var
influencesList
=
{};
var
attrChannelHash
=
{};
var
morphInfluences
=
new
Float32Array
(
8
);
function
addMorphtargetsAttr
(
objectInfluences
,
geo
,
glVaoBuffer
,
vao
,
shader
,
gl
)
{
var
morphTargets
=
geo
.
_morphPositions
;
var
morphNormals
=
geo
.
_morphNormals
;
var
length
=
objectInfluences
.
length
;
var
uploadBufferDatas
=
[];
var
influences
=
influencesList
[
geo
.
instanceId
];
if
(
!
influences
)
{
influences
=
[];
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
influences
[
i
]
=
[
i
,
0
];
}
influencesList
[
geo
.
instanceId
]
=
influences
;
}
var
attrChannel
=
attrChannelHash
[
geo
.
instanceId
];
if
(
!
attrChannel
)
{
attrChannel
=
[];
attrChannel
.
length
=
8
;
attrChannelHash
[
geo
.
instanceId
]
=
attrChannel
;
}
for
(
var
i
=
0
;
i
<
8
;
i
++
)
{
var
influence
=
influences
[
i
];
if
(
influence
&&
influence
[
1
]
!==
0
)
{
if
(
morphTargets
)
vao
.
removeAttribute
(
'morphTarget'
+
i
);
if
(
morphNormals
&&
i
<
4
)
vao
.
removeAttribute
(
'morphNormal'
+
i
);
}
}
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
var
influence
=
influences
[
i
];
influence
[
0
]
=
i
;
influence
[
1
]
=
objectInfluences
[
i
];
}
influences
.
sort
(
absNumericalSort
);
var
attrs
=
shader
.
attributes
;
var
attrLen
=
morphNormals
?
4
:
8
;
for
(
var
i
=
0
;
i
<
attrLen
;
i
++
)
{
var
influence
=
influences
[
i
];
if
(
influence
)
{
var
index
=
influence
[
0
];
var
value
=
influence
[
1
];
if
(
value
)
{
if
(
morphTargets
&&
morphTargets
[
index
])
{
var
targetBuffer
=
glVaoBuffer
.
morphTargetBuffers
[
index
];
if
(
!
targetBuffer
)
{
targetBuffer
=
glVaoBuffer
.
morphTargetBuffers
[
index
]
=
glCore_1
.
GLBuffer
.
createVertexBuffer
(
gl
,
null
,
gl
.
STATIC_DRAW
);
}
if
(
attrChannel
[
i
]
!==
index
)
{
attrChannel
[
i
]
=
index
;
uploadBufferDatas
.
push
({
buffer
:
targetBuffer
,
data
:
new
Float32Array
(
morphTargets
[
index
])
});
}
vao
.
addAttribute
(
targetBuffer
,
attrs
[
'morphTarget'
+
i
],
gl
.
FLOAT
,
false
,
0
,
0
*
4
,
'morphTarget'
+
i
);
}
if
(
morphNormals
&&
morphNormals
[
index
])
{
var
normalBuffer
=
glVaoBuffer
.
morphNormalBuffers
[
index
];
if
(
!
normalBuffer
)
{
normalBuffer
=
glVaoBuffer
.
morphNormalBuffers
[
index
]
=
glCore_1
.
GLBuffer
.
createVertexBuffer
(
gl
,
null
,
gl
.
STATIC_DRAW
);
}
if
(
attrChannel
[
i
]
!==
index
)
{
attrChannel
[
i
]
=
index
;
uploadBufferDatas
.
push
({
buffer
:
normalBuffer
,
data
:
morphNormals
[
index
]
});
}
vao
.
addAttribute
(
glVaoBuffer
.
morphNormalBuffers
[
index
],
attrs
[
'morphNormal'
+
i
],
gl
.
FLOAT
,
false
,
0
,
0
*
4
,
'morphNormal'
+
i
);
}
morphInfluences
[
i
]
=
value
;
continue
;
}
}
morphInfluences
[
i
]
=
0
;
}
shader
.
uniforms
[
"morphTargetInfluences"
]
=
morphInfluences
;
return
uploadBufferDatas
;
}
function
absNumericalSort
(
a
,
b
)
{
return
Math
.
abs
(
b
[
1
])
-
Math
.
abs
(
a
[
1
]);
}
WebglRenderer_1
.
WebglRenderer
.
registerPlugin
(
'd3'
,
D3Renderer
);
WebglRenderer_1
.
WebglRenderer
.
registerPlugin
(
'd3'
,
D3Renderer
);
...
@@ -16493,6 +16588,13 @@ var Mesh3D = (function (_super) {
...
@@ -16493,6 +16588,13 @@ var Mesh3D = (function (_super) {
_this
.
updateMorphTargets
();
_this
.
updateMorphTargets
();
return
_this
;
return
_this
;
}
}
Object
.
defineProperty
(
Mesh3D
.
prototype
,
"morphTargetInfluences"
,
{
get
:
function
()
{
return
this
.
_morphTargetInfluences
;
},
enumerable
:
true
,
configurable
:
true
});
Mesh3D
.
prototype
.
_render
=
function
(
renderer
)
{
Mesh3D
.
prototype
.
_render
=
function
(
renderer
)
{
if
(
!
this
.
visible
)
if
(
!
this
.
visible
)
return
;
return
;
...
@@ -16502,9 +16604,9 @@ var Mesh3D = (function (_super) {
...
@@ -16502,9 +16604,9 @@ var Mesh3D = (function (_super) {
Mesh3D
.
prototype
.
updateMorphTargets
=
function
()
{
Mesh3D
.
prototype
.
updateMorphTargets
=
function
()
{
var
morphPositions
=
this
.
geometry
.
_morphPositions
;
var
morphPositions
=
this
.
geometry
.
_morphPositions
;
if
(
morphPositions
)
{
if
(
morphPositions
)
{
this
.
morphTargetInfluences
=
[];
this
.
_
morphTargetInfluences
=
[];
for
(
var
i
=
0
;
i
<
morphPositions
.
length
;
i
++
)
for
(
var
i
=
0
;
i
<
morphPositions
.
length
;
i
++
)
this
.
morphTargetInfluences
.
push
(
0
);
this
.
_
morphTargetInfluences
.
push
(
0
);
}
}
};
};
Mesh3D
.
prototype
.
raycast
=
function
(
raycaster
,
intersects
)
{
Mesh3D
.
prototype
.
raycast
=
function
(
raycaster
,
intersects
)
{
...
@@ -16560,6 +16662,14 @@ var Mesh3D = (function (_super) {
...
@@ -16560,6 +16662,14 @@ var Mesh3D = (function (_super) {
}
}
};
};
;
;
Mesh3D
.
prototype
.
copy
=
function
(
source
,
recursive
)
{
if
(
recursive
===
void
0
)
{
recursive
=
true
;
}
_super
.
prototype
.
copy
.
call
(
this
,
source
,
recursive
);
if
(
source
.
morphTargetInfluences
)
{
this
.
_morphTargetInfluences
=
source
.
morphTargetInfluences
.
slice
();
}
return
this
;
};
Mesh3D
.
prototype
.
clone
=
function
()
{
Mesh3D
.
prototype
.
clone
=
function
()
{
return
new
Mesh3D
(
this
.
geometry
,
this
.
material
).
copy
(
this
);
return
new
Mesh3D
(
this
.
geometry
,
this
.
material
).
copy
(
this
);
};
};
...
@@ -21433,7 +21543,7 @@ var VertexArrayObject = (function () {
...
@@ -21433,7 +21543,7 @@ var VertexArrayObject = (function () {
return
this
;
return
this
;
};
};
;
;
VertexArrayObject
.
prototype
.
addAttribute
=
function
(
buffer
,
attribute
,
type
,
normalized
,
stride
,
start
)
{
VertexArrayObject
.
prototype
.
addAttribute
=
function
(
buffer
,
attribute
,
type
,
normalized
,
stride
,
start
,
name
)
{
this
.
attributes
.
push
({
this
.
attributes
.
push
({
buffer
:
buffer
,
buffer
:
buffer
,
attribute
:
attribute
,
attribute
:
attribute
,
...
@@ -21441,12 +21551,26 @@ var VertexArrayObject = (function () {
...
@@ -21441,12 +21551,26 @@ var VertexArrayObject = (function () {
type
:
type
||
this
.
gl
.
FLOAT
,
type
:
type
||
this
.
gl
.
FLOAT
,
normalized
:
normalized
||
false
,
normalized
:
normalized
||
false
,
stride
:
stride
||
0
,
stride
:
stride
||
0
,
start
:
start
||
0
start
:
start
||
0
,
name
:
name
,
});
});
this
.
dirty
=
true
;
this
.
dirty
=
true
;
return
this
;
return
this
;
};
};
;
;
VertexArrayObject
.
prototype
.
removeAttribute
=
function
(
name
,
onlyOne
)
{
if
(
onlyOne
===
void
0
)
{
onlyOne
=
true
;
}
var
len
=
this
.
attributes
.
length
;
for
(
var
i
=
len
-
1
;
i
>=
0
;
i
--
)
{
var
attr
=
this
.
attributes
[
i
];
if
(
attr
.
name
===
name
)
{
this
.
attributes
.
splice
(
i
,
1
);
if
(
onlyOne
)
break
;
}
}
return
this
;
};
VertexArrayObject
.
prototype
.
addIndex
=
function
(
buffer
)
{
VertexArrayObject
.
prototype
.
addIndex
=
function
(
buffer
)
{
this
.
indexBuffer
=
buffer
;
this
.
indexBuffer
=
buffer
;
this
.
dirty
=
true
;
this
.
dirty
=
true
;
...
...
build/fyge.min.js.map
View file @
950374dc
This diff is collapsed.
Click to expand it.
src/3D/D3Renderer.ts
View file @
950374dc
This diff is collapsed.
Click to expand it.
src/3D/Geometry.ts
View file @
950374dc
...
@@ -137,7 +137,7 @@ export class Geometry extends HashObject {
...
@@ -137,7 +137,7 @@ export class Geometry extends HashObject {
/**
/**
* 根据webglRendererId存一个,vao还需要根据着色器程序缓存
* 根据webglRendererId存一个,vao还需要根据着色器程序缓存
*/
*/
interface
VaoBufferInt
{
export
interface
VaoBufferInt
{
/**
/**
* 索引
* 索引
*/
*/
...
...
src/3D/Mesh3D.ts
View file @
950374dc
...
@@ -15,11 +15,12 @@ const tempPoint = new Vector3();
...
@@ -15,11 +15,12 @@ const tempPoint = new Vector3();
export
class
Mesh3D
extends
Object3D
{
export
class
Mesh3D
extends
Object3D
{
/**
/**
* 外部可设置
* 用于变形权重,只能获取,修改只能内部修改
* 用于变形权重,
* 最大长度8
*/
*/
public
morphTargetInfluences
:
number
[];
private
_morphTargetInfluences
:
number
[];
get
morphTargetInfluences
()
{
return
this
.
_morphTargetInfluences
;
}
//这个暂时不知道有啥用,到时看three的
//这个暂时不知道有啥用,到时看three的
// morphTargetDictionary
// morphTargetDictionary
constructor
(
constructor
(
...
@@ -38,9 +39,9 @@ export class Mesh3D extends Object3D {
...
@@ -38,9 +39,9 @@ export class Mesh3D extends Object3D {
updateMorphTargets
()
{
updateMorphTargets
()
{
var
morphPositions
=
this
.
geometry
.
_morphPositions
;
var
morphPositions
=
this
.
geometry
.
_morphPositions
;
if
(
morphPositions
)
{
if
(
morphPositions
)
{
this
.
morphTargetInfluences
=
[];
this
.
_
morphTargetInfluences
=
[];
//根据morphPositions的长度来定权重长度
//根据morphPositions的长度来定权重长度
for
(
var
i
=
0
;
i
<
morphPositions
.
length
;
i
++
)
this
.
morphTargetInfluences
.
push
(
0
);
for
(
var
i
=
0
;
i
<
morphPositions
.
length
;
i
++
)
this
.
_
morphTargetInfluences
.
push
(
0
);
}
}
}
}
...
@@ -123,7 +124,17 @@ export class Mesh3D extends Object3D {
...
@@ -123,7 +124,17 @@ export class Mesh3D extends Object3D {
}
}
}
}
};
};
copy
(
source
:
Mesh3D
,
recursive
:
boolean
=
true
)
{
super
.
copy
(
source
,
recursive
);
if
(
source
.
morphTargetInfluences
)
{
//变形的数据
this
.
_morphTargetInfluences
=
source
.
morphTargetInfluences
.
slice
();
}
//暂时不用
// if ( source.morphTargetDictionary !== undefined ) {
// this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
// }
return
this
}
/**
/**
*
*
*/
*/
...
...
src/glCore/VertexArrayObject.ts
View file @
950374dc
...
@@ -152,7 +152,7 @@ export class VertexArrayObject {
...
@@ -152,7 +152,7 @@ export class VertexArrayObject {
* @param start {Number}
* @param start {Number}
* @param name {string} 名字,用于移除,否则不需要传
* @param name {string} 名字,用于移除,否则不需要传
*/
*/
public
addAttribute
(
buffer
,
attribute
,
type
?,
normalized
?,
stride
?,
start
?,
name
?:
number
)
{
public
addAttribute
(
buffer
,
attribute
,
type
?,
normalized
?,
stride
?,
start
?,
name
?:
string
)
{
this
.
attributes
.
push
({
this
.
attributes
.
push
({
buffer
:
buffer
,
buffer
:
buffer
,
attribute
:
attribute
,
attribute
:
attribute
,
...
...
test/test.html
View file @
950374dc
...
@@ -45,7 +45,7 @@
...
@@ -45,7 +45,7 @@
<canvas
id=
"canvas"
style=
"width: 100%;height: 100%"
></canvas>
<canvas
id=
"canvas"
style=
"width: 100%;height: 100%"
></canvas>
</div>
</div>
<!-- 帧率检测 -->
<!-- 帧率检测 -->
<
!-- <script src="js/stats.js"></script> --
>
<
script
src=
"//yun.duiba.com.cn/db_games/libs0924/stats.js"
></script
>
</body>
</body>
<script>
<script>
window
.
addEventListener
(
"load"
,
async
function
()
{
window
.
addEventListener
(
"load"
,
async
function
()
{
...
@@ -155,13 +155,28 @@
...
@@ -155,13 +155,28 @@
//立方体几何
//立方体几何
var
geo
=
new
FYGE
.
BoxGeometry
(
4
,
4
,
4
)
var
geo
=
new
FYGE
.
BoxGeometry
(
4
,
4
,
4
)
geo
.
_morphPositions
=
[]
for
(
let
i
=
0
;
i
<
1
;
i
++
)
{
let
v
=
geo
.
_vertices
.
slice
();
// console.log(v)
for
(
var
j
=
0
;
j
<
v
.
length
;
j
++
)
{
// v[j] += 2
v
[
j
]
*=
2
}
geo
.
_morphPositions
.
push
(
v
)
}
console
.
log
()
// console.log( new Float32Array(v))
//光照材质
//光照材质
var
matL
=
new
FYGE
.
LightMaterial
();
var
matL
=
new
FYGE
.
LightMaterial
();
matL
.
map
=
texture
;
//加个贴图
matL
.
map
=
texture
;
//加个贴图
matL
.
side
=
2
// matL.color=0xff0000
// matL.color=0xff0000
// matL.alpha=0.5
// matL.alpha=0.5
// matL.wireframe=true
// matL.wireframe=true
var
m
=
scene
.
addChild
(
new
FYGE
.
Mesh3D
(
geo
,
matL
))
var
m
=
scene
.
addChild
(
new
FYGE
.
Mesh3D
(
geo
,
matL
))
matL
.
morphTargets
=
true
// m.morphTargetInfluences = [0]
m
.
position
.
set
(
0
,
0
,
0
)
m
.
position
.
set
(
0
,
0
,
0
)
// m.scale.set(1.3, 1.3, 1.3)
// m.scale.set(1.3, 1.3, 1.3)
// m.rotation.set(0,Math.PI/12,0)
// m.rotation.set(0,Math.PI/12,0)
...
@@ -171,6 +186,16 @@
...
@@ -171,6 +186,16 @@
// m.visible = false;
// m.visible = false;
m
.
position
.
y
=
0
m
.
position
.
y
=
0
m
.
addEventListener
(
FYGE
.
MouseEvent
.
CLICK
,
()
=>
{
console
.
log
(
123123
)
},
this
)
m
.
addEventListener
(
FYGE
.
MouseEvent
.
CLICK
,
()
=>
{
console
.
log
(
123123
)
},
this
)
let
mm
=
m
;
m
.
addEventListener
(
FYGE
.
Event
.
ENTER_FRAME
,
()
=>
{
var
morph
=
Math
.
abs
(
Math
.
sin
(
mm
.
rotation
.
y
))
*
1
mm
.
morphTargetInfluences
[
0
]
=
morph
// mm.morphTargetInfluences[1] = morph
// mm.morphTargetInfluences[2] = morph
// mm.morphTargetInfluences[3] = morph
})
//不带光找的材质
//不带光找的材质
var
mat1
=
new
FYGE
.
BaseMaterial
();
var
mat1
=
new
FYGE
.
BaseMaterial
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment