From 93b6a6f4cef6c3e7f196ea68f2df387c484dba01 Mon Sep 17 00:00:00 2001 From: work <840004959@qq.com> Date: Thu, 22 Jan 2026 02:22:05 +0800 Subject: [PATCH] fix(multi-client): Prevent duplicate lights when multiple clients connect (#250) * fix(multi-client): Prevent duplicate lights when multiple clients connect --- gz3d/src/gzscene.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gz3d/src/gzscene.js b/gz3d/src/gzscene.js index a0ca5dff..b22d0fa8 100644 --- a/gz3d/src/gzscene.js +++ b/gz3d/src/gzscene.js @@ -332,15 +332,16 @@ GZ3D.Scene.prototype.init = function() }; GZ3D.Scene.prototype.initScene = function() -{ +{ this.emitter.emit('show_grid', 'show'); - - // create a sun light - var obj = this.createLight(3, new THREE.Color(0.8, 0.8, 0.8), 0.9, - {position: {x:0, y:0, z:10}, orientation: {x:0, y:0, z:0, w:1}}, - null, true, 'sun', {x: 0.5, y: 0.1, z: -0.9}); - - this.add(obj); + var existingSun = this.getByName('sun'); + if (!existingSun) { + // create a sun light + var obj = this.createLight(3, new THREE.Color(0.8, 0.8, 0.8), 0.9, + {position: {x:0, y:0, z:10}, orientation: {x:0, y:0, z:0, w:1}}, + null, true, 'sun', {x: 0.5, y: 0.1, z: -0.9}); + this.add(obj); + } }; GZ3D.Scene.prototype.setSDFParser = function(sdfParser)