-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finally starting to get the example working
- Loading branch information
1 parent
f3a1d35
commit ba22bd6
Showing
18 changed files
with
186 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,15 @@ | |
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1"> | ||
|
||
<title>PlaneTTechJS Hello World</title> | ||
<title>PlanetTechJS Hello-World</title> | ||
<script src="./coi-serviceworker.js"></script> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"three": "https://unpkg.com/[email protected]/build/three.module.js", | ||
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/", | ||
"three/nodes": "https://unpkg.com/[email protected]/examples/jsm/nodes/Nodes.js", | ||
"planettech": "https://unpkg.com/planettech" | ||
"planettech": "https://unpkg.com/planettech@0.0.8-alpha.0.1.3" | ||
} | ||
} | ||
</script> | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,105 @@ | ||
|
||
import * as THREE from 'https://unpkg.com/[email protected]/build/three.module.js'; | ||
|
||
function toSphereSegement(plane,cnt,r) { | ||
let center = new THREE.Vector3().copy(cnt); | ||
let localCenter = new THREE.Vector3(); | ||
let v3 = new THREE.Vector3(); | ||
let v = new THREE.Vector3(); | ||
|
||
const u = new THREE.Vector3(); // create once | ||
const w = new THREE.Vector3(); // create once | ||
|
||
let p = plane | ||
p.worldToLocal(localCenter.copy(center)); | ||
let pos = p.geometry.attributes.position; | ||
for(let i = 0; i < pos.count; i++){ | ||
v3.fromBufferAttribute(pos, i); | ||
p.localToWorld( v3.clone() ); | ||
u.copy(v3); | ||
w.copy(v3); | ||
v3.sub(localCenter); | ||
v3.normalize().multiplyScalar(r).add(localCenter); | ||
pos.setXYZ(i, v3.x, v3.y, v3.z); | ||
|
||
u.x += 0.1; | ||
u.sub(localCenter); | ||
u.normalize().multiplyScalar(r).add(localCenter); | ||
|
||
w.y += 0.1; | ||
w.sub(localCenter); | ||
w.normalize().multiplyScalar(r).add(localCenter); | ||
|
||
u.sub(v3).cross(w.sub(v3)).normalize(); | ||
p.geometry.attributes.normal.setXYZ(i,u.x,u.y,u.z) | ||
|
||
} | ||
} | ||
|
||
|
||
|
||
function doCalculation(data, cb) { | ||
let result = null, err = null | ||
export function worker(){ | ||
return ` | ||
import * as THREE from 'https://unpkg.com/[email protected]/build/three.module.js'; | ||
function toSphereSegement(plane,cnt,r) { | ||
let center = new THREE.Vector3().copy(cnt); | ||
let localCenter = new THREE.Vector3(); | ||
let v3 = new THREE.Vector3(); | ||
let v = new THREE.Vector3(); | ||
const u = new THREE.Vector3(); // create once | ||
const w = new THREE.Vector3(); // create once | ||
let p = plane | ||
p.worldToLocal(localCenter.copy(center)); | ||
let pos = p.geometry.attributes.position; | ||
for(let i = 0; i < pos.count; i++){ | ||
v3.fromBufferAttribute(pos, i); | ||
p.localToWorld( v3.clone() ); | ||
u.copy(v3); | ||
w.copy(v3); | ||
v3.sub(localCenter); | ||
v3.normalize().multiplyScalar(r).add(localCenter); | ||
pos.setXYZ(i, v3.x, v3.y, v3.z); | ||
u.x += 0.1; | ||
u.sub(localCenter); | ||
u.normalize().multiplyScalar(r).add(localCenter); | ||
w.y += 0.1; | ||
w.sub(localCenter); | ||
w.normalize().multiplyScalar(r).add(localCenter); | ||
let wh = data.parentPositionVector[data.parentPositionVector.length - 1]; | ||
u.sub(v3).cross(w.sub(v3)).normalize(); | ||
p.geometry.attributes.normal.setXYZ(i,u.x,u.y,u.z) | ||
//console.log(wh) | ||
} | ||
} | ||
const geometry = new THREE.PlaneGeometry( wh, wh ); | ||
const material = new THREE.MeshBasicMaterial( ); | ||
const parent = new THREE.Mesh( geometry, material ); | ||
parent.position.set(...data.parentPositionVector) | ||
if (data.side=='right'){ | ||
parent.rotation.y = Math.PI/2; | ||
}else if(data.side=='left'){ | ||
parent.rotation.y = -Math.PI/2; | ||
}else if(data.side=='top'){ | ||
parent.rotation.x = -Math.PI/2; | ||
}else if(data.side=='bottom'){ | ||
parent.rotation.x = Math.PI/2; | ||
}else if(data.side=='front'){ | ||
//pass | ||
}else if(data.side=='back'){ | ||
parent.rotation.y = Math.PI; | ||
} | ||
|
||
var arrp = new Float32Array(data.positionBuffer); | ||
var arrn = new Float32Array(data.normalBuffer); | ||
let f2 = JSON.parse("[" + data.positionStr + "]") | ||
let f2n = JSON.parse("[" + data.normalStr + "]") | ||
function doCalculation(data, cb) { | ||
let result = null, err = null | ||
let f3 = Float32Array.from(f2) | ||
let f3n = Float32Array.from(f2n) | ||
let wh = data.parentPositionVector[data.parentPositionVector.length - 1]; | ||
let geoCore = new THREE.BufferGeometry() | ||
geoCore.setAttribute( 'position', new THREE.Float32BufferAttribute( f3, 3 ) ); | ||
geoCore.setAttribute( 'normal', new THREE.Float32BufferAttribute( f3n, 3 ) ); | ||
// geoCore.translate(...data.positionVector) | ||
|
||
let m = new THREE.Mesh(geoCore,new THREE.Material()) | ||
m.position.set(...data.positionVector) | ||
parent.add(m) | ||
//console.log(wh) | ||
toSphereSegement(m,new THREE.Vector3(...data.center),data.radius) | ||
arrp.set(geoCore.attributes.position.array) | ||
arrn.set(geoCore.attributes.normal.array) | ||
const geometry = new THREE.PlaneGeometry( wh, wh ); | ||
const material = new THREE.MeshBasicMaterial( ); | ||
const parent = new THREE.Mesh( geometry, material ); | ||
parent.position.set(...data.parentPositionVector) | ||
result = 'complete' | ||
cb(err, result) | ||
if (data.side=='right'){ | ||
parent.rotation.y = Math.PI/2; | ||
}else if(data.side=='left'){ | ||
parent.rotation.y = -Math.PI/2; | ||
}else if(data.side=='top'){ | ||
parent.rotation.x = -Math.PI/2; | ||
}else if(data.side=='bottom'){ | ||
parent.rotation.x = Math.PI/2; | ||
}else if(data.side=='front'){ | ||
//pass | ||
}else if(data.side=='back'){ | ||
parent.rotation.y = Math.PI; | ||
} | ||
var arrp = new Float32Array(data.positionBuffer); | ||
var arrn = new Float32Array(data.normalBuffer); | ||
let f2 = JSON.parse("[" + data.positionStr + "]") | ||
let f2n = JSON.parse("[" + data.normalStr + "]") | ||
let f3 = Float32Array.from(f2) | ||
let f3n = Float32Array.from(f2n) | ||
let geoCore = new THREE.BufferGeometry() | ||
geoCore.setAttribute( 'position', new THREE.Float32BufferAttribute( f3, 3 ) ); | ||
geoCore.setAttribute( 'normal', new THREE.Float32BufferAttribute( f3n, 3 ) ); | ||
// geoCore.translate(...data.positionVector) | ||
let m = new THREE.Mesh(geoCore,new THREE.Material()) | ||
m.position.set(...data.positionVector) | ||
parent.add(m) | ||
toSphereSegement(m,new THREE.Vector3(...data.center),data.radius) | ||
arrp.set(geoCore.attributes.position.array) | ||
arrn.set(geoCore.attributes.normal.array) | ||
result = 'complete' | ||
cb(err, result) | ||
} | ||
self.onmessage = function(msg) { | ||
const payload = msg.data | ||
doCalculation(payload, function(err, result) { | ||
const msg = { | ||
err, | ||
payload: result | ||
} | ||
self.postMessage(msg) | ||
}) | ||
} | ||
self.onmessage = function(msg) { | ||
const payload = msg.data | ||
doCalculation(payload, function(err, result) { | ||
const msg = { | ||
err, | ||
payload: result | ||
} | ||
self.postMessage(msg) | ||
}) | ||
}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters