Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions devtools-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!DOCTYPE html>
<html>
<head>
<title>Three.js DevTools Test</title>
<style>
body { margin: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #000; }
#devtools-panel {
position: fixed; top: 20px; right: 20px;
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
border: 1px solid #404040; border-radius: 8px;
padding: 16px; min-width: 280px;
box-shadow: 0 8px 32px rgba(0,0,0,0.8);
backdrop-filter: blur(10px);
}
.panel-title { color: #fff; font-size: 14px; font-weight: 600; margin: 0 0 12px 0; }
.control-group { display: flex; gap: 8px; margin-bottom: 12px; }
.btn {
padding: 8px 16px; border: none; border-radius: 4px;
font-size: 12px; font-weight: 500; cursor: pointer;
transition: all 0.2s ease; flex: 1;
}
.btn-toggle { background: #0ea5e9; color: white; }
.btn-toggle:hover { background: #0284c7; transform: translateY(-1px); }
.btn-enable { background: #10b981; color: white; }
.btn-enable:hover { background: #059669; transform: translateY(-1px); }
.btn-disable { background: #ef4444; color: white; }
.btn-disable:hover { background: #dc2626; transform: translateY(-1px); }
.status-row {
display: flex; align-items: center; justify-content: space-between;
padding: 8px 12px; background: rgba(255,255,255,0.05);
border-radius: 4px; border-left: 3px solid #0ea5e9;
}
.status-label { color: #a1a1aa; font-size: 12px; }
.status-value { font-weight: 600; font-size: 12px; }
.status-enabled { color: #10b981; }
.status-disabled { color: #ef4444; }
</style>
</head>
<body>
<div id="devtools-panel">
<div class="panel-title">Three.js DevTools</div>
<div class="control-group">
<button class="btn btn-toggle" onclick="toggleDevTools()">Toggle</button>
<button class="btn btn-enable" onclick="enableDevTools()">Enable</button>
<button class="btn btn-disable" onclick="disableDevTools()">Disable</button>
</div>
<div class="status-row">
<span class="status-label">Status</span>
<span id="statusText" class="status-value">Loading...</span>
</div>
</div>

<script type="module">
import * as THREE from './build/three.module.js';

// Create a simple scene
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);

camera.position.z = 5;

function animate() {
requestAnimationFrame(animate);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();

// DevTools control functions
window.toggleDevTools = function() {
const newState = THREE.DevTools.toggle();
updateStatus();
console.log('DevTools toggled to:', newState);
};

window.enableDevTools = function() {
THREE.DevTools.setEnabled(true);
updateStatus();
console.log('DevTools enabled');
};

window.disableDevTools = function() {
THREE.DevTools.setEnabled(false);
updateStatus();
console.log('DevTools disabled');
};

function updateStatus() {
const statusText = document.getElementById('statusText');
const isEnabled = THREE.DevTools.enabled;
statusText.textContent = isEnabled ? 'ENABLED' : 'DISABLED';
statusText.className = `status-value ${isEnabled ? 'status-enabled' : 'status-disabled'}`;
}

// Initial status update
updateStatus();
</script>
</body>
</html>
8 changes: 1 addition & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Three.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { UniformsUtils } from './renderers/shaders/UniformsUtils.js';
export { ShaderChunk } from './renderers/shaders/ShaderChunk.js';
export { PMREMGenerator } from './extras/PMREMGenerator.js';
export { WebGLUtils } from './renderers/webgl/WebGLUtils.js';
export { DevTools } from './devtools/DevTools.js';
39 changes: 39 additions & 0 deletions src/devtools/DevTools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const DevTools = {

enabled: true,

setEnabled( value ) {

this.enabled = Boolean( value );

if ( typeof localStorage !== 'undefined' ) {

localStorage.setItem( 'three-devtools-enabled', this.enabled );

}

},

toggle() {

this.setEnabled( ! this.enabled );
return this.enabled;

}

};

// Load saved preference
if ( typeof localStorage !== 'undefined' ) {

const saved = localStorage.getItem( 'three-devtools-enabled' );

if ( saved !== null ) {

DevTools.enabled = saved === 'true';

}

}

export { DevTools };
7 changes: 5 additions & 2 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ColorManagement } from '../../math/ColorManagement.js';
import { Vector3 } from '../../math/Vector3.js';
import { Matrix3 } from '../../math/Matrix3.js';
import { warn, error } from '../../utils.js';
import { DevTools } from '../../devtools/DevTools.js';

// From https://www.khronos.org/registry/webgl/extensions/KHR_parallel_shader_compile/
const COMPLETION_STATUS_KHR = 0x91B1;
Expand Down Expand Up @@ -475,8 +476,10 @@ function generateCubeUVSize( parameters ) {

function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {

// TODO Send this event to Three.js DevTools
// log( 'WebGLProgram', cacheKey );
// Send this event to Three.js DevTools
if ( DevTools.enabled ) {
// log( 'WebGLProgram', cacheKey );
}

const gl = renderer.getContext();

Expand Down