Browse Source

Trying to make an example for VRMLLoader.

Trying to make an example for VRMLLoader based on the VTKLoader example
to test the fix mentioned in mrdoob/three.js#3728 , but I'm getting a
"Cannot read property 'length' of undefined" error.
Cecile Muller 12 years ago
parent
commit
3c85e8efcc
2 changed files with 178 additions and 0 deletions
  1. 32 0
      examples/models/vrml/simple.wrl
  2. 146 0
      examples/webgl_loader_vrml.html

+ 32 - 0
examples/models/vrml/simple.wrl

@@ -0,0 +1,32 @@
+#VRML V2.0 utf8
+
+Transform {
+	rotation 0 1 0 0.4
+	children DEF myshape Shape {
+		appearance Appearance {
+			material Material {
+				diffuseColor 0 1 0
+				emissiveColor 0.2 0.2 0.2
+			}
+		}
+		geometry Box {
+			size 3 2 1
+		}
+	}
+}
+
+
+#Transform {
+#	rotation 1,0,0,0.4
+#	children USE myshape
+#}
+
+
+#Transform {
+#	rotation
+#		0
+#		0
+#		1
+#		0.4
+#	children USE myshape
+#}

+ 146 - 0
examples/webgl_loader_vrml.html

@@ -0,0 +1,146 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<title>three.js webgl - loaders - vrml loader</title>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
+		<style>
+			body {
+				font-family: Monospace;
+				background-color: #000;
+				color: #fff;
+				margin: 0px;
+				overflow: hidden;
+			}
+			#info {
+				color: #fff;
+				position: absolute;
+				top: 10px;
+				width: 100%;
+				text-align: center;
+				z-index: 100;
+				display:block;
+			}
+			#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
+		</style>
+	</head>
+
+	<body>
+		<div id="info">
+		<a href="http://threejs.org" target="_blank">three.js</a> -
+		vrml format loader test -
+		<!--model from <a href="http://cs.iupui.edu/~aharris/webDesign/vrml/" target="_blank">VRML 2.0 Tutorial</a>,-->
+		</div>
+
+		<script src="../build/three.min.js"></script>
+
+		<script src="js/controls/TrackballControls.js"></script>
+
+		<script src="js/loaders/VRMLLoader.js"></script>
+
+		<script src="js/Detector.js"></script>
+		<script src="js/libs/stats.min.js"></script>
+
+		<script>
+
+			if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
+
+			var container, stats;
+
+			var camera, controls, scene, renderer;
+
+			var cross;
+
+			init();
+			animate();
+
+			function init() {
+
+				camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1e10 );
+				camera.position.z = 0.2;
+
+				controls = new THREE.TrackballControls( camera );
+
+				controls.rotateSpeed = 5.0;
+				controls.zoomSpeed = 5;
+				controls.panSpeed = 2;
+
+				controls.noZoom = false;
+				controls.noPan = false;
+
+				controls.staticMoving = true;
+				controls.dynamicDampingFactor = 0.3;
+
+				scene = new THREE.Scene();
+
+				scene.add( camera );
+
+				// light
+
+				var dirLight = new THREE.DirectionalLight( 0xffffff );
+				dirLight.position.set( 200, 200, 1000 ).normalize();
+
+				camera.add( dirLight );
+				camera.add( dirLight.target );
+
+				var material = new THREE.MeshLambertMaterial( { color:0xffffff, side: THREE.DoubleSide } );
+
+				var loader = new THREE.VRMLLoader();
+				loader.addEventListener( 'load', function ( event ) {
+
+					var geometry = event.content;
+
+					var mesh = new THREE.Mesh( geometry, material );
+					mesh.position.setY( - 0.09 );
+					scene.add( mesh );
+
+				} );
+				loader.load( "models/vrml/simple.wrl" );
+
+				// renderer
+
+				renderer = new THREE.WebGLRenderer( { antialias: false } );
+				renderer.setClearColor( 0x000000, 1 );
+				renderer.setSize( window.innerWidth, window.innerHeight );
+
+				container = document.createElement( 'div' );
+				document.body.appendChild( container );
+				container.appendChild( renderer.domElement );
+
+				stats = new Stats();
+				stats.domElement.style.position = 'absolute';
+				stats.domElement.style.top = '0px';
+				container.appendChild( stats.domElement );
+
+				//
+
+				window.addEventListener( 'resize', onWindowResize, false );
+
+			}
+
+			function onWindowResize() {
+
+				camera.aspect = window.innerWidth / window.innerHeight;
+				camera.updateProjectionMatrix();
+
+				renderer.setSize( window.innerWidth, window.innerHeight );
+
+				controls.handleResize();
+
+			}
+
+			function animate() {
+
+				requestAnimationFrame( animate );
+
+				controls.update();
+				renderer.render( scene, camera );
+
+				stats.update();
+
+			}
+
+		</script>
+
+	</body>
+</html>