Changeset 1563556
- Timestamp:
- 12/28/2016 03:41:07 PM (8 years ago)
- Location:
- gltf-media-type/trunk
- Files:
-
- 5 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
gltf-media-type/trunk/README.txt
r1562420 r1563556 4 4 Requires at least: 4.5 5 5 Tested up to: 4.7 6 Stable tag: 1. 0.16 Stable tag: 1.1 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 18 18 == Installation == 19 19 20 1. U pload `gltf.php` tothe `/wp-content/plugins/` directory21 1. Activate the plugin through the 'Plugins' menu in WordPress20 1. U the `/wp-content/plugins/` directory 21 1. Activate the plugin through the 'Plugins' menu in WordPress 22 22 1. Upload .gltf or .glb files via the Media browser, or via the Add Media button for posts/pages. 23 23 1. Embed the 3D object in posts using a shortcode, like `[gltf_model scale="1.0" url="http://mywordpresssite.com/wp-content/uploads/2016/12/model.gltf"]. Note: You may get that full URL from the Media browser by selecting the file and copying the link. … … 33 33 == Changelog == 34 34 35 36 37 35 38 = 1.0 = 36 39 * First version, just basic rendering -
gltf-media-type/trunk/admin/class-gltf-admin.php
r1562406 r1563556 52 52 $this->plugin_name = $plugin_name; 53 53 $this->version = $version; 54 55 54 } 56 55 … … 83 82 * @since 1.0.0 84 83 */ 85 public function enqueue_scripts( ) {86 wp_enqueue_script( $this->plugin_name, plugin_dir_url( dirname( __FILE__ ) ) . 'js/three.min.js', null, $this->version, false );84 public function enqueue_scripts() { 85 wp_enqueue_script( , plugin_dir_url( dirname( __FILE__ ) ) . 'js/three.min.js', null, $this->version, false ); 87 86 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/gltf-admin.js', array( 'jquery' ), $this->version, false ); 88 87 88 89 90 91 92 93 94 95 96 89 97 } 90 98 -
gltf-media-type/trunk/gltf.php
r1562420 r1563556 12 12 * Plugin URI: http://goldsounds.com/plugins/gltf 13 13 * Description: A plugin to upload and render glTF 3D models in WordPress. 14 * Version: 1. 0.114 * Version: 1.1 15 15 * Author: Daniel Walmsley 16 16 * Author URI: http://goldsounds.com … … 51 51 * admin-specific hooks, and public-facing site hooks. 52 52 */ 53 require plugin_dir_path( __FILE__ ) . 'includes/class-gltf.php';53 require plugin_dir_path( __FILE__ ) . 'includes/class-gltf.php'; 54 54 55 55 /** -
gltf-media-type/trunk/includes/class-gltf-activator.php
r1562406 r1563556 31 31 */ 32 32 public static function activate() { 33 33 require_once plugin_dir_path( __FILE__ ) . 'class-gltf.php'; 34 $plugin = new Gltf(); 35 $plugin->register_scene_post_type(); 36 flush_rewrite_rules(); 34 37 } 35 38 -
gltf-media-type/trunk/includes/class-gltf-deactivator.php
r1562406 r1563556 31 31 */ 32 32 public static function deactivate() { 33 33 flush_rewrite_rules(); 34 34 } 35 35 -
gltf-media-type/trunk/includes/class-gltf.php
r1562406 r1563556 140 140 // add three.js if the current post has our shortcode 141 141 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_model_render_script' ) ); 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 142 157 } 143 158 … … 165 180 } 166 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 167 304 public function enqueue_model_render_script() { 168 305 global $post; 169 if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'gltf_model') ) { 170 wp_enqueue_script( 'threejs', plugin_dir_url( dirname( __FILE__ ) ) . 'js/three.min.js', null, $this->version, false ); 171 wp_enqueue_script( 'gltf-loader', plugin_dir_url( dirname( __FILE__ ) ) . 'js/loaders/GLTFLoader.js', array( 'threejs' ), $this->version, false ); 172 wp_enqueue_script( 'orbitcontrols', plugin_dir_url( dirname( __FILE__ ) ) . 'js/OrbitControls.js', array( 'threejs' ), $this->version, false ); 173 wp_enqueue_script( 'gltf-model-preview', plugin_dir_url( dirname( __FILE__ ) ) . 'js/gltf-model-preview.js', array( 'jquery', 'gltf-loader', 'orbitcontrols' ), $this->version, false ); 174 } 306 if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'gltf_model') ) { 307 require_once dirname( __FILE__ ) . '/class-gltf-model-utils.php'; 308 Gltf_Model_Utils::enqueue_scripts( $this->version ); 309 } 175 310 } 176 311 -
gltf-media-type/trunk/js/gltf-model-preview.js
r1562406 r1563556 12 12 13 13 function addLights() { 14 var ambient = new THREE.AmbientLight( 0x101030 ); 14 // var ambient = new THREE.AmbientLight( 0x101030 ); 15 var ambient = new THREE.AmbientLight( 0xFFFFFF, 1 ); 15 16 scene.add( ambient ); 16 17 -
gltf-media-type/trunk/public/class-gltf-public.php
r1562406 r1563556 96 96 * class. 97 97 */ 98 99 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/gltf-public.js', array( 'jquery' ), $this->version, false ); 98 require_once dirname( dirname( __FILE__ ) ) . '/includes/class-gltf-model-utils.php'; 99 Gltf_Model_Utils::enqueue_common_gltf_scripts( $this->version ); 100 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/gltf-public.js', array( 'jquery', 'orbitcontrols' ), $this->version, false ); 100 101 101 102 } -
gltf-media-type/trunk/public/js/gltf-public.js
r1562406 r1563556 2 2 'use strict'; 3 3 4 /** 5 * All of the code for your public-facing JavaScript source 6 * should reside in this file. 7 * 8 * Note: It has been assumed you will write jQuery code here, so the 9 * $ function reference has been prepared for usage within the scope 10 * of this function. 11 * 12 * This enables you to define handlers, for when the DOM is ready: 13 * 14 * $(function() { 15 * 16 * }); 17 * 18 * When the window is loaded: 19 * 20 * $( window ).load(function() { 21 * 22 * }); 23 * 24 * ...and/or other possibilities. 25 * 26 * Ideally, it is not considered best practise to attach more than a 27 * single DOM-ready or window-load handler for a particular page. 28 * Although scripts in the WordPress core, Plugins and Themes may be 29 * practising this, we should strive to set a better example in our own work. 30 */ 4 window.GltfScene = function() { 5 6 var container, camera, scene, renderer, controls; 7 8 function addCamera() { 9 camera = new THREE.PerspectiveCamera( 75, container.offsetWidth / container.offsetHeight, 1, 2000 ); 10 camera.position.set(0, 2, 3); 11 scene.add( camera ); 12 } 13 14 function addLights() { 15 // var ambient = new THREE.AmbientLight( 0x101030 ); 16 var ambient = new THREE.AmbientLight( 0xFFFFFF, 1 ); 17 scene.add( ambient ); 18 19 var directionalLight = new THREE.DirectionalLight( 0xffeedd ); 20 directionalLight.position.set( 0, 0, 1 ); 21 scene.add( directionalLight ); 22 } 23 24 function addControls() { 25 controls = new THREE.OrbitControls( camera, renderer.domElement ); 26 controls.userPan = false; 27 controls.userPanSpeed = 0.0; 28 controls.maxDistance = 5000.0; 29 controls.maxPolarAngle = Math.PI * 0.495; 30 controls.autoRotate = false; 31 // controls.autoRotateSpeed = -10.0; 32 } 33 34 function addRenderer() { 35 renderer = new THREE.WebGLRenderer({antialias:true}); 36 renderer.setClearColor( 0x222222 ); 37 renderer.setPixelRatio( window.devicePixelRatio ); 38 renderer.setSize( container.offsetWidth, container.offsetHeight ); 39 } 40 41 function addLoadingLogger() { 42 var manager = new THREE.LoadingManager(); 43 manager.onProgress = function ( item, loaded, total ) { 44 console.log( item, loaded, total ); 45 }; 46 } 47 48 function loadModel( modelUrl, modelScale ) { 49 THREE.GLTFLoader.Shaders.removeAll(); // remove all previous shaders 50 var loader = new THREE.GLTFLoader; 51 loader.load( modelUrl, function( data ) { 52 var object = data.scene; 53 object.scale.set(modelScale, modelScale, modelScale); 54 55 var animations = data.animations; 56 if ( animations && animations.length ) { 57 mixer = new THREE.AnimationMixer( object ); 58 for ( var i = 0; i < animations.length; i ++ ) { 59 var animation = animations[ i ]; 60 mixer.clipAction( animation ).play(); 61 } 62 } 63 64 scene.add( object ); 65 } ); 66 } 67 68 function render() { 69 renderer.render( scene, camera ); 70 } 71 72 function animate() { 73 requestAnimationFrame( animate ); 74 THREE.GLTFLoader.Animations.update(); 75 THREE.GLTFLoader.Shaders.update(scene, camera); 76 render(); 77 controls.update(); 78 } 79 80 function initScene( id ) { 81 container = jQuery( '#'+id ).get(0); 82 83 scene = new THREE.Scene(); 84 85 addLights(); // LIGHTS! 86 addCamera(); // CAMERA! 87 addRenderer(); // ACTION! :) 88 addControls(); 89 addLoadingLogger(); 90 91 container.appendChild( renderer.domElement ); 92 } 93 94 return { 95 render: function( id, scene ) { 96 console.log("rendering "+id+": "+JSON.stringify( scene )); 97 98 initScene( id ); 99 loadModel( scene.main_model, scene.main_model_scale ); 100 animate(); 101 } 102 } 103 }(); 31 104 32 105 })( jQuery );
Note: See TracChangeset
for help on using the changeset viewer.