芝麻web文件管理V1.00
编辑当前文件:/home/seolotod/critterchoice.com/wp-content/themes/rehub-theme/rehub-elementor/wpsm-3dmodel.php
start_controls_section( 'general', [ 'label' => esc_html__( 'GLTF Model loader', 'rehub-theme' ), 'tab' => Controls_Manager::TAB_CONTENT, ]); $this->add_control( 'td_url', [ 'label' => esc_html__( 'Url on gltf, glb model', 'rehub-theme' ), 'label_block' => true, 'type' => \Elementor\Controls_Manager::TEXT, ]); $this->add_control( 'td_image', [ 'label' => esc_html__( 'Fallback image', 'rehub-theme' ), 'label_block' => true, 'type' => \Elementor\Controls_Manager::MEDIA, ]); $this->add_control( 'td_load_iter', array( 'label' => esc_html__( 'Load only on iteraction', 'rehub-theme' ), 'desc' => esc_html__( 'To improve google web vitals', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'rehub-theme' ), 'label_off' => esc_html__( 'No', 'rehub-theme' ), 'return_value' => 'true', 'condition' => [ 'td_image[url]!' => '', ], ) ); $this->end_controls_section(); $this->start_controls_section( 'canvassize', [ 'label' => esc_html__( 'Canvas Size', 'rehub-theme' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ]); $this->add_responsive_control( 'threecanvwidth', [ 'label' => __('Area width', 'rehub-theme'), 'type' => Controls_Manager::SLIDER, 'default' => [ 'size' => '100', 'unit' => '%', ], 'size_units' => [ '%', 'px'], 'separator' => 'before', 'range' => [ '%' => [ 'min' => 1, 'max' => 200, ], 'px' => [ 'min' => 100, 'max' => 2500, ], ], 'selectors' => [ '{{WRAPPER}} .rh-t-model' => 'width: {{SIZE}}{{UNIT}};', ], ] ); $this->add_responsive_control( 'threecanvheight', [ 'label' => __('Area height', 'rehub-theme'), 'type' => Controls_Manager::SLIDER, 'default' => [ 'size' => '250', 'unit' => 'px', ], 'size_units' => [ '%', 'px'], 'range' => [ '%' => [ 'min' => 1, 'max' => 200, ], 'px' => [ 'min' => 100, 'max' => 2500, ], ], 'selectors' => [ '{{WRAPPER}} .rh-t-model' => 'height: {{SIZE}}{{UNIT}};', ], ] ); $this->end_controls_section(); $this->start_controls_section( 'aradd', [ 'label' => esc_html__( 'AR settings', 'rehub-theme' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ]); $this->add_control( 'td_ar', array( 'label' => esc_html__( 'Enable Argumented Reality option?', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'rehub-theme' ), 'label_off' => esc_html__( 'No', 'rehub-theme' ), 'return_value' => 'true', 'default' => 'true' ) ); $this->add_control( 'td_ar_scale', array( 'label' => esc_html__( 'Disable scale option for AR', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'rehub-theme' ), 'label_off' => esc_html__( 'No', 'rehub-theme' ), 'return_value' => 'true', ) ); $this->add_control( 'td_ar_wall', array( 'label' => esc_html__( 'Enable placement on Wall', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'rehub-theme' ), 'label_off' => esc_html__( 'No', 'rehub-theme' ), 'return_value' => 'true', ) ); $this->add_control( 'usdz_url', [ 'label' => esc_html__( 'Url of Usdz model for Ios', 'rehub-theme' ), 'label_block' => true, 'type' => Controls_Manager::TEXT, ]); $this->end_controls_section(); $this->start_controls_section( 'cameraadd', [ 'label' => esc_html__( 'Camera settings', 'rehub-theme' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ]); $this->add_control( 'td_rotate', array( 'label' => esc_html__( 'Enable Auto rotate?', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'rehub-theme' ), 'label_off' => esc_html__( 'No', 'rehub-theme' ), 'return_value' => 'true', 'default' => 'true' ) ); $this->add_control( 'td_camera', array( 'label' => esc_html__( 'Enable Camera Control?', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'rehub-theme' ), 'label_off' => esc_html__( 'No', 'rehub-theme' ), 'return_value' => 'true', 'default' => 'true' ) ); $this->add_control( 'td_zoom_disable', array( 'label' => esc_html__( 'Disable zoom', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'rehub-theme' ), 'label_off' => esc_html__( 'No', 'rehub-theme' ), 'return_value' => 'true', ) ); $this->add_control( 'td_cam_orbit', array( 'label' => esc_html__( 'Custom camera orbit', 'rehub-theme' ), 'description' => '
Documentation
', 'type' => \Elementor\Controls_Manager::CODE, ) ); $this->add_control( 'td_scale', array( 'label' => esc_html__( 'Scale', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0.01, 'max' => 10, 'step' => 0.01, ) ); $this->end_controls_section(); $this->start_controls_section( 'lightadd', [ 'label' => esc_html__( 'Light and Environment', 'rehub-theme' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ]); $this->add_control( 'td_sky', [ 'label' => esc_html__( 'HDR skybox image url', 'rehub-theme' ), 'label_block' => true, 'type' => \Elementor\Controls_Manager::TEXT, ]); $this->add_control( 'td_env', [ 'label' => esc_html__( 'HDR environment image url', 'rehub-theme' ), 'label_block' => true, 'type' => \Elementor\Controls_Manager::TEXT, ]); $this->add_control( 'td_neutral', array( 'label' => esc_html__( 'Enable Neutral Light', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'rehub-theme' ), 'label_off' => esc_html__( 'No', 'rehub-theme' ), 'return_value' => 'true', 'condition' => [ 'td_env[url]' => '', ], ) ); $this->add_control( 'td_shadow_opacity', array( 'label' => esc_html__( 'Shadow Opacity', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'max' => 1, 'step' => 0.01, ) ); $this->add_control( 'td_shadow_soft', array( 'label' => esc_html__( 'Shadow Softness', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'max' => 1, 'step' => 0.01, ) ); $this->end_controls_section(); $this->start_controls_section( 'animationadd', [ 'label' => esc_html__( 'Animation settings', 'rehub-theme' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ]); $this->add_control( 'td_play', array( 'label' => esc_html__( 'Autoplay animation of model', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'rehub-theme' ), 'label_off' => esc_html__( 'No', 'rehub-theme' ), 'return_value' => 'true', ) ); $this->add_control( 'td_an_choose', [ 'label' => esc_html__( 'Set name of animation to play', 'rehub-theme' ), 'label_block' => true, 'type' => Controls_Manager::TEXT, ]); $this->end_controls_section(); $this->start_controls_section( 'transformadd', [ 'label' => esc_html__( 'Transform animation settings', 'rehub-theme' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ]); $this->add_control( 'td_rx', array( 'label' => esc_html__( 'Roll strength', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'max' => 250, 'step' => 1, ) ); $this->add_control( 'td_ry', array( 'label' => esc_html__( 'Pitch strength', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'max' => 250, 'step' => 1, ) ); $this->add_control( 'td_rz', array( 'label' => esc_html__( 'Yaw strength', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'max' => 250, 'step' => 1, ) ); $this->add_control( 'td_mmove', array( 'label' => esc_html__( 'React on Mouth move', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'min' => 0, 'max' => 100, 'step' => 0.1, ) ); $this->end_controls_section(); $this->start_controls_section( 'scriptsadd', [ 'label' => esc_html__( 'Additional js scripts', 'rehub-theme' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ]); $this->add_control( 'addscript', array( 'label' => esc_html__( 'Additional script script', 'rehub-theme' ), 'description' => 'available variables are modelViewer, mouseX, mouseY', 'type' => \Elementor\Controls_Manager::CODE, ) ); $this->add_control( 'td_variants', array( 'label' => esc_html__( 'Enable variant selector of model', 'rehub-theme' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'rehub-theme' ), 'label_off' => esc_html__( 'No', 'rehub-theme' ), 'return_value' => 'yes', ) ); $this->end_controls_section(); } /* Widget output Rendering */ protected function render() { $settings = $this->get_settings_for_display(); $addscript = $settings['addscript']; $variants = $variantblock = $posterblock = ''; if ( ! empty( $settings['td_url'] )) { $this->add_render_attribute( 'rh_tdata', 'src', esc_url($settings['td_url']) ); } if ( ! empty( $settings['td_sky'])) { $this->add_render_attribute( 'rh_tdata', 'skybox-image', esc_url($settings['td_sky'])); } if ( ! empty( $settings['td_env'])) { $this->add_render_attribute( 'rh_tdata', 'environment-image', esc_url($settings['td_env'])); } if ( ! empty( $settings['td_load_iter'] )) { $this->add_render_attribute( 'rh_tdata', 'data-loaditer', 'true' ); } if ( ! empty( $settings['td_neutral'] )) { $this->add_render_attribute( 'rh_tdata', 'environment-image', 'neutral' ); } if ( ! empty( $settings['td_shadow_opacity'] )) { $this->add_render_attribute( 'rh_tdata', 'shadow-intensity', $settings['td_shadow_opacity'] ); } if ( ! empty( $settings['td_shadow_soft'] )) { $this->add_render_attribute( 'rh_tdata', 'shadow-softness', $settings['td_shadow_soft'] ); } if ( ! empty( $settings['td_play'] )) { $this->add_render_attribute( 'rh_tdata', 'autoplay' ); } if ( ! empty( $settings['td_an_choose'] )) { $this->add_render_attribute( 'rh_tdata', 'animation-name', $settings['td_an_choose'] ); } if ( ! empty( $settings['td_rotate'] )) { $this->add_render_attribute( 'rh_tdata', 'auto-rotate' ); } if ( ! empty( $settings['td_camera'] )) { $this->add_render_attribute( 'rh_tdata', 'camera-controls' ); $this->add_render_attribute( 'rh_tdata', 'data-camera', "yes" ); } if ( ! empty( $settings['td_zoom_disable'] )) { $this->add_render_attribute( 'rh_tdata', 'disable-zoom' ); } if ( ! empty( $settings['td_cam_orbit'] )) { $this->add_render_attribute( 'rh_tdata', 'camera-orbit', $settings['td_cam_orbit'] ); } if ( ! empty( $settings['td_ar'] )) { $this->add_render_attribute( 'rh_tdata', 'ar' ); } if ( ! empty( $settings['td_ar_scale'] )) { $this->add_render_attribute( 'rh_tdata', 'ar-scale', 'fixed' ); } if ( ! empty( $settings['td_ar_wall'] )) { $this->add_render_attribute( 'rh_tdata', 'ar-placement', 'wall' ); } if ( ! empty( $settings['usdz_url'] )) { $this->add_render_attribute( 'rh_tdata', 'ios-src', $settings['usdz_url'] ); } if ( ! empty( $settings['td_scale'] )) { $this->add_render_attribute( 'rh_tdata', 'data-scale', $settings['td_scale'] ); } if ( ! empty( $settings['td_rx'] )) { $this->add_render_attribute( 'rh_tdata', 'data-rx', $settings['td_rx'] ); } if ( ! empty( $settings['td_ry'] )) { $this->add_render_attribute( 'rh_tdata', 'data-ry', $settings['td_ry'] ); } if ( ! empty( $settings['td_rz'] )) { $this->add_render_attribute( 'rh_tdata', 'data-rz', $settings['td_rz'] ); } if ( ! empty( $settings['td_mmove'] )) { $this->add_render_attribute( 'rh_tdata', 'data-mousemove', $settings['td_mmove'] ); } if ( ! empty( $settings['td_variants'] )) { $this->add_render_attribute( 'rh_tdata', 'data-variants', 'yes' ); $variants = true; } $widgetId = $this->get_id(); if($variants){ $variantblock = '
'.esc_html__('Variant: ', 'rehub-theme').'
'; } if ( ! empty( $settings['td_image']['url'] )) { $posterblock = '
'; } $defaultblock = '
'.esc_html__("View in your space", "rehub-theme").'
'; echo '
get_render_attribute_string( 'rh_tdata' ).'>'.$variantblock.$posterblock.$defaultblock.'
'; $script = ' (() => { const modelViewer = document.querySelector("#rh_three_'.esc_attr($widgetId). '"); modelViewer.addEventListener("progress", onRHProgress); const time = performance.now(); var td_rx = modelViewer.dataset.rx; var td_ry = modelViewer.dataset.ry; var td_rz = modelViewer.dataset.rz; var td_scale = modelViewer.dataset.scale; var td_camera = modelViewer.dataset.camera; var td_variants = modelViewer.dataset.variants; var td_mousemove = modelViewer.dataset.mousemove; var td_loaditer = modelViewer.dataset.loaditer; if(td_loaditer){ }else{ requestIdleCallback(function(){ onRHInteraction(); }, { timeout: 2500 }); } var mouseX = 0; var mouseY = 0; var windowHalfX = window.innerWidth / 2; var windowHalfY = window.innerHeight / 2; document.addEventListener("mousemove", function(event){ mouseX = ( event.clientX - windowHalfX ); mouseY = ( event.clientY - windowHalfY ); }); if(td_scale){ modelViewer.scale = `${td_scale} ${td_scale} ${td_scale}`; } if(td_variants){ const select = document.querySelector("#rh_threevar_'.esc_attr($widgetId). '"); modelViewer.addEventListener("load", () => { const names = modelViewer.availableVariants; if(typeof names !=="undefined" && names.length > 0) { select.classList.remove("rhhidden"); for (const name of names) { const option = document.createElement("option"); option.value = name; option.textContent = name; select.appendChild(option); } } }); select.addEventListener("input", (event) => { modelViewer.variantName = event.target.value; }); } '.$addscript.' if(td_rx || td_ry || td_rz || td_mousemove){ const animate = (now) => { requestAnimationFrame(animate); if(typeof modelViewer.orientation !=="undefined"){ let spaceorient = modelViewer.orientation.split(" "); if(typeof td_rx === "undefined") td_rx = 0; if(typeof td_ry === "undefined") td_ry = 0; if(typeof td_rz === "undefined") td_rz = 0; let rx = parseFloat(spaceorient[0]) + td_rx/50; let ry = parseFloat(spaceorient[1]) + td_ry/50; let rz = parseFloat(spaceorient[2]) + td_rz/50; if(td_mousemove){ rz += 0.05 * ( mouseX * td_mousemove/1000 - rz ); ry += 0.05 * ( mouseY * td_mousemove/1000 - ry ); } modelViewer.orientation = `${rx}deg ${ry}deg ${rz}deg`; if(!td_camera){ modelViewer.updateFraming(); } } }; animate(); } })(); '; if ( Plugin::$instance->editor->is_edit_mode() ) { echo ''; }else{ wp_add_inline_script('rh-modelviewer-init', $script); } //echo ''; } } Plugin::instance()->widgets_manager->register( new WPSM_Model_T_Widget );