@anov/3d 0.0.4-alpha.1 → 0.0.4-alpha13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -144
- package/dist/applicationApi.d.ts +34 -0
- package/dist/{core/cssRenderer.js → applicationApi.js} +53 -21
- package/dist/environment/index.d.ts +27 -0
- package/dist/environment/index.js +84 -0
- package/dist/environment/time/index.d.ts +12 -0
- package/dist/environment/time/index.js +27 -0
- package/dist/environment/weather/type.d.ts +15 -0
- package/dist/environment/weather/type.js +27 -0
- package/dist/hooksManager.d.ts +2 -0
- package/dist/hooksManager.js +15 -0
- package/dist/index.d.ts +15 -3
- package/dist/index.js +38 -5
- package/dist/messageStatus.d.ts +49 -0
- package/dist/messageStatus.js +50 -0
- package/dist/utils/index.d.ts +11 -50
- package/dist/utils/index.js +29 -92
- package/dist/utils/messageFn.d.ts +12 -0
- package/dist/utils/messageFn.js +33 -0
- package/package.json +8 -24
- package/dist/commonEnu.d.ts +0 -5
- package/dist/commonEnu.js +0 -6
- package/dist/core/camera.d.ts +0 -32
- package/dist/core/camera.js +0 -74
- package/dist/core/control/transformControls.d.ts +0 -12
- package/dist/core/control/transformControls.js +0 -72
- package/dist/core/cssRenderer.d.ts +0 -17
- package/dist/core/events.d.ts +0 -16
- package/dist/core/events.js +0 -38
- package/dist/core/global/global.d.ts +0 -27
- package/dist/core/global/global.js +0 -72
- package/dist/core/global/globalControl.d.ts +0 -17
- package/dist/core/global/globalControl.js +0 -62
- package/dist/core/group.d.ts +0 -57
- package/dist/core/group.js +0 -157
- package/dist/core/line.d.ts +0 -13
- package/dist/core/line.js +0 -83
- package/dist/core/mesh.d.ts +0 -59
- package/dist/core/mesh.js +0 -180
- package/dist/core/model.d.ts +0 -30
- package/dist/core/model.js +0 -109
- package/dist/core/scene.d.ts +0 -175
- package/dist/core/scene.js +0 -381
- package/dist/core/use/useScene.d.ts +0 -10
- package/dist/core/use/useScene.js +0 -14
- package/dist/core/use/useframe.d.ts +0 -6
- package/dist/core/use/useframe.js +0 -11
- package/dist/export.d.ts +0 -40
- package/dist/export.js +0 -36
- package/dist/threeCell.d.ts +0 -8
- package/dist/threeCell.js +0 -16
- package/dist/type.d.ts +0 -3
- package/dist/type.js +0 -1
- package/dist/utils/createElement.d.ts +0 -103
- package/dist/utils/createElement.js +0 -145
- package/dist/utils/createLabel.d.ts +0 -2
- package/dist/utils/createLabel.js +0 -4
- package/dist/utils/line.d.ts +0 -0
- package/dist/utils/line.js +0 -0
- package/dist/utils/move.d.ts +0 -48
- package/dist/utils/move.js +0 -149
- package/examples/fonts/LICENSE +0 -13
- package/examples/fonts/README.md +0 -11
- package/examples/fonts/droid/NOTICE +0 -190
- package/examples/fonts/droid/README.txt +0 -18
- package/examples/fonts/droid/droid_sans_bold.typeface.json +0 -1
- package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +0 -1
- package/examples/fonts/droid/droid_sans_regular.typeface.json +0 -1
- package/examples/fonts/droid/droid_serif_bold.typeface.json +0 -1
- package/examples/fonts/droid/droid_serif_regular.typeface.json +0 -1
- package/examples/fonts/gentilis_bold.typeface.json +0 -1
- package/examples/fonts/gentilis_regular.typeface.json +0 -1
- package/examples/fonts/helvetiker_bold.typeface.json +0 -1
- package/examples/fonts/helvetiker_regular.typeface.json +0 -1
- package/examples/fonts/optimer_bold.typeface.json +0 -1
- package/examples/fonts/optimer_regular.typeface.json +0 -1
- package/examples/fonts/ttf/README.md +0 -9
- package/examples/fonts/ttf/kenpixel.ttf +0 -0
- package/examples/jsm/animation/AnimationClipCreator.js +0 -116
- package/examples/jsm/animation/CCDIKSolver.js +0 -482
- package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
- package/examples/jsm/animation/MMDPhysics.js +0 -1406
- package/examples/jsm/cameras/CinematicCamera.js +0 -208
- package/examples/jsm/capabilities/WebGL.js +0 -91
- package/examples/jsm/capabilities/WebGPU.js +0 -53
- package/examples/jsm/controls/ArcballControls.js +0 -3224
- package/examples/jsm/controls/DragControls.js +0 -220
- package/examples/jsm/controls/FirstPersonControls.js +0 -325
- package/examples/jsm/controls/FlyControls.js +0 -300
- package/examples/jsm/controls/MapControls.js +0 -28
- package/examples/jsm/controls/OrbitControls.js +0 -1388
- package/examples/jsm/controls/PointerLockControls.js +0 -162
- package/examples/jsm/controls/TrackballControls.js +0 -828
- package/examples/jsm/controls/TransformControls.js +0 -1557
- package/examples/jsm/csm/CSM.js +0 -384
- package/examples/jsm/csm/CSMFrustum.js +0 -152
- package/examples/jsm/csm/CSMHelper.js +0 -193
- package/examples/jsm/csm/CSMShader.js +0 -252
- package/examples/jsm/curves/CurveExtras.js +0 -422
- package/examples/jsm/curves/NURBSCurve.js +0 -80
- package/examples/jsm/curves/NURBSSurface.js +0 -52
- package/examples/jsm/curves/NURBSUtils.js +0 -487
- package/examples/jsm/effects/AnaglyphEffect.js +0 -154
- package/examples/jsm/effects/AsciiEffect.js +0 -263
- package/examples/jsm/effects/OutlineEffect.js +0 -539
- package/examples/jsm/effects/ParallaxBarrierEffect.js +0 -119
- package/examples/jsm/effects/PeppersGhostEffect.js +0 -153
- package/examples/jsm/effects/StereoEffect.js +0 -55
- package/examples/jsm/environments/DebugEnvironment.js +0 -52
- package/examples/jsm/environments/RoomEnvironment.js +0 -148
- package/examples/jsm/exporters/DRACOExporter.js +0 -267
- package/examples/jsm/exporters/EXRExporter.js +0 -501
- package/examples/jsm/exporters/GLTFExporter.js +0 -3161
- package/examples/jsm/exporters/KTX2Exporter.js +0 -292
- package/examples/jsm/exporters/MMDExporter.js +0 -217
- package/examples/jsm/exporters/OBJExporter.js +0 -284
- package/examples/jsm/exporters/PLYExporter.js +0 -528
- package/examples/jsm/exporters/STLExporter.js +0 -199
- package/examples/jsm/exporters/USDZExporter.js +0 -711
- package/examples/jsm/geometries/BoxLineGeometry.js +0 -69
- package/examples/jsm/geometries/ConvexGeometry.js +0 -53
- package/examples/jsm/geometries/DecalGeometry.js +0 -356
- package/examples/jsm/geometries/ParametricGeometries.js +0 -254
- package/examples/jsm/geometries/ParametricGeometry.js +0 -139
- package/examples/jsm/geometries/RoundedBoxGeometry.js +0 -155
- package/examples/jsm/geometries/TeapotGeometry.js +0 -704
- package/examples/jsm/geometries/TextGeometry.js +0 -57
- package/examples/jsm/helpers/LightProbeHelper.js +0 -130
- package/examples/jsm/helpers/OctreeHelper.js +0 -73
- package/examples/jsm/helpers/PositionalAudioHelper.js +0 -109
- package/examples/jsm/helpers/RectAreaLightHelper.js +0 -85
- package/examples/jsm/helpers/VertexNormalsHelper.js +0 -96
- package/examples/jsm/helpers/VertexTangentsHelper.js +0 -88
- package/examples/jsm/helpers/ViewHelper.js +0 -333
- package/examples/jsm/interactive/HTMLMesh.js +0 -565
- package/examples/jsm/interactive/InteractiveGroup.js +0 -116
- package/examples/jsm/interactive/SelectionBox.js +0 -227
- package/examples/jsm/interactive/SelectionHelper.js +0 -104
- package/examples/jsm/libs/ammo.wasm.js +0 -822
- package/examples/jsm/libs/ammo.wasm.wasm +0 -0
- package/examples/jsm/libs/basis/README.md +0 -46
- package/examples/jsm/libs/basis/basis_transcoder.js +0 -21
- package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
- package/examples/jsm/libs/chevrotain.module.min.js +0 -141
- package/examples/jsm/libs/draco/README.md +0 -32
- package/examples/jsm/libs/draco/draco_decoder.js +0 -34
- package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
- package/examples/jsm/libs/draco/draco_encoder.js +0 -33
- package/examples/jsm/libs/draco/draco_wasm_wrapper.js +0 -117
- package/examples/jsm/libs/draco/gltf/draco_decoder.js +0 -33
- package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
- package/examples/jsm/libs/draco/gltf/draco_encoder.js +0 -33
- package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +0 -116
- package/examples/jsm/libs/ecsy.module.js +0 -1792
- package/examples/jsm/libs/fflate.module.js +0 -2474
- package/examples/jsm/libs/ktx-parse.module.js +0 -1
- package/examples/jsm/libs/lil-gui.module.min.js +0 -8
- package/examples/jsm/libs/lottie_canvas.module.js +0 -14844
- package/examples/jsm/libs/meshopt_decoder.module.js +0 -178
- package/examples/jsm/libs/mikktspace.module.js +0 -128
- package/examples/jsm/libs/mmdparser.module.js +0 -11530
- package/examples/jsm/libs/motion-controllers.module.js +0 -397
- package/examples/jsm/libs/opentype.module.js +0 -14568
- package/examples/jsm/libs/potpack.module.js +0 -125
- package/examples/jsm/libs/rhino3dm/rhino3dm.js +0 -21
- package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +0 -16
- package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
- package/examples/jsm/libs/stats.module.js +0 -167
- package/examples/jsm/libs/tween.module.js +0 -803
- package/examples/jsm/libs/utif.module.js +0 -1579
- package/examples/jsm/libs/zstddec.module.js +0 -1
- package/examples/jsm/lights/IESSpotLight.js +0 -25
- package/examples/jsm/lights/LightProbeGenerator.js +0 -252
- package/examples/jsm/lights/RectAreaLightUniformsLib.js +0 -79
- package/examples/jsm/lines/Line2.js +0 -19
- package/examples/jsm/lines/LineGeometry.js +0 -79
- package/examples/jsm/lines/LineMaterial.js +0 -702
- package/examples/jsm/lines/LineSegments2.js +0 -361
- package/examples/jsm/lines/LineSegmentsGeometry.js +0 -241
- package/examples/jsm/lines/Wireframe.js +0 -56
- package/examples/jsm/lines/WireframeGeometry2.js +0 -24
- package/examples/jsm/loaders/3DMLoader.js +0 -1497
- package/examples/jsm/loaders/3MFLoader.js +0 -1478
- package/examples/jsm/loaders/AMFLoader.js +0 -521
- package/examples/jsm/loaders/BVHLoader.js +0 -437
- package/examples/jsm/loaders/ColladaLoader.js +0 -4122
- package/examples/jsm/loaders/DDSLoader.js +0 -274
- package/examples/jsm/loaders/DRACOLoader.js +0 -612
- package/examples/jsm/loaders/EXRLoader.js +0 -2309
- package/examples/jsm/loaders/FBXLoader.js +0 -4142
- package/examples/jsm/loaders/FontLoader.js +0 -183
- package/examples/jsm/loaders/GCodeLoader.js +0 -261
- package/examples/jsm/loaders/GLTFLoader.js +0 -4576
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +0 -115
- package/examples/jsm/loaders/IESLoader.js +0 -337
- package/examples/jsm/loaders/KMZLoader.js +0 -130
- package/examples/jsm/loaders/KTX2Loader.js +0 -868
- package/examples/jsm/loaders/KTXLoader.js +0 -176
- package/examples/jsm/loaders/LDrawLoader.js +0 -2464
- package/examples/jsm/loaders/LUT3dlLoader.js +0 -151
- package/examples/jsm/loaders/LUTCubeLoader.js +0 -153
- package/examples/jsm/loaders/LWOLoader.js +0 -1052
- package/examples/jsm/loaders/LogLuvLoader.js +0 -606
- package/examples/jsm/loaders/LottieLoader.js +0 -77
- package/examples/jsm/loaders/MD2Loader.js +0 -399
- package/examples/jsm/loaders/MDDLoader.js +0 -102
- package/examples/jsm/loaders/MMDLoader.js +0 -2273
- package/examples/jsm/loaders/MTLLoader.js +0 -567
- package/examples/jsm/loaders/MaterialXLoader.js +0 -734
- package/examples/jsm/loaders/NRRDLoader.js +0 -699
- package/examples/jsm/loaders/OBJLoader.js +0 -905
- package/examples/jsm/loaders/PCDLoader.js +0 -467
- package/examples/jsm/loaders/PDBLoader.js +0 -232
- package/examples/jsm/loaders/PLYLoader.js +0 -771
- package/examples/jsm/loaders/PVRLoader.js +0 -251
- package/examples/jsm/loaders/RGBELoader.js +0 -468
- package/examples/jsm/loaders/RGBMLoader.js +0 -1065
- package/examples/jsm/loaders/STLLoader.js +0 -403
- package/examples/jsm/loaders/SVGLoader.js +0 -3172
- package/examples/jsm/loaders/TDSLoader.js +0 -1124
- package/examples/jsm/loaders/TGALoader.js +0 -517
- package/examples/jsm/loaders/TIFFLoader.js +0 -36
- package/examples/jsm/loaders/TTFLoader.js +0 -214
- package/examples/jsm/loaders/TiltLoader.js +0 -520
- package/examples/jsm/loaders/USDZLoader.js +0 -633
- package/examples/jsm/loaders/VOXLoader.js +0 -311
- package/examples/jsm/loaders/VRMLLoader.js +0 -3533
- package/examples/jsm/loaders/VTKLoader.js +0 -1163
- package/examples/jsm/loaders/XYZLoader.js +0 -106
- package/examples/jsm/loaders/lwo/IFFParser.js +0 -1218
- package/examples/jsm/loaders/lwo/LWO2Parser.js +0 -414
- package/examples/jsm/loaders/lwo/LWO3Parser.js +0 -373
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -420
- package/examples/jsm/math/Capsule.js +0 -137
- package/examples/jsm/math/ColorConverter.js +0 -36
- package/examples/jsm/math/ConvexHull.js +0 -1271
- package/examples/jsm/math/ImprovedNoise.js +0 -71
- package/examples/jsm/math/Lut.js +0 -204
- package/examples/jsm/math/MeshSurfaceSampler.js +0 -250
- package/examples/jsm/math/OBB.js +0 -423
- package/examples/jsm/math/Octree.js +0 -462
- package/examples/jsm/math/SimplexNoise.js +0 -444
- package/examples/jsm/misc/ConvexObjectBreaker.js +0 -519
- package/examples/jsm/misc/GPUComputationRenderer.js +0 -446
- package/examples/jsm/misc/Gyroscope.js +0 -66
- package/examples/jsm/misc/MD2Character.js +0 -276
- package/examples/jsm/misc/MD2CharacterComplex.js +0 -576
- package/examples/jsm/misc/MorphAnimMesh.js +0 -75
- package/examples/jsm/misc/MorphBlendMesh.js +0 -322
- package/examples/jsm/misc/ProgressiveLightMap.js +0 -323
- package/examples/jsm/misc/RollerCoaster.js +0 -566
- package/examples/jsm/misc/TubePainter.js +0 -205
- package/examples/jsm/misc/Volume.js +0 -473
- package/examples/jsm/misc/VolumeSlice.js +0 -229
- package/examples/jsm/modifiers/CurveModifier.js +0 -326
- package/examples/jsm/modifiers/EdgeSplitModifier.js +0 -279
- package/examples/jsm/modifiers/SimplifyModifier.js +0 -525
- package/examples/jsm/modifiers/TessellateModifier.js +0 -307
- package/examples/jsm/nodes/Nodes.js +0 -171
- package/examples/jsm/nodes/accessors/BitangentNode.js +0 -89
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +0 -99
- package/examples/jsm/nodes/accessors/BufferNode.js +0 -30
- package/examples/jsm/nodes/accessors/CameraNode.js +0 -98
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +0 -103
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +0 -77
- package/examples/jsm/nodes/accessors/InstanceNode.js +0 -71
- package/examples/jsm/nodes/accessors/MaterialNode.js +0 -267
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +0 -39
- package/examples/jsm/nodes/accessors/ModelNode.js +0 -34
- package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +0 -29
- package/examples/jsm/nodes/accessors/MorphNode.js +0 -70
- package/examples/jsm/nodes/accessors/NormalNode.js +0 -96
- package/examples/jsm/nodes/accessors/Object3DNode.js +0 -150
- package/examples/jsm/nodes/accessors/PointUVNode.js +0 -26
- package/examples/jsm/nodes/accessors/PositionNode.js +0 -104
- package/examples/jsm/nodes/accessors/ReferenceNode.js +0 -72
- package/examples/jsm/nodes/accessors/ReflectVectorNode.js +0 -35
- package/examples/jsm/nodes/accessors/SceneNode.js +0 -52
- package/examples/jsm/nodes/accessors/SkinningNode.js +0 -93
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +0 -27
- package/examples/jsm/nodes/accessors/TangentNode.js +0 -103
- package/examples/jsm/nodes/accessors/TextureBicubicNode.js +0 -94
- package/examples/jsm/nodes/accessors/TextureNode.js +0 -271
- package/examples/jsm/nodes/accessors/TextureSizeNode.js +0 -35
- package/examples/jsm/nodes/accessors/UVNode.js +0 -47
- package/examples/jsm/nodes/accessors/UserDataNode.js +0 -29
- package/examples/jsm/nodes/code/CodeNode.js +0 -78
- package/examples/jsm/nodes/code/ExpressionNode.js +0 -37
- package/examples/jsm/nodes/code/FunctionCallNode.js +0 -96
- package/examples/jsm/nodes/code/FunctionNode.js +0 -127
- package/examples/jsm/nodes/code/ScriptableNode.js +0 -488
- package/examples/jsm/nodes/code/ScriptableValueNode.js +0 -167
- package/examples/jsm/nodes/core/ArrayUniformNode.js +0 -26
- package/examples/jsm/nodes/core/AttributeNode.js +0 -102
- package/examples/jsm/nodes/core/BypassNode.js +0 -45
- package/examples/jsm/nodes/core/CacheNode.js +0 -46
- package/examples/jsm/nodes/core/ConstNode.js +0 -32
- package/examples/jsm/nodes/core/ContextNode.js +0 -61
- package/examples/jsm/nodes/core/IndexNode.js +0 -66
- package/examples/jsm/nodes/core/InputNode.js +0 -83
- package/examples/jsm/nodes/core/LightingModel.js +0 -15
- package/examples/jsm/nodes/core/Node.js +0 -454
- package/examples/jsm/nodes/core/NodeAttribute.js +0 -15
- package/examples/jsm/nodes/core/NodeBuilder.js +0 -1016
- package/examples/jsm/nodes/core/NodeCache.js +0 -26
- package/examples/jsm/nodes/core/NodeCode.js +0 -15
- package/examples/jsm/nodes/core/NodeFrame.js +0 -110
- package/examples/jsm/nodes/core/NodeFunction.js +0 -22
- package/examples/jsm/nodes/core/NodeFunctionInput.js +0 -17
- package/examples/jsm/nodes/core/NodeKeywords.js +0 -80
- package/examples/jsm/nodes/core/NodeParser.js +0 -11
- package/examples/jsm/nodes/core/NodeUniform.js +0 -28
- package/examples/jsm/nodes/core/NodeUtils.js +0 -212
- package/examples/jsm/nodes/core/NodeVar.js +0 -14
- package/examples/jsm/nodes/core/NodeVarying.js +0 -17
- package/examples/jsm/nodes/core/PropertyNode.js +0 -61
- package/examples/jsm/nodes/core/StackNode.js +0 -99
- package/examples/jsm/nodes/core/TempNode.js +0 -58
- package/examples/jsm/nodes/core/UniformNode.js +0 -61
- package/examples/jsm/nodes/core/VarNode.js +0 -87
- package/examples/jsm/nodes/core/VaryingNode.js +0 -69
- package/examples/jsm/nodes/core/constants.js +0 -27
- package/examples/jsm/nodes/display/BlendModeNode.js +0 -99
- package/examples/jsm/nodes/display/BumpMapNode.js +0 -77
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +0 -100
- package/examples/jsm/nodes/display/ColorSpaceNode.js +0 -108
- package/examples/jsm/nodes/display/FrontFacingNode.js +0 -27
- package/examples/jsm/nodes/display/NormalMapNode.js +0 -106
- package/examples/jsm/nodes/display/PosterizeNode.js +0 -32
- package/examples/jsm/nodes/display/ToneMappingNode.js +0 -141
- package/examples/jsm/nodes/display/ViewportDepthNode.js +0 -69
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +0 -34
- package/examples/jsm/nodes/display/ViewportNode.js +0 -115
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +0 -31
- package/examples/jsm/nodes/display/ViewportTextureNode.js +0 -75
- package/examples/jsm/nodes/fog/FogExp2Node.js +0 -35
- package/examples/jsm/nodes/fog/FogNode.js +0 -37
- package/examples/jsm/nodes/fog/FogRangeNode.js +0 -34
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +0 -40
- package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +0 -9
- package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +0 -43
- package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +0 -29
- package/examples/jsm/nodes/functions/BSDF/D_GGX.js +0 -18
- package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +0 -13
- package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +0 -16
- package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +0 -13
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +0 -20
- package/examples/jsm/nodes/functions/PhongLightingModel.js +0 -67
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +0 -343
- package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +0 -13
- package/examples/jsm/nodes/functions/material/getRoughness.js +0 -18
- package/examples/jsm/nodes/geometry/RangeNode.js +0 -104
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +0 -85
- package/examples/jsm/nodes/lighting/AONode.js +0 -27
- package/examples/jsm/nodes/lighting/AmbientLightNode.js +0 -27
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +0 -184
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +0 -40
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +0 -191
- package/examples/jsm/nodes/lighting/HemisphereLightNode.js +0 -55
- package/examples/jsm/nodes/lighting/IESSpotLightNode.js +0 -39
- package/examples/jsm/nodes/lighting/LightNode.js +0 -57
- package/examples/jsm/nodes/lighting/LightUtils.js +0 -17
- package/examples/jsm/nodes/lighting/LightingContextNode.js +0 -102
- package/examples/jsm/nodes/lighting/LightingNode.js +0 -21
- package/examples/jsm/nodes/lighting/LightsNode.js +0 -128
- package/examples/jsm/nodes/lighting/PointLightNode.js +0 -68
- package/examples/jsm/nodes/lighting/SpotLightNode.js +0 -89
- package/examples/jsm/nodes/loaders/NodeLoader.js +0 -108
- package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +0 -59
- package/examples/jsm/nodes/loaders/NodeObjectLoader.js +0 -70
- package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +0 -28
- package/examples/jsm/nodes/materials/Materials.js +0 -12
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +0 -27
- package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +0 -34
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -40
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +0 -65
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +0 -128
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +0 -80
- package/examples/jsm/nodes/materials/NodeMaterial.js +0 -536
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -49
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -103
- package/examples/jsm/nodes/materialx/DISCLAIMER.md +0 -199
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +0 -68
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +0 -56
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +0 -618
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +0 -19
- package/examples/jsm/nodes/math/CondNode.js +0 -86
- package/examples/jsm/nodes/math/MathNode.js +0 -359
- package/examples/jsm/nodes/math/OperatorNode.js +0 -269
- package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +0 -152
- package/examples/jsm/nodes/parsers/GLSLNodeParser.js +0 -14
- package/examples/jsm/nodes/procedural/CheckerNode.js +0 -42
- package/examples/jsm/nodes/shadernode/ShaderNode.js +0 -420
- package/examples/jsm/nodes/utils/ArrayElementNode.js +0 -33
- package/examples/jsm/nodes/utils/ConvertNode.js +0 -65
- package/examples/jsm/nodes/utils/DiscardNode.js +0 -26
- package/examples/jsm/nodes/utils/EquirectUVNode.js +0 -33
- package/examples/jsm/nodes/utils/JoinNode.js +0 -51
- package/examples/jsm/nodes/utils/LoopNode.js +0 -186
- package/examples/jsm/nodes/utils/MatcapUVNode.js +0 -30
- package/examples/jsm/nodes/utils/MaxMipLevelNode.js +0 -46
- package/examples/jsm/nodes/utils/OscNode.js +0 -81
- package/examples/jsm/nodes/utils/PackingNode.js +0 -55
- package/examples/jsm/nodes/utils/RemapNode.js +0 -42
- package/examples/jsm/nodes/utils/RotateUVNode.js +0 -43
- package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -37
- package/examples/jsm/nodes/utils/SplitNode.js +0 -104
- package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +0 -41
- package/examples/jsm/nodes/utils/TimerNode.js +0 -94
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +0 -62
- package/examples/jsm/objects/GroundProjectedSkybox.js +0 -172
- package/examples/jsm/objects/Lensflare.js +0 -377
- package/examples/jsm/objects/MarchingCubes.js +0 -1176
- package/examples/jsm/objects/Reflector.js +0 -264
- package/examples/jsm/objects/ReflectorForSSRPass.js +0 -349
- package/examples/jsm/objects/Refractor.js +0 -324
- package/examples/jsm/objects/ShadowMesh.js +0 -80
- package/examples/jsm/objects/Sky.js +0 -219
- package/examples/jsm/objects/Water.js +0 -330
- package/examples/jsm/objects/Water2.js +0 -358
- package/examples/jsm/offscreen/jank.js +0 -45
- package/examples/jsm/offscreen/offscreen.js +0 -8
- package/examples/jsm/offscreen/scene.js +0 -86
- package/examples/jsm/physics/AmmoPhysics.js +0 -285
- package/examples/jsm/physics/RapierPhysics.js +0 -199
- package/examples/jsm/postprocessing/AfterimagePass.js +0 -104
- package/examples/jsm/postprocessing/BloomPass.js +0 -172
- package/examples/jsm/postprocessing/BokehPass.js +0 -140
- package/examples/jsm/postprocessing/ClearPass.js +0 -46
- package/examples/jsm/postprocessing/CubeTexturePass.js +0 -85
- package/examples/jsm/postprocessing/DotScreenPass.js +0 -65
- package/examples/jsm/postprocessing/EffectComposer.js +0 -231
- package/examples/jsm/postprocessing/FilmPass.js +0 -66
- package/examples/jsm/postprocessing/GlitchPass.js +0 -128
- package/examples/jsm/postprocessing/HalftonePass.js +0 -79
- package/examples/jsm/postprocessing/LUTPass.js +0 -173
- package/examples/jsm/postprocessing/MaskPass.js +0 -104
- package/examples/jsm/postprocessing/OutlinePass.js +0 -654
- package/examples/jsm/postprocessing/OutputPass.js +0 -91
- package/examples/jsm/postprocessing/Pass.js +0 -84
- package/examples/jsm/postprocessing/RenderPass.js +0 -81
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +0 -235
- package/examples/jsm/postprocessing/SAOPass.js +0 -411
- package/examples/jsm/postprocessing/SMAAPass.js +0 -201
- package/examples/jsm/postprocessing/SSAARenderPass.js +0 -228
- package/examples/jsm/postprocessing/SSAOPass.js +0 -440
- package/examples/jsm/postprocessing/SSRPass.js +0 -641
- package/examples/jsm/postprocessing/SavePass.js +0 -79
- package/examples/jsm/postprocessing/ShaderPass.js +0 -77
- package/examples/jsm/postprocessing/TAARenderPass.js +0 -189
- package/examples/jsm/postprocessing/TexturePass.js +0 -67
- package/examples/jsm/postprocessing/UnrealBloomPass.js +0 -415
- package/examples/jsm/renderers/CSS2DRenderer.js +0 -215
- package/examples/jsm/renderers/CSS3DRenderer.js +0 -335
- package/examples/jsm/renderers/Projector.js +0 -918
- package/examples/jsm/renderers/SVGRenderer.js +0 -553
- package/examples/jsm/renderers/common/Animation.js +0 -58
- package/examples/jsm/renderers/common/Attributes.js +0 -75
- package/examples/jsm/renderers/common/Backend.js +0 -162
- package/examples/jsm/renderers/common/Background.js +0 -136
- package/examples/jsm/renderers/common/Binding.js +0 -19
- package/examples/jsm/renderers/common/Bindings.js +0 -165
- package/examples/jsm/renderers/common/Buffer.js +0 -38
- package/examples/jsm/renderers/common/BufferUtils.js +0 -33
- package/examples/jsm/renderers/common/ChainMap.js +0 -89
- package/examples/jsm/renderers/common/ComputePipeline.js +0 -17
- package/examples/jsm/renderers/common/Constants.js +0 -14
- package/examples/jsm/renderers/common/CubeRenderTarget.js +0 -65
- package/examples/jsm/renderers/common/DataMap.js +0 -54
- package/examples/jsm/renderers/common/Geometries.js +0 -215
- package/examples/jsm/renderers/common/Info.js +0 -73
- package/examples/jsm/renderers/common/Pipeline.js +0 -13
- package/examples/jsm/renderers/common/Pipelines.js +0 -370
- package/examples/jsm/renderers/common/ProgrammableStage.js +0 -18
- package/examples/jsm/renderers/common/RenderContext.js +0 -38
- package/examples/jsm/renderers/common/RenderContexts.js +0 -49
- package/examples/jsm/renderers/common/RenderList.js +0 -178
- package/examples/jsm/renderers/common/RenderLists.js +0 -38
- package/examples/jsm/renderers/common/RenderObject.js +0 -129
- package/examples/jsm/renderers/common/RenderObjects.js +0 -95
- package/examples/jsm/renderers/common/RenderPipeline.js +0 -16
- package/examples/jsm/renderers/common/Renderer.js +0 -895
- package/examples/jsm/renderers/common/SampledTexture.js +0 -80
- package/examples/jsm/renderers/common/Sampler.js +0 -18
- package/examples/jsm/renderers/common/StorageBuffer.js +0 -17
- package/examples/jsm/renderers/common/Textures.js +0 -218
- package/examples/jsm/renderers/common/Uniform.js +0 -140
- package/examples/jsm/renderers/common/UniformBuffer.js +0 -15
- package/examples/jsm/renderers/common/UniformsGroup.js +0 -299
- package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +0 -39
- package/examples/jsm/renderers/common/nodes/NodeSampler.js +0 -21
- package/examples/jsm/renderers/common/nodes/NodeUniform.js +0 -135
- package/examples/jsm/renderers/common/nodes/Nodes.js +0 -330
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +0 -340
- package/examples/jsm/renderers/webgl/nodes/SlotNode.js +0 -26
- package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +0 -764
- package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +0 -49
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +0 -844
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +0 -32
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +0 -902
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +0 -104
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeParser.js +0 -14
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +0 -274
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +0 -223
- package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +0 -324
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +0 -533
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureMipmapUtils.js +0 -163
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +0 -964
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +0 -92
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +0 -87
- package/examples/jsm/shaders/AfterimageShader.js +0 -56
- package/examples/jsm/shaders/BasicShader.js +0 -27
- package/examples/jsm/shaders/BleachBypassShader.js +0 -62
- package/examples/jsm/shaders/BlendShader.js +0 -47
- package/examples/jsm/shaders/BokehShader.js +0 -143
- package/examples/jsm/shaders/BokehShader2.js +0 -393
- package/examples/jsm/shaders/BrightnessContrastShader.js +0 -54
- package/examples/jsm/shaders/ColorCorrectionShader.js +0 -50
- package/examples/jsm/shaders/ColorifyShader.js +0 -51
- package/examples/jsm/shaders/ConvolutionShader.js +0 -103
- package/examples/jsm/shaders/CopyShader.js +0 -45
- package/examples/jsm/shaders/DOFMipMapShader.js +0 -54
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +0 -166
- package/examples/jsm/shaders/DigitalGlitch.js +0 -101
- package/examples/jsm/shaders/DotScreenShader.js +0 -70
- package/examples/jsm/shaders/ExposureShader.js +0 -44
- package/examples/jsm/shaders/FXAAShader.js +0 -286
- package/examples/jsm/shaders/FilmShader.js +0 -102
- package/examples/jsm/shaders/FocusShader.js +0 -87
- package/examples/jsm/shaders/FreiChenShader.js +0 -94
- package/examples/jsm/shaders/GammaCorrectionShader.js +0 -43
- package/examples/jsm/shaders/GodRaysShader.js +0 -313
- package/examples/jsm/shaders/HalftoneShader.js +0 -310
- package/examples/jsm/shaders/HorizontalBlurShader.js +0 -59
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +0 -61
- package/examples/jsm/shaders/HueSaturationShader.js +0 -65
- package/examples/jsm/shaders/KaleidoShader.js +0 -56
- package/examples/jsm/shaders/LuminosityHighPassShader.js +0 -64
- package/examples/jsm/shaders/LuminosityShader.js +0 -46
- package/examples/jsm/shaders/MMDToonShader.js +0 -132
- package/examples/jsm/shaders/MirrorShader.js +0 -54
- package/examples/jsm/shaders/NormalMapShader.js +0 -53
- package/examples/jsm/shaders/OutputShader.js +0 -78
- package/examples/jsm/shaders/RGBShiftShader.js +0 -54
- package/examples/jsm/shaders/SAOShader.js +0 -188
- package/examples/jsm/shaders/SMAAShader.js +0 -460
- package/examples/jsm/shaders/SSAOShader.js +0 -288
- package/examples/jsm/shaders/SSRShader.js +0 -364
- package/examples/jsm/shaders/SepiaShader.js +0 -52
- package/examples/jsm/shaders/SobelOperatorShader.js +0 -90
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +0 -88
- package/examples/jsm/shaders/TechnicolorShader.js +0 -43
- package/examples/jsm/shaders/ToonShader.js +0 -326
- package/examples/jsm/shaders/TriangleBlurShader.js +0 -72
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +0 -45
- package/examples/jsm/shaders/VelocityShader.js +0 -128
- package/examples/jsm/shaders/VerticalBlurShader.js +0 -59
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +0 -61
- package/examples/jsm/shaders/VignetteShader.js +0 -51
- package/examples/jsm/shaders/VolumeShader.js +0 -289
- package/examples/jsm/shaders/WaterRefractionShader.js +0 -93
- package/examples/jsm/textures/FlakesTexture.js +0 -40
- package/examples/jsm/utils/BufferGeometryUtils.js +0 -1373
- package/examples/jsm/utils/CameraUtils.js +0 -73
- package/examples/jsm/utils/GPUStatsPanel.js +0 -128
- package/examples/jsm/utils/GeometryCompressionUtils.js +0 -639
- package/examples/jsm/utils/GeometryUtils.js +0 -221
- package/examples/jsm/utils/LDrawUtils.js +0 -202
- package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
- package/examples/jsm/utils/SceneUtils.js +0 -254
- package/examples/jsm/utils/ShadowMapViewer.js +0 -210
- package/examples/jsm/utils/SkeletonUtils.js +0 -413
- package/examples/jsm/utils/TextureUtils.js +0 -86
- package/examples/jsm/utils/UVsDebug.js +0 -165
- package/examples/jsm/utils/WorkerPool.js +0 -102
- package/examples/jsm/webxr/ARButton.js +0 -208
- package/examples/jsm/webxr/OculusHandModel.js +0 -109
- package/examples/jsm/webxr/OculusHandPointerModel.js +0 -413
- package/examples/jsm/webxr/Text2D.js +0 -38
- package/examples/jsm/webxr/VRButton.js +0 -200
- package/examples/jsm/webxr/XRButton.js +0 -198
- package/examples/jsm/webxr/XRControllerModelFactory.js +0 -299
- package/examples/jsm/webxr/XREstimatedLight.js +0 -223
- package/examples/jsm/webxr/XRHandMeshModel.js +0 -112
- package/examples/jsm/webxr/XRHandModelFactory.js +0 -105
- package/examples/jsm/webxr/XRHandPrimitiveModel.js +0 -103
- package/examples/jsm/webxr/XRPlanes.js +0 -100
- package/lib/3d.min.js +0 -1
|
@@ -1,1792 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Return the name of a component
|
|
3
|
-
* @param {Component} Component
|
|
4
|
-
* @private
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Get a key from a list of components
|
|
9
|
-
* @param {Array(Component)} Components Array of components to generate the key
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
|
-
function queryKey(Components) {
|
|
13
|
-
var ids = [];
|
|
14
|
-
for (var n = 0; n < Components.length; n++) {
|
|
15
|
-
var T = Components[n];
|
|
16
|
-
|
|
17
|
-
if (!componentRegistered(T)) {
|
|
18
|
-
throw new Error(`Tried to create a query with an unregistered component`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (typeof T === "object") {
|
|
22
|
-
var operator = T.operator === "not" ? "!" : T.operator;
|
|
23
|
-
ids.push(operator + T.Component._typeId);
|
|
24
|
-
} else {
|
|
25
|
-
ids.push(T._typeId);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return ids.sort().join("-");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Detector for browser's "window"
|
|
33
|
-
const hasWindow = typeof window !== "undefined";
|
|
34
|
-
|
|
35
|
-
// performance.now() "polyfill"
|
|
36
|
-
const now =
|
|
37
|
-
hasWindow && typeof window.performance !== "undefined"
|
|
38
|
-
? performance.now.bind(performance)
|
|
39
|
-
: Date.now.bind(Date);
|
|
40
|
-
|
|
41
|
-
function componentRegistered(T) {
|
|
42
|
-
return (
|
|
43
|
-
(typeof T === "object" && T.Component._typeId !== undefined) ||
|
|
44
|
-
(T.isComponent && T._typeId !== undefined)
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
class SystemManager {
|
|
49
|
-
constructor(world) {
|
|
50
|
-
this._systems = [];
|
|
51
|
-
this._executeSystems = []; // Systems that have `execute` method
|
|
52
|
-
this.world = world;
|
|
53
|
-
this.lastExecutedSystem = null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
registerSystem(SystemClass, attributes) {
|
|
57
|
-
if (!SystemClass.isSystem) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`System '${SystemClass.name}' does not extend 'System' class`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (this.getSystem(SystemClass) !== undefined) {
|
|
64
|
-
console.warn(`System '${SystemClass.getName()}' already registered.`);
|
|
65
|
-
return this;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
var system = new SystemClass(this.world, attributes);
|
|
69
|
-
if (system.init) system.init(attributes);
|
|
70
|
-
system.order = this._systems.length;
|
|
71
|
-
this._systems.push(system);
|
|
72
|
-
if (system.execute) {
|
|
73
|
-
this._executeSystems.push(system);
|
|
74
|
-
this.sortSystems();
|
|
75
|
-
}
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
unregisterSystem(SystemClass) {
|
|
80
|
-
let system = this.getSystem(SystemClass);
|
|
81
|
-
if (system === undefined) {
|
|
82
|
-
console.warn(
|
|
83
|
-
`Can unregister system '${SystemClass.getName()}'. It doesn't exist.`
|
|
84
|
-
);
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this._systems.splice(this._systems.indexOf(system), 1);
|
|
89
|
-
|
|
90
|
-
if (system.execute) {
|
|
91
|
-
this._executeSystems.splice(this._executeSystems.indexOf(system), 1);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// @todo Add system.unregister() call to free resources
|
|
95
|
-
return this;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
sortSystems() {
|
|
99
|
-
this._executeSystems.sort((a, b) => {
|
|
100
|
-
return a.priority - b.priority || a.order - b.order;
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
getSystem(SystemClass) {
|
|
105
|
-
return this._systems.find((s) => s instanceof SystemClass);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
getSystems() {
|
|
109
|
-
return this._systems;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
removeSystem(SystemClass) {
|
|
113
|
-
var index = this._systems.indexOf(SystemClass);
|
|
114
|
-
if (!~index) return;
|
|
115
|
-
|
|
116
|
-
this._systems.splice(index, 1);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
executeSystem(system, delta, time) {
|
|
120
|
-
if (system.initialized) {
|
|
121
|
-
if (system.canExecute()) {
|
|
122
|
-
let startTime = now();
|
|
123
|
-
system.execute(delta, time);
|
|
124
|
-
system.executeTime = now() - startTime;
|
|
125
|
-
this.lastExecutedSystem = system;
|
|
126
|
-
system.clearEvents();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
stop() {
|
|
132
|
-
this._executeSystems.forEach((system) => system.stop());
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
execute(delta, time, forcePlay) {
|
|
136
|
-
this._executeSystems.forEach(
|
|
137
|
-
(system) =>
|
|
138
|
-
(forcePlay || system.enabled) && this.executeSystem(system, delta, time)
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
stats() {
|
|
143
|
-
var stats = {
|
|
144
|
-
numSystems: this._systems.length,
|
|
145
|
-
systems: {},
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
for (var i = 0; i < this._systems.length; i++) {
|
|
149
|
-
var system = this._systems[i];
|
|
150
|
-
var systemStats = (stats.systems[system.getName()] = {
|
|
151
|
-
queries: {},
|
|
152
|
-
executeTime: system.executeTime,
|
|
153
|
-
});
|
|
154
|
-
for (var name in system.ctx) {
|
|
155
|
-
systemStats.queries[name] = system.ctx[name].stats();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return stats;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
class ObjectPool {
|
|
164
|
-
// @todo Add initial size
|
|
165
|
-
constructor(T, initialSize) {
|
|
166
|
-
this.freeList = [];
|
|
167
|
-
this.count = 0;
|
|
168
|
-
this.T = T;
|
|
169
|
-
this.isObjectPool = true;
|
|
170
|
-
|
|
171
|
-
if (typeof initialSize !== "undefined") {
|
|
172
|
-
this.expand(initialSize);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
acquire() {
|
|
177
|
-
// Grow the list by 20%ish if we're out
|
|
178
|
-
if (this.freeList.length <= 0) {
|
|
179
|
-
this.expand(Math.round(this.count * 0.2) + 1);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
var item = this.freeList.pop();
|
|
183
|
-
|
|
184
|
-
return item;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
release(item) {
|
|
188
|
-
item.reset();
|
|
189
|
-
this.freeList.push(item);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
expand(count) {
|
|
193
|
-
for (var n = 0; n < count; n++) {
|
|
194
|
-
var clone = new this.T();
|
|
195
|
-
clone._pool = this;
|
|
196
|
-
this.freeList.push(clone);
|
|
197
|
-
}
|
|
198
|
-
this.count += count;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
totalSize() {
|
|
202
|
-
return this.count;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
totalFree() {
|
|
206
|
-
return this.freeList.length;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
totalUsed() {
|
|
210
|
-
return this.count - this.freeList.length;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* @private
|
|
216
|
-
* @class EventDispatcher
|
|
217
|
-
*/
|
|
218
|
-
class EventDispatcher {
|
|
219
|
-
constructor() {
|
|
220
|
-
this._listeners = {};
|
|
221
|
-
this.stats = {
|
|
222
|
-
fired: 0,
|
|
223
|
-
handled: 0,
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Add an event listener
|
|
229
|
-
* @param {String} eventName Name of the event to listen
|
|
230
|
-
* @param {Function} listener Callback to trigger when the event is fired
|
|
231
|
-
*/
|
|
232
|
-
addEventListener(eventName, listener) {
|
|
233
|
-
let listeners = this._listeners;
|
|
234
|
-
if (listeners[eventName] === undefined) {
|
|
235
|
-
listeners[eventName] = [];
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (listeners[eventName].indexOf(listener) === -1) {
|
|
239
|
-
listeners[eventName].push(listener);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Check if an event listener is already added to the list of listeners
|
|
245
|
-
* @param {String} eventName Name of the event to check
|
|
246
|
-
* @param {Function} listener Callback for the specified event
|
|
247
|
-
*/
|
|
248
|
-
hasEventListener(eventName, listener) {
|
|
249
|
-
return (
|
|
250
|
-
this._listeners[eventName] !== undefined &&
|
|
251
|
-
this._listeners[eventName].indexOf(listener) !== -1
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Remove an event listener
|
|
257
|
-
* @param {String} eventName Name of the event to remove
|
|
258
|
-
* @param {Function} listener Callback for the specified event
|
|
259
|
-
*/
|
|
260
|
-
removeEventListener(eventName, listener) {
|
|
261
|
-
var listenerArray = this._listeners[eventName];
|
|
262
|
-
if (listenerArray !== undefined) {
|
|
263
|
-
var index = listenerArray.indexOf(listener);
|
|
264
|
-
if (index !== -1) {
|
|
265
|
-
listenerArray.splice(index, 1);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Dispatch an event
|
|
272
|
-
* @param {String} eventName Name of the event to dispatch
|
|
273
|
-
* @param {Entity} entity (Optional) Entity to emit
|
|
274
|
-
* @param {Component} component
|
|
275
|
-
*/
|
|
276
|
-
dispatchEvent(eventName, entity, component) {
|
|
277
|
-
this.stats.fired++;
|
|
278
|
-
|
|
279
|
-
var listenerArray = this._listeners[eventName];
|
|
280
|
-
if (listenerArray !== undefined) {
|
|
281
|
-
var array = listenerArray.slice(0);
|
|
282
|
-
|
|
283
|
-
for (var i = 0; i < array.length; i++) {
|
|
284
|
-
array[i].call(this, entity, component);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Reset stats counters
|
|
291
|
-
*/
|
|
292
|
-
resetCounters() {
|
|
293
|
-
this.stats.fired = this.stats.handled = 0;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
class Query {
|
|
298
|
-
/**
|
|
299
|
-
* @param {Array(Component)} Components List of types of components to query
|
|
300
|
-
*/
|
|
301
|
-
constructor(Components, manager) {
|
|
302
|
-
this.Components = [];
|
|
303
|
-
this.NotComponents = [];
|
|
304
|
-
|
|
305
|
-
Components.forEach((component) => {
|
|
306
|
-
if (typeof component === "object") {
|
|
307
|
-
this.NotComponents.push(component.Component);
|
|
308
|
-
} else {
|
|
309
|
-
this.Components.push(component);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
if (this.Components.length === 0) {
|
|
314
|
-
throw new Error("Can't create a query without components");
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
this.entities = [];
|
|
318
|
-
|
|
319
|
-
this.eventDispatcher = new EventDispatcher();
|
|
320
|
-
|
|
321
|
-
// This query is being used by a reactive system
|
|
322
|
-
this.reactive = false;
|
|
323
|
-
|
|
324
|
-
this.key = queryKey(Components);
|
|
325
|
-
|
|
326
|
-
// Fill the query with the existing entities
|
|
327
|
-
for (var i = 0; i < manager._entities.length; i++) {
|
|
328
|
-
var entity = manager._entities[i];
|
|
329
|
-
if (this.match(entity)) {
|
|
330
|
-
// @todo ??? this.addEntity(entity); => preventing the event to be generated
|
|
331
|
-
entity.queries.push(this);
|
|
332
|
-
this.entities.push(entity);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Add entity to this query
|
|
339
|
-
* @param {Entity} entity
|
|
340
|
-
*/
|
|
341
|
-
addEntity(entity) {
|
|
342
|
-
entity.queries.push(this);
|
|
343
|
-
this.entities.push(entity);
|
|
344
|
-
|
|
345
|
-
this.eventDispatcher.dispatchEvent(Query.prototype.ENTITY_ADDED, entity);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Remove entity from this query
|
|
350
|
-
* @param {Entity} entity
|
|
351
|
-
*/
|
|
352
|
-
removeEntity(entity) {
|
|
353
|
-
let index = this.entities.indexOf(entity);
|
|
354
|
-
if (~index) {
|
|
355
|
-
this.entities.splice(index, 1);
|
|
356
|
-
|
|
357
|
-
index = entity.queries.indexOf(this);
|
|
358
|
-
entity.queries.splice(index, 1);
|
|
359
|
-
|
|
360
|
-
this.eventDispatcher.dispatchEvent(
|
|
361
|
-
Query.prototype.ENTITY_REMOVED,
|
|
362
|
-
entity
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
match(entity) {
|
|
368
|
-
return (
|
|
369
|
-
entity.hasAllComponents(this.Components) &&
|
|
370
|
-
!entity.hasAnyComponents(this.NotComponents)
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
toJSON() {
|
|
375
|
-
return {
|
|
376
|
-
key: this.key,
|
|
377
|
-
reactive: this.reactive,
|
|
378
|
-
components: {
|
|
379
|
-
included: this.Components.map((C) => C.name),
|
|
380
|
-
not: this.NotComponents.map((C) => C.name),
|
|
381
|
-
},
|
|
382
|
-
numEntities: this.entities.length,
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Return stats for this query
|
|
388
|
-
*/
|
|
389
|
-
stats() {
|
|
390
|
-
return {
|
|
391
|
-
numComponents: this.Components.length,
|
|
392
|
-
numEntities: this.entities.length,
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
Query.prototype.ENTITY_ADDED = "Query#ENTITY_ADDED";
|
|
398
|
-
Query.prototype.ENTITY_REMOVED = "Query#ENTITY_REMOVED";
|
|
399
|
-
Query.prototype.COMPONENT_CHANGED = "Query#COMPONENT_CHANGED";
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* @private
|
|
403
|
-
* @class QueryManager
|
|
404
|
-
*/
|
|
405
|
-
class QueryManager {
|
|
406
|
-
constructor(world) {
|
|
407
|
-
this._world = world;
|
|
408
|
-
|
|
409
|
-
// Queries indexed by a unique identifier for the components it has
|
|
410
|
-
this._queries = {};
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
onEntityRemoved(entity) {
|
|
414
|
-
for (var queryName in this._queries) {
|
|
415
|
-
var query = this._queries[queryName];
|
|
416
|
-
if (entity.queries.indexOf(query) !== -1) {
|
|
417
|
-
query.removeEntity(entity);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* Callback when a component is added to an entity
|
|
424
|
-
* @param {Entity} entity Entity that just got the new component
|
|
425
|
-
* @param {Component} Component Component added to the entity
|
|
426
|
-
*/
|
|
427
|
-
onEntityComponentAdded(entity, Component) {
|
|
428
|
-
// @todo Use bitmask for checking components?
|
|
429
|
-
|
|
430
|
-
// Check each indexed query to see if we need to add this entity to the list
|
|
431
|
-
for (var queryName in this._queries) {
|
|
432
|
-
var query = this._queries[queryName];
|
|
433
|
-
|
|
434
|
-
if (
|
|
435
|
-
!!~query.NotComponents.indexOf(Component) &&
|
|
436
|
-
~query.entities.indexOf(entity)
|
|
437
|
-
) {
|
|
438
|
-
query.removeEntity(entity);
|
|
439
|
-
continue;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
// Add the entity only if:
|
|
443
|
-
// Component is in the query
|
|
444
|
-
// and Entity has ALL the components of the query
|
|
445
|
-
// and Entity is not already in the query
|
|
446
|
-
if (
|
|
447
|
-
!~query.Components.indexOf(Component) ||
|
|
448
|
-
!query.match(entity) ||
|
|
449
|
-
~query.entities.indexOf(entity)
|
|
450
|
-
)
|
|
451
|
-
continue;
|
|
452
|
-
|
|
453
|
-
query.addEntity(entity);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
/**
|
|
458
|
-
* Callback when a component is removed from an entity
|
|
459
|
-
* @param {Entity} entity Entity to remove the component from
|
|
460
|
-
* @param {Component} Component Component to remove from the entity
|
|
461
|
-
*/
|
|
462
|
-
onEntityComponentRemoved(entity, Component) {
|
|
463
|
-
for (var queryName in this._queries) {
|
|
464
|
-
var query = this._queries[queryName];
|
|
465
|
-
|
|
466
|
-
if (
|
|
467
|
-
!!~query.NotComponents.indexOf(Component) &&
|
|
468
|
-
!~query.entities.indexOf(entity) &&
|
|
469
|
-
query.match(entity)
|
|
470
|
-
) {
|
|
471
|
-
query.addEntity(entity);
|
|
472
|
-
continue;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
if (
|
|
476
|
-
!!~query.Components.indexOf(Component) &&
|
|
477
|
-
!!~query.entities.indexOf(entity) &&
|
|
478
|
-
!query.match(entity)
|
|
479
|
-
) {
|
|
480
|
-
query.removeEntity(entity);
|
|
481
|
-
continue;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* Get a query for the specified components
|
|
488
|
-
* @param {Component} Components Components that the query should have
|
|
489
|
-
*/
|
|
490
|
-
getQuery(Components) {
|
|
491
|
-
var key = queryKey(Components);
|
|
492
|
-
var query = this._queries[key];
|
|
493
|
-
if (!query) {
|
|
494
|
-
this._queries[key] = query = new Query(Components, this._world);
|
|
495
|
-
}
|
|
496
|
-
return query;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Return some stats from this class
|
|
501
|
-
*/
|
|
502
|
-
stats() {
|
|
503
|
-
var stats = {};
|
|
504
|
-
for (var queryName in this._queries) {
|
|
505
|
-
stats[queryName] = this._queries[queryName].stats();
|
|
506
|
-
}
|
|
507
|
-
return stats;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
class Component {
|
|
512
|
-
constructor(props) {
|
|
513
|
-
if (props !== false) {
|
|
514
|
-
const schema = this.constructor.schema;
|
|
515
|
-
|
|
516
|
-
for (const key in schema) {
|
|
517
|
-
if (props && props.hasOwnProperty(key)) {
|
|
518
|
-
this[key] = props[key];
|
|
519
|
-
} else {
|
|
520
|
-
const schemaProp = schema[key];
|
|
521
|
-
if (schemaProp.hasOwnProperty("default")) {
|
|
522
|
-
this[key] = schemaProp.type.clone(schemaProp.default);
|
|
523
|
-
} else {
|
|
524
|
-
const type = schemaProp.type;
|
|
525
|
-
this[key] = type.clone(type.default);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
if ( props !== undefined) {
|
|
531
|
-
this.checkUndefinedAttributes(props);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
this._pool = null;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
copy(source) {
|
|
539
|
-
const schema = this.constructor.schema;
|
|
540
|
-
|
|
541
|
-
for (const key in schema) {
|
|
542
|
-
const prop = schema[key];
|
|
543
|
-
|
|
544
|
-
if (source.hasOwnProperty(key)) {
|
|
545
|
-
this[key] = prop.type.copy(source[key], this[key]);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
// @DEBUG
|
|
550
|
-
{
|
|
551
|
-
this.checkUndefinedAttributes(source);
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
return this;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
clone() {
|
|
558
|
-
return new this.constructor().copy(this);
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
reset() {
|
|
562
|
-
const schema = this.constructor.schema;
|
|
563
|
-
|
|
564
|
-
for (const key in schema) {
|
|
565
|
-
const schemaProp = schema[key];
|
|
566
|
-
|
|
567
|
-
if (schemaProp.hasOwnProperty("default")) {
|
|
568
|
-
this[key] = schemaProp.type.copy(schemaProp.default, this[key]);
|
|
569
|
-
} else {
|
|
570
|
-
const type = schemaProp.type;
|
|
571
|
-
this[key] = type.copy(type.default, this[key]);
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
dispose() {
|
|
577
|
-
if (this._pool) {
|
|
578
|
-
this._pool.release(this);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
getName() {
|
|
583
|
-
return this.constructor.getName();
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
checkUndefinedAttributes(src) {
|
|
587
|
-
const schema = this.constructor.schema;
|
|
588
|
-
|
|
589
|
-
// Check that the attributes defined in source are also defined in the schema
|
|
590
|
-
Object.keys(src).forEach((srcKey) => {
|
|
591
|
-
if (!schema.hasOwnProperty(srcKey)) {
|
|
592
|
-
console.warn(
|
|
593
|
-
`Trying to set attribute '${srcKey}' not defined in the '${this.constructor.name}' schema. Please fix the schema, the attribute value won't be set`
|
|
594
|
-
);
|
|
595
|
-
}
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
Component.schema = {};
|
|
601
|
-
Component.isComponent = true;
|
|
602
|
-
Component.getName = function () {
|
|
603
|
-
return this.displayName || this.name;
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
class SystemStateComponent extends Component {}
|
|
607
|
-
|
|
608
|
-
SystemStateComponent.isSystemStateComponent = true;
|
|
609
|
-
|
|
610
|
-
class EntityPool extends ObjectPool {
|
|
611
|
-
constructor(entityManager, entityClass, initialSize) {
|
|
612
|
-
super(entityClass, undefined);
|
|
613
|
-
this.entityManager = entityManager;
|
|
614
|
-
|
|
615
|
-
if (typeof initialSize !== "undefined") {
|
|
616
|
-
this.expand(initialSize);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
expand(count) {
|
|
621
|
-
for (var n = 0; n < count; n++) {
|
|
622
|
-
var clone = new this.T(this.entityManager);
|
|
623
|
-
clone._pool = this;
|
|
624
|
-
this.freeList.push(clone);
|
|
625
|
-
}
|
|
626
|
-
this.count += count;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
/**
|
|
631
|
-
* @private
|
|
632
|
-
* @class EntityManager
|
|
633
|
-
*/
|
|
634
|
-
class EntityManager {
|
|
635
|
-
constructor(world) {
|
|
636
|
-
this.world = world;
|
|
637
|
-
this.componentsManager = world.componentsManager;
|
|
638
|
-
|
|
639
|
-
// All the entities in this instance
|
|
640
|
-
this._entities = [];
|
|
641
|
-
this._nextEntityId = 0;
|
|
642
|
-
|
|
643
|
-
this._entitiesByNames = {};
|
|
644
|
-
|
|
645
|
-
this._queryManager = new QueryManager(this);
|
|
646
|
-
this.eventDispatcher = new EventDispatcher();
|
|
647
|
-
this._entityPool = new EntityPool(
|
|
648
|
-
this,
|
|
649
|
-
this.world.options.entityClass,
|
|
650
|
-
this.world.options.entityPoolSize
|
|
651
|
-
);
|
|
652
|
-
|
|
653
|
-
// Deferred deletion
|
|
654
|
-
this.entitiesWithComponentsToRemove = [];
|
|
655
|
-
this.entitiesToRemove = [];
|
|
656
|
-
this.deferredRemovalEnabled = true;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
getEntityByName(name) {
|
|
660
|
-
return this._entitiesByNames[name];
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
/**
|
|
664
|
-
* Create a new entity
|
|
665
|
-
*/
|
|
666
|
-
createEntity(name) {
|
|
667
|
-
var entity = this._entityPool.acquire();
|
|
668
|
-
entity.alive = true;
|
|
669
|
-
entity.name = name || "";
|
|
670
|
-
if (name) {
|
|
671
|
-
if (this._entitiesByNames[name]) {
|
|
672
|
-
console.warn(`Entity name '${name}' already exist`);
|
|
673
|
-
} else {
|
|
674
|
-
this._entitiesByNames[name] = entity;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
this._entities.push(entity);
|
|
679
|
-
this.eventDispatcher.dispatchEvent(ENTITY_CREATED, entity);
|
|
680
|
-
return entity;
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
// COMPONENTS
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* Add a component to an entity
|
|
687
|
-
* @param {Entity} entity Entity where the component will be added
|
|
688
|
-
* @param {Component} Component Component to be added to the entity
|
|
689
|
-
* @param {Object} values Optional values to replace the default attributes
|
|
690
|
-
*/
|
|
691
|
-
entityAddComponent(entity, Component, values) {
|
|
692
|
-
// @todo Probably define Component._typeId with a default value and avoid using typeof
|
|
693
|
-
if (
|
|
694
|
-
typeof Component._typeId === "undefined" &&
|
|
695
|
-
!this.world.componentsManager._ComponentsMap[Component._typeId]
|
|
696
|
-
) {
|
|
697
|
-
throw new Error(
|
|
698
|
-
`Attempted to add unregistered component "${Component.getName()}"`
|
|
699
|
-
);
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
if (~entity._ComponentTypes.indexOf(Component)) {
|
|
703
|
-
{
|
|
704
|
-
console.warn(
|
|
705
|
-
"Component type already exists on entity.",
|
|
706
|
-
entity,
|
|
707
|
-
Component.getName()
|
|
708
|
-
);
|
|
709
|
-
}
|
|
710
|
-
return;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
entity._ComponentTypes.push(Component);
|
|
714
|
-
|
|
715
|
-
if (Component.__proto__ === SystemStateComponent) {
|
|
716
|
-
entity.numStateComponents++;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
var componentPool = this.world.componentsManager.getComponentsPool(
|
|
720
|
-
Component
|
|
721
|
-
);
|
|
722
|
-
|
|
723
|
-
var component = componentPool
|
|
724
|
-
? componentPool.acquire()
|
|
725
|
-
: new Component(values);
|
|
726
|
-
|
|
727
|
-
if (componentPool && values) {
|
|
728
|
-
component.copy(values);
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
entity._components[Component._typeId] = component;
|
|
732
|
-
|
|
733
|
-
this._queryManager.onEntityComponentAdded(entity, Component);
|
|
734
|
-
this.world.componentsManager.componentAddedToEntity(Component);
|
|
735
|
-
|
|
736
|
-
this.eventDispatcher.dispatchEvent(COMPONENT_ADDED, entity, Component);
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
/**
|
|
740
|
-
* Remove a component from an entity
|
|
741
|
-
* @param {Entity} entity Entity which will get removed the component
|
|
742
|
-
* @param {*} Component Component to remove from the entity
|
|
743
|
-
* @param {Bool} immediately If you want to remove the component immediately instead of deferred (Default is false)
|
|
744
|
-
*/
|
|
745
|
-
entityRemoveComponent(entity, Component, immediately) {
|
|
746
|
-
var index = entity._ComponentTypes.indexOf(Component);
|
|
747
|
-
if (!~index) return;
|
|
748
|
-
|
|
749
|
-
this.eventDispatcher.dispatchEvent(COMPONENT_REMOVE, entity, Component);
|
|
750
|
-
|
|
751
|
-
if (immediately) {
|
|
752
|
-
this._entityRemoveComponentSync(entity, Component, index);
|
|
753
|
-
} else {
|
|
754
|
-
if (entity._ComponentTypesToRemove.length === 0)
|
|
755
|
-
this.entitiesWithComponentsToRemove.push(entity);
|
|
756
|
-
|
|
757
|
-
entity._ComponentTypes.splice(index, 1);
|
|
758
|
-
entity._ComponentTypesToRemove.push(Component);
|
|
759
|
-
|
|
760
|
-
entity._componentsToRemove[Component._typeId] =
|
|
761
|
-
entity._components[Component._typeId];
|
|
762
|
-
delete entity._components[Component._typeId];
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
// Check each indexed query to see if we need to remove it
|
|
766
|
-
this._queryManager.onEntityComponentRemoved(entity, Component);
|
|
767
|
-
|
|
768
|
-
if (Component.__proto__ === SystemStateComponent) {
|
|
769
|
-
entity.numStateComponents--;
|
|
770
|
-
|
|
771
|
-
// Check if the entity was a ghost waiting for the last system state component to be removed
|
|
772
|
-
if (entity.numStateComponents === 0 && !entity.alive) {
|
|
773
|
-
entity.remove();
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
_entityRemoveComponentSync(entity, Component, index) {
|
|
779
|
-
// Remove T listing on entity and property ref, then free the component.
|
|
780
|
-
entity._ComponentTypes.splice(index, 1);
|
|
781
|
-
var component = entity._components[Component._typeId];
|
|
782
|
-
delete entity._components[Component._typeId];
|
|
783
|
-
component.dispose();
|
|
784
|
-
this.world.componentsManager.componentRemovedFromEntity(Component);
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
/**
|
|
788
|
-
* Remove all the components from an entity
|
|
789
|
-
* @param {Entity} entity Entity from which the components will be removed
|
|
790
|
-
*/
|
|
791
|
-
entityRemoveAllComponents(entity, immediately) {
|
|
792
|
-
let Components = entity._ComponentTypes;
|
|
793
|
-
|
|
794
|
-
for (let j = Components.length - 1; j >= 0; j--) {
|
|
795
|
-
if (Components[j].__proto__ !== SystemStateComponent)
|
|
796
|
-
this.entityRemoveComponent(entity, Components[j], immediately);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
/**
|
|
801
|
-
* Remove the entity from this manager. It will clear also its components
|
|
802
|
-
* @param {Entity} entity Entity to remove from the manager
|
|
803
|
-
* @param {Bool} immediately If you want to remove the component immediately instead of deferred (Default is false)
|
|
804
|
-
*/
|
|
805
|
-
removeEntity(entity, immediately) {
|
|
806
|
-
var index = this._entities.indexOf(entity);
|
|
807
|
-
|
|
808
|
-
if (!~index) throw new Error("Tried to remove entity not in list");
|
|
809
|
-
|
|
810
|
-
entity.alive = false;
|
|
811
|
-
this.entityRemoveAllComponents(entity, immediately);
|
|
812
|
-
|
|
813
|
-
if (entity.numStateComponents === 0) {
|
|
814
|
-
// Remove from entity list
|
|
815
|
-
this.eventDispatcher.dispatchEvent(ENTITY_REMOVED, entity);
|
|
816
|
-
this._queryManager.onEntityRemoved(entity);
|
|
817
|
-
if (immediately === true) {
|
|
818
|
-
this._releaseEntity(entity, index);
|
|
819
|
-
} else {
|
|
820
|
-
this.entitiesToRemove.push(entity);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
_releaseEntity(entity, index) {
|
|
826
|
-
this._entities.splice(index, 1);
|
|
827
|
-
|
|
828
|
-
if (this._entitiesByNames[entity.name]) {
|
|
829
|
-
delete this._entitiesByNames[entity.name];
|
|
830
|
-
}
|
|
831
|
-
entity._pool.release(entity);
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
/**
|
|
835
|
-
* Remove all entities from this manager
|
|
836
|
-
*/
|
|
837
|
-
removeAllEntities() {
|
|
838
|
-
for (var i = this._entities.length - 1; i >= 0; i--) {
|
|
839
|
-
this.removeEntity(this._entities[i]);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
processDeferredRemoval() {
|
|
844
|
-
if (!this.deferredRemovalEnabled) {
|
|
845
|
-
return;
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
for (let i = 0; i < this.entitiesToRemove.length; i++) {
|
|
849
|
-
let entity = this.entitiesToRemove[i];
|
|
850
|
-
let index = this._entities.indexOf(entity);
|
|
851
|
-
this._releaseEntity(entity, index);
|
|
852
|
-
}
|
|
853
|
-
this.entitiesToRemove.length = 0;
|
|
854
|
-
|
|
855
|
-
for (let i = 0; i < this.entitiesWithComponentsToRemove.length; i++) {
|
|
856
|
-
let entity = this.entitiesWithComponentsToRemove[i];
|
|
857
|
-
while (entity._ComponentTypesToRemove.length > 0) {
|
|
858
|
-
let Component = entity._ComponentTypesToRemove.pop();
|
|
859
|
-
|
|
860
|
-
var component = entity._componentsToRemove[Component._typeId];
|
|
861
|
-
delete entity._componentsToRemove[Component._typeId];
|
|
862
|
-
component.dispose();
|
|
863
|
-
this.world.componentsManager.componentRemovedFromEntity(Component);
|
|
864
|
-
|
|
865
|
-
//this._entityRemoveComponentSync(entity, Component, index);
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
this.entitiesWithComponentsToRemove.length = 0;
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
/**
|
|
873
|
-
* Get a query based on a list of components
|
|
874
|
-
* @param {Array(Component)} Components List of components that will form the query
|
|
875
|
-
*/
|
|
876
|
-
queryComponents(Components) {
|
|
877
|
-
return this._queryManager.getQuery(Components);
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
// EXTRAS
|
|
881
|
-
|
|
882
|
-
/**
|
|
883
|
-
* Return number of entities
|
|
884
|
-
*/
|
|
885
|
-
count() {
|
|
886
|
-
return this._entities.length;
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
/**
|
|
890
|
-
* Return some stats
|
|
891
|
-
*/
|
|
892
|
-
stats() {
|
|
893
|
-
var stats = {
|
|
894
|
-
numEntities: this._entities.length,
|
|
895
|
-
numQueries: Object.keys(this._queryManager._queries).length,
|
|
896
|
-
queries: this._queryManager.stats(),
|
|
897
|
-
numComponentPool: Object.keys(this.componentsManager._componentPool)
|
|
898
|
-
.length,
|
|
899
|
-
componentPool: {},
|
|
900
|
-
eventDispatcher: this.eventDispatcher.stats,
|
|
901
|
-
};
|
|
902
|
-
|
|
903
|
-
for (var ecsyComponentId in this.componentsManager._componentPool) {
|
|
904
|
-
var pool = this.componentsManager._componentPool[ecsyComponentId];
|
|
905
|
-
stats.componentPool[pool.T.getName()] = {
|
|
906
|
-
used: pool.totalUsed(),
|
|
907
|
-
size: pool.count,
|
|
908
|
-
};
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
return stats;
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
const ENTITY_CREATED = "EntityManager#ENTITY_CREATE";
|
|
916
|
-
const ENTITY_REMOVED = "EntityManager#ENTITY_REMOVED";
|
|
917
|
-
const COMPONENT_ADDED = "EntityManager#COMPONENT_ADDED";
|
|
918
|
-
const COMPONENT_REMOVE = "EntityManager#COMPONENT_REMOVE";
|
|
919
|
-
|
|
920
|
-
class ComponentManager {
|
|
921
|
-
constructor() {
|
|
922
|
-
this.Components = [];
|
|
923
|
-
this._ComponentsMap = {};
|
|
924
|
-
|
|
925
|
-
this._componentPool = {};
|
|
926
|
-
this.numComponents = {};
|
|
927
|
-
this.nextComponentId = 0;
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
hasComponent(Component) {
|
|
931
|
-
return this.Components.indexOf(Component) !== -1;
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
registerComponent(Component, objectPool) {
|
|
935
|
-
if (this.Components.indexOf(Component) !== -1) {
|
|
936
|
-
console.warn(
|
|
937
|
-
`Component type: '${Component.getName()}' already registered.`
|
|
938
|
-
);
|
|
939
|
-
return;
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
const schema = Component.schema;
|
|
943
|
-
|
|
944
|
-
if (!schema) {
|
|
945
|
-
throw new Error(
|
|
946
|
-
`Component "${Component.getName()}" has no schema property.`
|
|
947
|
-
);
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
for (const propName in schema) {
|
|
951
|
-
const prop = schema[propName];
|
|
952
|
-
|
|
953
|
-
if (!prop.type) {
|
|
954
|
-
throw new Error(
|
|
955
|
-
`Invalid schema for component "${Component.getName()}". Missing type for "${propName}" property.`
|
|
956
|
-
);
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
Component._typeId = this.nextComponentId++;
|
|
961
|
-
this.Components.push(Component);
|
|
962
|
-
this._ComponentsMap[Component._typeId] = Component;
|
|
963
|
-
this.numComponents[Component._typeId] = 0;
|
|
964
|
-
|
|
965
|
-
if (objectPool === undefined) {
|
|
966
|
-
objectPool = new ObjectPool(Component);
|
|
967
|
-
} else if (objectPool === false) {
|
|
968
|
-
objectPool = undefined;
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
this._componentPool[Component._typeId] = objectPool;
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
componentAddedToEntity(Component) {
|
|
975
|
-
this.numComponents[Component._typeId]++;
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
componentRemovedFromEntity(Component) {
|
|
979
|
-
this.numComponents[Component._typeId]--;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
getComponentsPool(Component) {
|
|
983
|
-
return this._componentPool[Component._typeId];
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
const Version = "0.3.1";
|
|
988
|
-
|
|
989
|
-
const proxyMap = new WeakMap();
|
|
990
|
-
|
|
991
|
-
const proxyHandler = {
|
|
992
|
-
set(target, prop) {
|
|
993
|
-
throw new Error(
|
|
994
|
-
`Tried to write to "${target.constructor.getName()}#${String(
|
|
995
|
-
prop
|
|
996
|
-
)}" on immutable component. Use .getMutableComponent() to modify a component.`
|
|
997
|
-
);
|
|
998
|
-
},
|
|
999
|
-
};
|
|
1000
|
-
|
|
1001
|
-
function wrapImmutableComponent(T, component) {
|
|
1002
|
-
if (component === undefined) {
|
|
1003
|
-
return undefined;
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
let wrappedComponent = proxyMap.get(component);
|
|
1007
|
-
|
|
1008
|
-
if (!wrappedComponent) {
|
|
1009
|
-
wrappedComponent = new Proxy(component, proxyHandler);
|
|
1010
|
-
proxyMap.set(component, wrappedComponent);
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
return wrappedComponent;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
class Entity {
|
|
1017
|
-
constructor(entityManager) {
|
|
1018
|
-
this._entityManager = entityManager || null;
|
|
1019
|
-
|
|
1020
|
-
// Unique ID for this entity
|
|
1021
|
-
this.id = entityManager._nextEntityId++;
|
|
1022
|
-
|
|
1023
|
-
// List of components types the entity has
|
|
1024
|
-
this._ComponentTypes = [];
|
|
1025
|
-
|
|
1026
|
-
// Instance of the components
|
|
1027
|
-
this._components = {};
|
|
1028
|
-
|
|
1029
|
-
this._componentsToRemove = {};
|
|
1030
|
-
|
|
1031
|
-
// Queries where the entity is added
|
|
1032
|
-
this.queries = [];
|
|
1033
|
-
|
|
1034
|
-
// Used for deferred removal
|
|
1035
|
-
this._ComponentTypesToRemove = [];
|
|
1036
|
-
|
|
1037
|
-
this.alive = false;
|
|
1038
|
-
|
|
1039
|
-
//if there are state components on a entity, it can't be removed completely
|
|
1040
|
-
this.numStateComponents = 0;
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
// COMPONENTS
|
|
1044
|
-
|
|
1045
|
-
getComponent(Component, includeRemoved) {
|
|
1046
|
-
var component = this._components[Component._typeId];
|
|
1047
|
-
|
|
1048
|
-
if (!component && includeRemoved === true) {
|
|
1049
|
-
component = this._componentsToRemove[Component._typeId];
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
return wrapImmutableComponent(Component, component)
|
|
1053
|
-
;
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
getRemovedComponent(Component) {
|
|
1057
|
-
const component = this._componentsToRemove[Component._typeId];
|
|
1058
|
-
|
|
1059
|
-
return wrapImmutableComponent(Component, component)
|
|
1060
|
-
;
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
getComponents() {
|
|
1064
|
-
return this._components;
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
getComponentsToRemove() {
|
|
1068
|
-
return this._componentsToRemove;
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
getComponentTypes() {
|
|
1072
|
-
return this._ComponentTypes;
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
getMutableComponent(Component) {
|
|
1076
|
-
var component = this._components[Component._typeId];
|
|
1077
|
-
|
|
1078
|
-
if (!component) {
|
|
1079
|
-
return;
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
for (var i = 0; i < this.queries.length; i++) {
|
|
1083
|
-
var query = this.queries[i];
|
|
1084
|
-
// @todo accelerate this check. Maybe having query._Components as an object
|
|
1085
|
-
// @todo add Not components
|
|
1086
|
-
if (query.reactive && query.Components.indexOf(Component) !== -1) {
|
|
1087
|
-
query.eventDispatcher.dispatchEvent(
|
|
1088
|
-
Query.prototype.COMPONENT_CHANGED,
|
|
1089
|
-
this,
|
|
1090
|
-
component
|
|
1091
|
-
);
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
return component;
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
addComponent(Component, values) {
|
|
1098
|
-
this._entityManager.entityAddComponent(this, Component, values);
|
|
1099
|
-
return this;
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
removeComponent(Component, forceImmediate) {
|
|
1103
|
-
this._entityManager.entityRemoveComponent(this, Component, forceImmediate);
|
|
1104
|
-
return this;
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
hasComponent(Component, includeRemoved) {
|
|
1108
|
-
return (
|
|
1109
|
-
!!~this._ComponentTypes.indexOf(Component) ||
|
|
1110
|
-
(includeRemoved === true && this.hasRemovedComponent(Component))
|
|
1111
|
-
);
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
hasRemovedComponent(Component) {
|
|
1115
|
-
return !!~this._ComponentTypesToRemove.indexOf(Component);
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
hasAllComponents(Components) {
|
|
1119
|
-
for (var i = 0; i < Components.length; i++) {
|
|
1120
|
-
if (!this.hasComponent(Components[i])) return false;
|
|
1121
|
-
}
|
|
1122
|
-
return true;
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
hasAnyComponents(Components) {
|
|
1126
|
-
for (var i = 0; i < Components.length; i++) {
|
|
1127
|
-
if (this.hasComponent(Components[i])) return true;
|
|
1128
|
-
}
|
|
1129
|
-
return false;
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
removeAllComponents(forceImmediate) {
|
|
1133
|
-
return this._entityManager.entityRemoveAllComponents(this, forceImmediate);
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
copy(src) {
|
|
1137
|
-
// TODO: This can definitely be optimized
|
|
1138
|
-
for (var ecsyComponentId in src._components) {
|
|
1139
|
-
var srcComponent = src._components[ecsyComponentId];
|
|
1140
|
-
this.addComponent(srcComponent.constructor);
|
|
1141
|
-
var component = this.getComponent(srcComponent.constructor);
|
|
1142
|
-
component.copy(srcComponent);
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
return this;
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
clone() {
|
|
1149
|
-
return new Entity(this._entityManager).copy(this);
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
reset() {
|
|
1153
|
-
this.id = this._entityManager._nextEntityId++;
|
|
1154
|
-
this._ComponentTypes.length = 0;
|
|
1155
|
-
this.queries.length = 0;
|
|
1156
|
-
|
|
1157
|
-
for (var ecsyComponentId in this._components) {
|
|
1158
|
-
delete this._components[ecsyComponentId];
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
remove(forceImmediate) {
|
|
1163
|
-
return this._entityManager.removeEntity(this, forceImmediate);
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
const DEFAULT_OPTIONS = {
|
|
1168
|
-
entityPoolSize: 0,
|
|
1169
|
-
entityClass: Entity,
|
|
1170
|
-
};
|
|
1171
|
-
|
|
1172
|
-
class World {
|
|
1173
|
-
constructor(options = {}) {
|
|
1174
|
-
this.options = Object.assign({}, DEFAULT_OPTIONS, options);
|
|
1175
|
-
|
|
1176
|
-
this.componentsManager = new ComponentManager(this);
|
|
1177
|
-
this.entityManager = new EntityManager(this);
|
|
1178
|
-
this.systemManager = new SystemManager(this);
|
|
1179
|
-
|
|
1180
|
-
this.enabled = true;
|
|
1181
|
-
|
|
1182
|
-
this.eventQueues = {};
|
|
1183
|
-
|
|
1184
|
-
if (hasWindow && typeof CustomEvent !== "undefined") {
|
|
1185
|
-
var event = new CustomEvent("ecsy-world-created", {
|
|
1186
|
-
detail: { world: this, version: Version },
|
|
1187
|
-
});
|
|
1188
|
-
window.dispatchEvent(event);
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
this.lastTime = now() / 1000;
|
|
1192
|
-
}
|
|
1193
|
-
|
|
1194
|
-
registerComponent(Component, objectPool) {
|
|
1195
|
-
this.componentsManager.registerComponent(Component, objectPool);
|
|
1196
|
-
return this;
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
registerSystem(System, attributes) {
|
|
1200
|
-
this.systemManager.registerSystem(System, attributes);
|
|
1201
|
-
return this;
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
hasRegisteredComponent(Component) {
|
|
1205
|
-
return this.componentsManager.hasComponent(Component);
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
unregisterSystem(System) {
|
|
1209
|
-
this.systemManager.unregisterSystem(System);
|
|
1210
|
-
return this;
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
getSystem(SystemClass) {
|
|
1214
|
-
return this.systemManager.getSystem(SystemClass);
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
getSystems() {
|
|
1218
|
-
return this.systemManager.getSystems();
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
execute(delta, time) {
|
|
1222
|
-
if (!delta) {
|
|
1223
|
-
time = now() / 1000;
|
|
1224
|
-
delta = time - this.lastTime;
|
|
1225
|
-
this.lastTime = time;
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
if (this.enabled) {
|
|
1229
|
-
this.systemManager.execute(delta, time);
|
|
1230
|
-
this.entityManager.processDeferredRemoval();
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
stop() {
|
|
1235
|
-
this.enabled = false;
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
play() {
|
|
1239
|
-
this.enabled = true;
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
createEntity(name) {
|
|
1243
|
-
return this.entityManager.createEntity(name);
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
stats() {
|
|
1247
|
-
var stats = {
|
|
1248
|
-
entities: this.entityManager.stats(),
|
|
1249
|
-
system: this.systemManager.stats(),
|
|
1250
|
-
};
|
|
1251
|
-
|
|
1252
|
-
return stats;
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
class System {
|
|
1257
|
-
canExecute() {
|
|
1258
|
-
if (this._mandatoryQueries.length === 0) return true;
|
|
1259
|
-
|
|
1260
|
-
for (let i = 0; i < this._mandatoryQueries.length; i++) {
|
|
1261
|
-
var query = this._mandatoryQueries[i];
|
|
1262
|
-
if (query.entities.length === 0) {
|
|
1263
|
-
return false;
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
return true;
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
getName() {
|
|
1271
|
-
return this.constructor.getName();
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
constructor(world, attributes) {
|
|
1275
|
-
this.world = world;
|
|
1276
|
-
this.enabled = true;
|
|
1277
|
-
|
|
1278
|
-
// @todo Better naming :)
|
|
1279
|
-
this._queries = {};
|
|
1280
|
-
this.queries = {};
|
|
1281
|
-
|
|
1282
|
-
this.priority = 0;
|
|
1283
|
-
|
|
1284
|
-
// Used for stats
|
|
1285
|
-
this.executeTime = 0;
|
|
1286
|
-
|
|
1287
|
-
if (attributes && attributes.priority) {
|
|
1288
|
-
this.priority = attributes.priority;
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
this._mandatoryQueries = [];
|
|
1292
|
-
|
|
1293
|
-
this.initialized = true;
|
|
1294
|
-
|
|
1295
|
-
if (this.constructor.queries) {
|
|
1296
|
-
for (var queryName in this.constructor.queries) {
|
|
1297
|
-
var queryConfig = this.constructor.queries[queryName];
|
|
1298
|
-
var Components = queryConfig.components;
|
|
1299
|
-
if (!Components || Components.length === 0) {
|
|
1300
|
-
throw new Error("'components' attribute can't be empty in a query");
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
// Detect if the components have already been registered
|
|
1304
|
-
let unregisteredComponents = Components.filter(
|
|
1305
|
-
(Component) => !componentRegistered(Component)
|
|
1306
|
-
);
|
|
1307
|
-
|
|
1308
|
-
if (unregisteredComponents.length > 0) {
|
|
1309
|
-
throw new Error(
|
|
1310
|
-
`Tried to create a query '${
|
|
1311
|
-
this.constructor.name
|
|
1312
|
-
}.${queryName}' with unregistered components: [${unregisteredComponents
|
|
1313
|
-
.map((c) => c.getName())
|
|
1314
|
-
.join(", ")}]`
|
|
1315
|
-
);
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
var query = this.world.entityManager.queryComponents(Components);
|
|
1319
|
-
|
|
1320
|
-
this._queries[queryName] = query;
|
|
1321
|
-
if (queryConfig.mandatory === true) {
|
|
1322
|
-
this._mandatoryQueries.push(query);
|
|
1323
|
-
}
|
|
1324
|
-
this.queries[queryName] = {
|
|
1325
|
-
results: query.entities,
|
|
1326
|
-
};
|
|
1327
|
-
|
|
1328
|
-
// Reactive configuration added/removed/changed
|
|
1329
|
-
var validEvents = ["added", "removed", "changed"];
|
|
1330
|
-
|
|
1331
|
-
const eventMapping = {
|
|
1332
|
-
added: Query.prototype.ENTITY_ADDED,
|
|
1333
|
-
removed: Query.prototype.ENTITY_REMOVED,
|
|
1334
|
-
changed: Query.prototype.COMPONENT_CHANGED, // Query.prototype.ENTITY_CHANGED
|
|
1335
|
-
};
|
|
1336
|
-
|
|
1337
|
-
if (queryConfig.listen) {
|
|
1338
|
-
validEvents.forEach((eventName) => {
|
|
1339
|
-
if (!this.execute) {
|
|
1340
|
-
console.warn(
|
|
1341
|
-
`System '${this.getName()}' has defined listen events (${validEvents.join(
|
|
1342
|
-
", "
|
|
1343
|
-
)}) for query '${queryName}' but it does not implement the 'execute' method.`
|
|
1344
|
-
);
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
// Is the event enabled on this system's query?
|
|
1348
|
-
if (queryConfig.listen[eventName]) {
|
|
1349
|
-
let event = queryConfig.listen[eventName];
|
|
1350
|
-
|
|
1351
|
-
if (eventName === "changed") {
|
|
1352
|
-
query.reactive = true;
|
|
1353
|
-
if (event === true) {
|
|
1354
|
-
// Any change on the entity from the components in the query
|
|
1355
|
-
let eventList = (this.queries[queryName][eventName] = []);
|
|
1356
|
-
query.eventDispatcher.addEventListener(
|
|
1357
|
-
Query.prototype.COMPONENT_CHANGED,
|
|
1358
|
-
(entity) => {
|
|
1359
|
-
// Avoid duplicates
|
|
1360
|
-
if (eventList.indexOf(entity) === -1) {
|
|
1361
|
-
eventList.push(entity);
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
);
|
|
1365
|
-
} else if (Array.isArray(event)) {
|
|
1366
|
-
let eventList = (this.queries[queryName][eventName] = []);
|
|
1367
|
-
query.eventDispatcher.addEventListener(
|
|
1368
|
-
Query.prototype.COMPONENT_CHANGED,
|
|
1369
|
-
(entity, changedComponent) => {
|
|
1370
|
-
// Avoid duplicates
|
|
1371
|
-
if (
|
|
1372
|
-
event.indexOf(changedComponent.constructor) !== -1 &&
|
|
1373
|
-
eventList.indexOf(entity) === -1
|
|
1374
|
-
) {
|
|
1375
|
-
eventList.push(entity);
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
);
|
|
1379
|
-
}
|
|
1380
|
-
} else {
|
|
1381
|
-
let eventList = (this.queries[queryName][eventName] = []);
|
|
1382
|
-
|
|
1383
|
-
query.eventDispatcher.addEventListener(
|
|
1384
|
-
eventMapping[eventName],
|
|
1385
|
-
(entity) => {
|
|
1386
|
-
// @fixme overhead?
|
|
1387
|
-
if (eventList.indexOf(entity) === -1)
|
|
1388
|
-
eventList.push(entity);
|
|
1389
|
-
}
|
|
1390
|
-
);
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
});
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
|
|
1399
|
-
stop() {
|
|
1400
|
-
this.executeTime = 0;
|
|
1401
|
-
this.enabled = false;
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
play() {
|
|
1405
|
-
this.enabled = true;
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
// @question rename to clear queues?
|
|
1409
|
-
clearEvents() {
|
|
1410
|
-
for (let queryName in this.queries) {
|
|
1411
|
-
var query = this.queries[queryName];
|
|
1412
|
-
if (query.added) {
|
|
1413
|
-
query.added.length = 0;
|
|
1414
|
-
}
|
|
1415
|
-
if (query.removed) {
|
|
1416
|
-
query.removed.length = 0;
|
|
1417
|
-
}
|
|
1418
|
-
if (query.changed) {
|
|
1419
|
-
if (Array.isArray(query.changed)) {
|
|
1420
|
-
query.changed.length = 0;
|
|
1421
|
-
} else {
|
|
1422
|
-
for (let name in query.changed) {
|
|
1423
|
-
query.changed[name].length = 0;
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
toJSON() {
|
|
1431
|
-
var json = {
|
|
1432
|
-
name: this.getName(),
|
|
1433
|
-
enabled: this.enabled,
|
|
1434
|
-
executeTime: this.executeTime,
|
|
1435
|
-
priority: this.priority,
|
|
1436
|
-
queries: {},
|
|
1437
|
-
};
|
|
1438
|
-
|
|
1439
|
-
if (this.constructor.queries) {
|
|
1440
|
-
var queries = this.constructor.queries;
|
|
1441
|
-
for (let queryName in queries) {
|
|
1442
|
-
let query = this.queries[queryName];
|
|
1443
|
-
let queryDefinition = queries[queryName];
|
|
1444
|
-
let jsonQuery = (json.queries[queryName] = {
|
|
1445
|
-
key: this._queries[queryName].key,
|
|
1446
|
-
});
|
|
1447
|
-
|
|
1448
|
-
jsonQuery.mandatory = queryDefinition.mandatory === true;
|
|
1449
|
-
jsonQuery.reactive =
|
|
1450
|
-
queryDefinition.listen &&
|
|
1451
|
-
(queryDefinition.listen.added === true ||
|
|
1452
|
-
queryDefinition.listen.removed === true ||
|
|
1453
|
-
queryDefinition.listen.changed === true ||
|
|
1454
|
-
Array.isArray(queryDefinition.listen.changed));
|
|
1455
|
-
|
|
1456
|
-
if (jsonQuery.reactive) {
|
|
1457
|
-
jsonQuery.listen = {};
|
|
1458
|
-
|
|
1459
|
-
const methods = ["added", "removed", "changed"];
|
|
1460
|
-
methods.forEach((method) => {
|
|
1461
|
-
if (query[method]) {
|
|
1462
|
-
jsonQuery.listen[method] = {
|
|
1463
|
-
entities: query[method].length,
|
|
1464
|
-
};
|
|
1465
|
-
}
|
|
1466
|
-
});
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
|
|
1471
|
-
return json;
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
|
-
System.isSystem = true;
|
|
1476
|
-
System.getName = function () {
|
|
1477
|
-
return this.displayName || this.name;
|
|
1478
|
-
};
|
|
1479
|
-
|
|
1480
|
-
function Not(Component) {
|
|
1481
|
-
return {
|
|
1482
|
-
operator: "not",
|
|
1483
|
-
Component: Component,
|
|
1484
|
-
};
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
class TagComponent extends Component {
|
|
1488
|
-
constructor() {
|
|
1489
|
-
super(false);
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
TagComponent.isTagComponent = true;
|
|
1494
|
-
|
|
1495
|
-
const copyValue = (src) => src;
|
|
1496
|
-
|
|
1497
|
-
const cloneValue = (src) => src;
|
|
1498
|
-
|
|
1499
|
-
const copyArray = (src, dest) => {
|
|
1500
|
-
if (!src) {
|
|
1501
|
-
return src;
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
if (!dest) {
|
|
1505
|
-
return src.slice();
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
dest.length = 0;
|
|
1509
|
-
|
|
1510
|
-
for (let i = 0; i < src.length; i++) {
|
|
1511
|
-
dest.push(src[i]);
|
|
1512
|
-
}
|
|
1513
|
-
|
|
1514
|
-
return dest;
|
|
1515
|
-
};
|
|
1516
|
-
|
|
1517
|
-
const cloneArray = (src) => src && src.slice();
|
|
1518
|
-
|
|
1519
|
-
const copyJSON = (src) => JSON.parse(JSON.stringify(src));
|
|
1520
|
-
|
|
1521
|
-
const cloneJSON = (src) => JSON.parse(JSON.stringify(src));
|
|
1522
|
-
|
|
1523
|
-
const copyCopyable = (src, dest) => {
|
|
1524
|
-
if (!src) {
|
|
1525
|
-
return src;
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
|
-
if (!dest) {
|
|
1529
|
-
return src.clone();
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1532
|
-
return dest.copy(src);
|
|
1533
|
-
};
|
|
1534
|
-
|
|
1535
|
-
const cloneClonable = (src) => src && src.clone();
|
|
1536
|
-
|
|
1537
|
-
function createType(typeDefinition) {
|
|
1538
|
-
var mandatoryProperties = ["name", "default", "copy", "clone"];
|
|
1539
|
-
|
|
1540
|
-
var undefinedProperties = mandatoryProperties.filter((p) => {
|
|
1541
|
-
return !typeDefinition.hasOwnProperty(p);
|
|
1542
|
-
});
|
|
1543
|
-
|
|
1544
|
-
if (undefinedProperties.length > 0) {
|
|
1545
|
-
throw new Error(
|
|
1546
|
-
`createType expects a type definition with the following properties: ${undefinedProperties.join(
|
|
1547
|
-
", "
|
|
1548
|
-
)}`
|
|
1549
|
-
);
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
typeDefinition.isType = true;
|
|
1553
|
-
|
|
1554
|
-
return typeDefinition;
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
/**
|
|
1558
|
-
* Standard types
|
|
1559
|
-
*/
|
|
1560
|
-
const Types = {
|
|
1561
|
-
Number: createType({
|
|
1562
|
-
name: "Number",
|
|
1563
|
-
default: 0,
|
|
1564
|
-
copy: copyValue,
|
|
1565
|
-
clone: cloneValue,
|
|
1566
|
-
}),
|
|
1567
|
-
|
|
1568
|
-
Boolean: createType({
|
|
1569
|
-
name: "Boolean",
|
|
1570
|
-
default: false,
|
|
1571
|
-
copy: copyValue,
|
|
1572
|
-
clone: cloneValue,
|
|
1573
|
-
}),
|
|
1574
|
-
|
|
1575
|
-
String: createType({
|
|
1576
|
-
name: "String",
|
|
1577
|
-
default: "",
|
|
1578
|
-
copy: copyValue,
|
|
1579
|
-
clone: cloneValue,
|
|
1580
|
-
}),
|
|
1581
|
-
|
|
1582
|
-
Array: createType({
|
|
1583
|
-
name: "Array",
|
|
1584
|
-
default: [],
|
|
1585
|
-
copy: copyArray,
|
|
1586
|
-
clone: cloneArray,
|
|
1587
|
-
}),
|
|
1588
|
-
|
|
1589
|
-
Ref: createType({
|
|
1590
|
-
name: "Ref",
|
|
1591
|
-
default: undefined,
|
|
1592
|
-
copy: copyValue,
|
|
1593
|
-
clone: cloneValue,
|
|
1594
|
-
}),
|
|
1595
|
-
|
|
1596
|
-
JSON: createType({
|
|
1597
|
-
name: "JSON",
|
|
1598
|
-
default: null,
|
|
1599
|
-
copy: copyJSON,
|
|
1600
|
-
clone: cloneJSON,
|
|
1601
|
-
}),
|
|
1602
|
-
};
|
|
1603
|
-
|
|
1604
|
-
function generateId(length) {
|
|
1605
|
-
var result = "";
|
|
1606
|
-
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
1607
|
-
var charactersLength = characters.length;
|
|
1608
|
-
for (var i = 0; i < length; i++) {
|
|
1609
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
1610
|
-
}
|
|
1611
|
-
return result;
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
function injectScript(src, onLoad) {
|
|
1615
|
-
var script = document.createElement("script");
|
|
1616
|
-
// @todo Use link to the ecsy-devtools repo?
|
|
1617
|
-
script.src = src;
|
|
1618
|
-
script.onload = onLoad;
|
|
1619
|
-
(document.head || document.documentElement).appendChild(script);
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
/* global Peer */
|
|
1623
|
-
|
|
1624
|
-
function hookConsoleAndErrors(connection) {
|
|
1625
|
-
var wrapFunctions = ["error", "warning", "log"];
|
|
1626
|
-
wrapFunctions.forEach((key) => {
|
|
1627
|
-
if (typeof console[key] === "function") {
|
|
1628
|
-
var fn = console[key].bind(console);
|
|
1629
|
-
console[key] = (...args) => {
|
|
1630
|
-
connection.send({
|
|
1631
|
-
method: "console",
|
|
1632
|
-
type: key,
|
|
1633
|
-
args: JSON.stringify(args),
|
|
1634
|
-
});
|
|
1635
|
-
return fn.apply(null, args);
|
|
1636
|
-
};
|
|
1637
|
-
}
|
|
1638
|
-
});
|
|
1639
|
-
|
|
1640
|
-
window.addEventListener("error", (error) => {
|
|
1641
|
-
connection.send({
|
|
1642
|
-
method: "error",
|
|
1643
|
-
error: JSON.stringify({
|
|
1644
|
-
message: error.error.message,
|
|
1645
|
-
stack: error.error.stack,
|
|
1646
|
-
}),
|
|
1647
|
-
});
|
|
1648
|
-
});
|
|
1649
|
-
}
|
|
1650
|
-
|
|
1651
|
-
function includeRemoteIdHTML(remoteId) {
|
|
1652
|
-
let infoDiv = document.createElement("div");
|
|
1653
|
-
infoDiv.style.cssText = `
|
|
1654
|
-
align-items: center;
|
|
1655
|
-
background-color: #333;
|
|
1656
|
-
color: #aaa;
|
|
1657
|
-
display:flex;
|
|
1658
|
-
font-family: Arial;
|
|
1659
|
-
font-size: 1.1em;
|
|
1660
|
-
height: 40px;
|
|
1661
|
-
justify-content: center;
|
|
1662
|
-
left: 0;
|
|
1663
|
-
opacity: 0.9;
|
|
1664
|
-
position: absolute;
|
|
1665
|
-
right: 0;
|
|
1666
|
-
text-align: center;
|
|
1667
|
-
top: 0;
|
|
1668
|
-
`;
|
|
1669
|
-
|
|
1670
|
-
infoDiv.innerHTML = `Open ECSY devtools to connect to this page using the code: <b style="color: #fff">${remoteId}</b> <button onClick="generateNewCode()">Generate new code</button>`;
|
|
1671
|
-
document.body.appendChild(infoDiv);
|
|
1672
|
-
|
|
1673
|
-
return infoDiv;
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
|
-
function enableRemoteDevtools(remoteId) {
|
|
1677
|
-
if (!hasWindow) {
|
|
1678
|
-
console.warn("Remote devtools not available outside the browser");
|
|
1679
|
-
return;
|
|
1680
|
-
}
|
|
1681
|
-
|
|
1682
|
-
window.generateNewCode = () => {
|
|
1683
|
-
window.localStorage.clear();
|
|
1684
|
-
remoteId = generateId(6);
|
|
1685
|
-
window.localStorage.setItem("ecsyRemoteId", remoteId);
|
|
1686
|
-
window.location.reload(false);
|
|
1687
|
-
};
|
|
1688
|
-
|
|
1689
|
-
remoteId = remoteId || window.localStorage.getItem("ecsyRemoteId");
|
|
1690
|
-
if (!remoteId) {
|
|
1691
|
-
remoteId = generateId(6);
|
|
1692
|
-
window.localStorage.setItem("ecsyRemoteId", remoteId);
|
|
1693
|
-
}
|
|
1694
|
-
|
|
1695
|
-
let infoDiv = includeRemoteIdHTML(remoteId);
|
|
1696
|
-
|
|
1697
|
-
window.__ECSY_REMOTE_DEVTOOLS_INJECTED = true;
|
|
1698
|
-
window.__ECSY_REMOTE_DEVTOOLS = {};
|
|
1699
|
-
|
|
1700
|
-
let Version = "";
|
|
1701
|
-
|
|
1702
|
-
// This is used to collect the worlds created before the communication is being established
|
|
1703
|
-
let worldsBeforeLoading = [];
|
|
1704
|
-
let onWorldCreated = (e) => {
|
|
1705
|
-
var world = e.detail.world;
|
|
1706
|
-
Version = e.detail.version;
|
|
1707
|
-
worldsBeforeLoading.push(world);
|
|
1708
|
-
};
|
|
1709
|
-
window.addEventListener("ecsy-world-created", onWorldCreated);
|
|
1710
|
-
|
|
1711
|
-
let onLoaded = () => {
|
|
1712
|
-
// var peer = new Peer(remoteId);
|
|
1713
|
-
var peer = new Peer(remoteId, {
|
|
1714
|
-
host: "peerjs.ecsy.io",
|
|
1715
|
-
secure: true,
|
|
1716
|
-
port: 443,
|
|
1717
|
-
config: {
|
|
1718
|
-
iceServers: [
|
|
1719
|
-
{ url: "stun:stun.l.google.com:19302" },
|
|
1720
|
-
{ url: "stun:stun1.l.google.com:19302" },
|
|
1721
|
-
{ url: "stun:stun2.l.google.com:19302" },
|
|
1722
|
-
{ url: "stun:stun3.l.google.com:19302" },
|
|
1723
|
-
{ url: "stun:stun4.l.google.com:19302" },
|
|
1724
|
-
],
|
|
1725
|
-
},
|
|
1726
|
-
debug: 3,
|
|
1727
|
-
});
|
|
1728
|
-
|
|
1729
|
-
peer.on("open", (/* id */) => {
|
|
1730
|
-
peer.on("connection", (connection) => {
|
|
1731
|
-
window.__ECSY_REMOTE_DEVTOOLS.connection = connection;
|
|
1732
|
-
connection.on("open", function () {
|
|
1733
|
-
// infoDiv.style.visibility = "hidden";
|
|
1734
|
-
infoDiv.innerHTML = "Connected";
|
|
1735
|
-
|
|
1736
|
-
// Receive messages
|
|
1737
|
-
connection.on("data", function (data) {
|
|
1738
|
-
if (data.type === "init") {
|
|
1739
|
-
var script = document.createElement("script");
|
|
1740
|
-
script.setAttribute("type", "text/javascript");
|
|
1741
|
-
script.onload = () => {
|
|
1742
|
-
script.parentNode.removeChild(script);
|
|
1743
|
-
|
|
1744
|
-
// Once the script is injected we don't need to listen
|
|
1745
|
-
window.removeEventListener(
|
|
1746
|
-
"ecsy-world-created",
|
|
1747
|
-
onWorldCreated
|
|
1748
|
-
);
|
|
1749
|
-
worldsBeforeLoading.forEach((world) => {
|
|
1750
|
-
var event = new CustomEvent("ecsy-world-created", {
|
|
1751
|
-
detail: { world: world, version: Version },
|
|
1752
|
-
});
|
|
1753
|
-
window.dispatchEvent(event);
|
|
1754
|
-
});
|
|
1755
|
-
};
|
|
1756
|
-
script.innerHTML = data.script;
|
|
1757
|
-
(document.head || document.documentElement).appendChild(script);
|
|
1758
|
-
script.onload();
|
|
1759
|
-
|
|
1760
|
-
hookConsoleAndErrors(connection);
|
|
1761
|
-
} else if (data.type === "executeScript") {
|
|
1762
|
-
let value = eval(data.script);
|
|
1763
|
-
if (data.returnEval) {
|
|
1764
|
-
connection.send({
|
|
1765
|
-
method: "evalReturn",
|
|
1766
|
-
value: value,
|
|
1767
|
-
});
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
});
|
|
1771
|
-
});
|
|
1772
|
-
});
|
|
1773
|
-
});
|
|
1774
|
-
};
|
|
1775
|
-
|
|
1776
|
-
// Inject PeerJS script
|
|
1777
|
-
injectScript(
|
|
1778
|
-
"https://cdn.jsdelivr.net/npm/peerjs@0.3.20/dist/peer.min.js",
|
|
1779
|
-
onLoaded
|
|
1780
|
-
);
|
|
1781
|
-
}
|
|
1782
|
-
|
|
1783
|
-
if (hasWindow) {
|
|
1784
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
1785
|
-
|
|
1786
|
-
// @todo Provide a way to disable it if needed
|
|
1787
|
-
if (urlParams.has("enable-remote-devtools")) {
|
|
1788
|
-
enableRemoteDevtools();
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
|
-
export { Component, Not, ObjectPool, System, SystemStateComponent, TagComponent, Types, Version, World, Entity as _Entity, cloneArray, cloneClonable, cloneJSON, cloneValue, copyArray, copyCopyable, copyJSON, copyValue, createType, enableRemoteDevtools };
|