-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5a77c6
commit 85f3091
Showing
16 changed files
with
1,570 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"webgl": [ | ||
"creating_3d_text" | ||
"creating_3d_text", | ||
"loading_3d_models_NissanZProto" | ||
], | ||
"webgl / nodes": [ | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>PyWeb3D webgl - GLTFloader</title> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/brython.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/brython_stdlib.js"></script> | ||
<script src="https://unpkg.com/[email protected]/build/three.js"></script> | ||
<script src="https://www.pyweb3d.org/pyweb3d/v1.0.0/pyweb3d.brython.js"></script> | ||
<link rel="stylesheet" href="main.css"> | ||
<style> | ||
body { margin: 0; } | ||
</style> | ||
</head> | ||
<body onload="brython(1)"> | ||
<script src="../jsm/loaders/GLTFLoader.js"></script> | ||
<script src="../jsm/controls/OrbitControls.js"></script> | ||
<script src="../jsm/loaders/RGBELoader.js"></script> | ||
|
||
<div id="info"> | ||
<a href="https://pyweb3d.org" target="_blank" rel="noopener">PyWeb3D</a> car materials<br/> | ||
Nissan Z Proto model by <a href="https://sketchfab.com/3d-models/nissan-z-proto-db9a5f7ae9d84a0fb01cac96afe3e69c" target="_blank" rel="noopener">Lexyc16</a> | ||
<br><br> | ||
</div> | ||
|
||
<script type="text/python"> | ||
from browser import document, window | ||
from pyweb3d.pyweb3d import * | ||
|
||
GLTFLoader = window.THREE.GLTFLoader.new | ||
OrbitControls = window.THREE.OrbitControls.new | ||
RGBELoader = window.THREE.RGBELoader.new | ||
|
||
#Variables for setup | ||
|
||
camera = None | ||
renderer = None | ||
scene = None | ||
car = None | ||
|
||
def init(): | ||
global camera | ||
global renderer | ||
global scene | ||
global car | ||
|
||
#Create scene | ||
scene = Scene() | ||
scene.background = Color( 0x333333 ) | ||
scene.environment = RGBELoader().load( 'textures/venice_sunset_1k.hdr' ) | ||
scene.environment.mapping = EquirectangularReflectionMapping | ||
scene.fog = Fog( 0x333333, 10, 15 ) | ||
|
||
grid = GridHelper( 20, 40, 0xffffff, 0xffffff ) | ||
grid.material.opacity = 0.2 | ||
grid.material.depthWrite = False | ||
grid.material.transparent = True | ||
scene.add( grid ) | ||
|
||
fov = 45 | ||
aspect = window.innerWidth / window.innerHeight | ||
near = 1 | ||
far = 1500 | ||
|
||
#Camera setup | ||
camera = PerspectiveCamera(fov, aspect, near, far) | ||
camera.position.x = 8 | ||
camera.position.y = 1 | ||
camera.position.z = 10 | ||
|
||
ambientLight = AmbientLight( 'white', 2 ) | ||
scene.add( ambientLight ) | ||
|
||
DirectLight = DirectionalLight( 'white', 3.5 ) | ||
DirectLight.position.set( 100, 100, 100 ) | ||
scene.add( DirectLight ) | ||
|
||
hemiLight = HemisphereLight('white', 'darkslategrey', 5) | ||
scene.add(hemiLight) | ||
|
||
#Renderer | ||
renderer = WebGLRenderer( { 'antialias': True } ) | ||
renderer.setPixelRatio( window.devicePixelRatio ) | ||
renderer.setSize( window.innerWidth, window.innerHeight ) | ||
document.body.appendChild( renderer.domElement ) | ||
|
||
controls = OrbitControls(camera, renderer.domElement) | ||
|
||
#Load Model | ||
loader = GLTFLoader() | ||
|
||
def loadGLTF(gltf): | ||
car = gltf.scene | ||
car.scale.setScalar( 1.5 ) | ||
# center | ||
box = Box3().setFromObject( car ) | ||
center = box.getCenter( Vector3() ) | ||
car.position.x += ( car.position.x - center.x ) | ||
car.position.y += ( car.position.y - center.y + 1.4) | ||
car.position.z += ( car.position.z - center.z ) | ||
|
||
scene.add( car ) | ||
animate(0) | ||
|
||
loader.load( 'models/Nissan_Z_Proto/scene.gltf', loadGLTF) | ||
|
||
def onWindowResize(resize): | ||
|
||
camera.aspect = window.innerWidth / window.innerHeight | ||
camera.updateProjectionMatrix() | ||
|
||
renderer.setSize( window.innerWidth, window.innerHeight ) | ||
|
||
window.addEventListener( 'resize', onWindowResize ) | ||
|
||
def animate(time): | ||
window.requestAnimationFrame( animate ) | ||
renderer.render( scene, camera ) | ||
|
||
init() | ||
</script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Model Information: | ||
* title: Nissan Z Proto | ||
* source: https://sketchfab.com/3d-models/nissan-z-proto-db9a5f7ae9d84a0fb01cac96afe3e69c | ||
* author: Lexyc16 (https://sketchfab.com/Lexyc16) | ||
|
||
Model License: | ||
* license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) | ||
* requirements: Author must be credited. Commercial use is allowed. | ||
|
||
If you use this 3D model in your project be sure to copy paste this credit wherever you share it: | ||
This work is based on "Nissan Z Proto" (https://sketchfab.com/3d-models/nissan-z-proto-db9a5f7ae9d84a0fb01cac96afe3e69c) by Lexyc16 (https://sketchfab.com/Lexyc16) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) |
Binary file not shown.
Oops, something went wrong.