Skip to content

Commit 357be5e

Browse files
committed
add skill
1 parent f4457a0 commit 357be5e

File tree

7 files changed

+99
-23
lines changed

7 files changed

+99
-23
lines changed

assets/logo/skill.png

25.8 KB
Loading

assets/models/buggy.glb

552 Bytes
Binary file not shown.

demos/buggy.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ demo = () => {
1212
phy.add({ type:'plane', name:'floor', size:[300,1,300], visible:false });
1313
//phy.add({ pos:[0,20,0], rot:[0,0,0], size:[0.5,0.5,0.5], mass:30})
1414
//phy.add({ type:'box', size:[4,1,6], rot:[1,0,0], pos:[0,0.5,0], radius:0.025 })
15-
16-
// phy.add({ type:'box', size:[4,4,1], pos:[0,2,10], radius:0.025 })
15+
//phy.add({ type:'box', size:[4,4,1], pos:[0,2,10], radius:0.025 })
1716

1817
// preLoad
1918
const maps = [
@@ -39,8 +38,6 @@ onComplete = () => {
3938
const suspension = model['h_susp_base']
4039
const brake = model['h_brake']
4140

42-
43-
4441
buggy = phy.add( {
4542

4643
type:'vehicle',
@@ -125,8 +122,8 @@ terrainTest = () => {
125122

126123
update = () => {
127124

125+
// decal terrain > 50
128126
let p = buggy.position;
129-
//let d = math.distance({ x:p.x, z:p.z });
130127
let d = math.distanceArray([p.x, 0, p.z])
131128

132129
if( d > 50 ){
@@ -136,50 +133,41 @@ update = () => {
136133
])
137134
}
138135

139-
//let key = phy.getKey()
140-
//phy.update( { name:'buggy', key:key } )
141-
142136
}
143137

144138
applyMaterial = ( model ) => {
145139

146140
const mat = {}
147141

148-
149-
//let Mat = phy.getMat()
150-
//let clear = Mat.get('clear')
151-
152-
const path = './assets/textures/buggy/'
153-
154142
mat['carGlass'] = phy.getMat('carGlass');
155143

156144
mat['body'] = phy.material({
157145
name:'body',
158146
roughness: 0.5,
159147
metalness: 1.0,
160148
envMapIntensity: 1.35,
161-
map: phy.texture({ url:path + 'body_c.jpg' }),
149+
map: phy.getTexture('body_c'),
162150
clearcoat: 1.0, clearcoatRoughness: 0.03, sheen: 0.5,
163151
});
164152

165153
mat['extra'] = phy.material({
166154
name:'extra',
167155
roughness: 0.1,
168156
metalness: 0.6,
169-
map: phy.texture({ url:path + 'extra_c.jpg' }),
170-
normalMap: phy.texture({ url:path + 'extra_n.jpg' }),
157+
map: phy.getTexture('extra_c'),
158+
normalMap: phy.getTexture('extra_n'),
171159
normalScale: [ 1, -1 ],
172160
});
173161

174162
mat['pilote'] = phy.material({
175163
name:'pilote',
176164
roughness: 0.4,
177165
metalness: 0.6,
178-
map: phy.texture({ url:path + 'pilote_c.jpg' }),
166+
map: phy.getTexture('pilote_c'),
179167
});
180168

181-
let wheel_map = phy.texture({ url:path + 'wheel_c.jpg' })
182-
let wheel_normal = phy.texture({ url:path + 'wheel_n.jpg' })
169+
let wheel_map = phy.getTexture('wheel_c')
170+
let wheel_normal = phy.getTexture('wheel_n')
183171

184172
mat['wheel'] = phy.material({
185173
name:'wheel',
@@ -204,7 +192,7 @@ applyMaterial = ( model ) => {
204192
name:'susp',
205193
roughness: 0.6,
206194
metalness: 0.4,
207-
map: phy.texture({ url:path + 'suspension_c.jpg' }),
195+
map: phy.getTexture('suspension_c'),
208196
});
209197

210198
mat['brake'] = phy.material({

demos/material.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ onComplete2 = () => {
8383
const models = phy.getMesh('palette')
8484
let m = models.palette;
8585

86+
/*
87+
// test basic material
88+
const mat = phy.material({type:'basic', map:m.material.map })
89+
m.children[0].children[0].material = mat
90+
m.children[1].children[0].material = mat
91+
*/
92+
93+
console.log(m)
94+
8695
m.castShadow = true
8796
m.receiveShadow = false;
8897
m.position.set(0,0.3125,1.2)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "phy-engine",
3-
"version": "0.12.2",
3+
"version": "0.12.3",
44
"description": "JavaScript 3D Physics for three.js",
55
"type": "module",
66
"main": "./build/Phy.cjs",

src/3TH/Hub.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ let dayColor = ['#000', '#444', '#feb', 'rgba(213,211,212,0.32)'];
105105
let nightColor = ['#fff', '#bee', '#bfb', 'rgba(0,0,0,0.4)'];
106106

107107
let engineLogo = null;
108+
let engineSkill = null;
109+
let engineCanvas = null
108110

109111
let setting = {
110112
cross:4,
@@ -914,7 +916,12 @@ export class Hub {
914916

915917
if(!engineLogo) return;
916918
menu.removeChild(engineLogo);
919+
topDown.removeChild(engineCanvas);
920+
topDown.removeChild(engineSkill);
921+
917922
engineLogo = null;
923+
engineSkill = null;
924+
engineCanvas = null;
918925

919926
}
920927

@@ -925,6 +932,16 @@ export class Hub {
925932
engineLogo = new Image(256, 128);
926933
engineLogo.style.cssText = 'position:absolute; top:40px; left:200px; width:256px; height: 128px;';
927934
menu.appendChild(engineLogo);
935+
936+
engineSkill = new Image(256, 256);
937+
engineSkill.style.cssText = 'position:absolute; top:0px; left:500px; height:100%; width:auto;';
938+
topDown.appendChild(engineSkill);
939+
940+
engineCanvas = document.createElement( 'canvas' );
941+
engineCanvas.width = engineCanvas.height = 256;
942+
engineCanvas.style.cssText = 'position:absolute; top:0px; left:500px; height:100%; width:auto;';//'position:absolute; width:100%; height:100%;';
943+
topDown.appendChild(engineCanvas);
944+
928945
Hub.setLogoImage();
929946

930947
}
@@ -934,6 +951,60 @@ export class Hub {
934951
if(!engineLogo) return;
935952
name = name ? name.toLowerCase() : Main.engineType.toLowerCase();
936953
engineLogo.src = './assets/logo/'+name+'.png';
954+
engineSkill.src = './assets/logo/skill.png';
955+
Hub.setEnginSkill(name);
956+
957+
}
958+
959+
static setEnginSkill( name ) {
960+
961+
const ctx = engineCanvas.getContext( '2d' );
962+
const data = Main.engineSkill[name]
963+
964+
ctx.clearRect(0, 0, 256, 256);
965+
966+
//console.log(data)
967+
ctx.fillStyle = data.c;
968+
ctx.strokeStyle = data.c;
969+
970+
ctx.beginPath();
971+
let p = Hub.getPoint('speed', data.speed )
972+
ctx.moveTo(p.x, p.y);
973+
p = Hub.getPoint('option', data.option )
974+
ctx.lineTo(p.x, p.y);
975+
p = Hub.getPoint('vehicle', data.vehicle )
976+
ctx.lineTo(p.x, p.y);
977+
p = Hub.getPoint('constraint', data.constraint )
978+
ctx.lineTo(p.x, p.y);
979+
p = Hub.getPoint('stability', data.stability )
980+
ctx.lineTo(p.x, p.y);
981+
p = Hub.getPoint('precision', data.precision )
982+
ctx.lineTo(p.x, p.y);
983+
p = Hub.getPoint('speed', data.speed )
984+
ctx.lineTo(p.x, p.y);
985+
ctx.fill();
986+
ctx.stroke();
987+
988+
989+
}
990+
991+
static getPoint( d, v ) {
992+
let a = 0
993+
switch(d){
994+
case 'speed': a = 0; break;
995+
case 'option': a = 300; break;
996+
case 'vehicle': a = 240; break;
997+
case 'constraint': a = 180; break;
998+
case 'stability': a = 120; break;
999+
case 'precision': a = 60; break;
1000+
1001+
}
1002+
1003+
let angle = (a-180) * (Math.PI/180)
1004+
let x = 128 + ((75*v) * Math.sin(angle))
1005+
let y = 128 + ((75*v) * Math.cos(angle))
1006+
1007+
return {x:x,y:y}
9371008

9381009
}
9391010

src/Main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const setting = {
113113
shadow:0.75,
114114

115115
exposure: 0.5,//0.68,//1,
116-
direct:8, //3.14,
116+
direct:13, //9,
117117
spherical: 1,
118118
envIntensity:2.0,//1.3,
119119
bgIntensity:1.5,//1,
@@ -233,6 +233,14 @@ export const Main = {
233233
isWorker:true,
234234
devMode:false,
235235
engineList: [ 'OIMO', 'AMMO', 'PHYSX', 'HAVOK', 'RAPIER', 'JOLT' ],
236+
engineSkill: {
237+
physx: {c:'rgba(125,201,0,0.5)', speed:0.9, option:1.0, precision:0.9, stability:0.9, constraint:1.0, vehicle:1.0 },
238+
havok: {c:'rgba(255,187,0,0.5)', speed:1.0, option:0.9, precision:1.0, stability:1.0, constraint:0.8, vehicle:0.1 },
239+
jolt: {c:'rgba(22,147,197,0.5)', speed:0.6, option:0.9, precision:0.8, stability:0.8, constraint:0.6, vehicle:0.7 },
240+
rapier:{c:'rgba(168,251,194,0.5)', speed:0.6, option:0.8, precision:0.9, stability:0.5, constraint:0.7, vehicle:0.2 },
241+
ammo : {c:'rgba(255,154,0,0.5)', speed:0.4, option:0.7, precision:0.6, stability:0.5, constraint:0.8, vehicle:0.8 },
242+
oimo: {c:'rgba(246,82,22,0.5)', speed:0.3, option:0.5, precision:0.6, stability:0.5, constraint:0.8, vehicle:0.2 },
243+
},
236244
demoList:[],
237245
demoLink:[],
238246
devLink:[],

0 commit comments

Comments
 (0)