Plugin Directory

Changeset 1563556

Timestamp:
12/28/2016 03:41:07 PM (8 years ago)
Author:
goldsounds
Message:

Added gltf_scene post type

Location:
gltf-media-type/trunk
Files:
5 added
9 edited

Legend:

Unmodified
Added
Removed
  • gltf-media-type/trunk/README.txt

    r1562420 r1563556  
    44Requires at least: 4.5
    55Tested up to: 4.7
    6 Stable tag: 1.0.1
     6Stable tag: 1.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1818== Installation ==
    1919
    20 1. Upload `gltf.php` to the `/wp-content/plugins/` directory
    21 1. Activate the plugin through the 'Plugins' menu in WordPress
     201. U the `/wp-content/plugins/` directory
     211. Activate the plugin through the 'Plugins' menu in WordPress
    22221. Upload .gltf or .glb files via the Media browser, or via the Add Media button for posts/pages.
    23231. 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.
     
    3333== Changelog ==
    3434
     35
     36
     37
    3538= 1.0 =
    3639* First version, just basic rendering
  • gltf-media-type/trunk/admin/class-gltf-admin.php

    r1562406 r1563556  
    5252        $this->plugin_name = $plugin_name;
    5353        $this->version = $version;
    54 
    5554    }
    5655
     
    8382     * @since    1.0.0
    8483     */
    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 );
    8786        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/gltf-admin.js', array( 'jquery' ), $this->version, false );
    8887
     88
     89
     90
     91
     92
     93
     94
     95
     96
    8997    }
    9098
  • gltf-media-type/trunk/gltf.php

    r1562420 r1563556  
    1212 * Plugin URI:        http://goldsounds.com/plugins/gltf
    1313 * Description:       A plugin to upload and render glTF 3D models in WordPress.
    14  * Version:           1.0.1
     14 * Version:           1.1
    1515 * Author:            Daniel Walmsley
    1616 * Author URI:        http://goldsounds.com
     
    5151 * admin-specific hooks, and public-facing site hooks.
    5252 */
    53 require plugin_dir_path( __FILE__ ) . 'includes/class-gltf.php';
     53require plugin_dir_path( __FILE__ ) . 'includes/class-gltf.php';
    5454
    5555/**
  • gltf-media-type/trunk/includes/class-gltf-activator.php

    r1562406 r1563556  
    3131     */
    3232    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();
    3437    }
    3538
  • gltf-media-type/trunk/includes/class-gltf-deactivator.php

    r1562406 r1563556  
    3131     */
    3232    public static function deactivate() {
    33 
     33        flush_rewrite_rules();
    3434    }
    3535
  • gltf-media-type/trunk/includes/class-gltf.php

    r1562406 r1563556  
    140140        // add three.js if the current post has our shortcode
    141141        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
    142157    }
    143158
     
    165180    }
    166181
     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
    167304    public function enqueue_model_render_script() {
    168305        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        }
    175310    }
    176311
  • gltf-media-type/trunk/js/gltf-model-preview.js

    r1562406 r1563556  
    1212
    1313    function addLights() {
    14         var ambient = new THREE.AmbientLight( 0x101030 );
     14        // var ambient = new THREE.AmbientLight( 0x101030 );
     15        var ambient = new THREE.AmbientLight( 0xFFFFFF, 1 );
    1516        scene.add( ambient );
    1617
  • gltf-media-type/trunk/public/class-gltf-public.php

    r1562406 r1563556  
    9696         * class.
    9797         */
    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 );
    100101
    101102    }
  • gltf-media-type/trunk/public/js/gltf-public.js

    r1562406 r1563556  
    22    'use strict';
    33
    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     }();
    31104
    32105})( jQuery );
Note: See TracChangeset for help on using the changeset viewer.