ThreeJS 入门 这是一个适用于 ThreeJS 应用程序的通用模板。它使用以下包: - ViteJS v8 - ThreeJS v0.185.1 - TypeScript v3.7.2 - Vue.js v2.6.11 - Vuex v2.4.1 - Vue-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v
ThreeJS 入门 这是一个适用于 ThreeJS 应用程序的通用模板。它使用以下包: - ViteJS v8 - ThreeJS v0.185.1 - TypeScript v3.7.2 - Vue.js v2.6.11 - Vuex v2.4.1 - Vue-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v2.4.1 - Vuex-Router v
This is a general template for ThreeJS applications. It uses the following packages:
This has been developed with NodeJS 24.
$ pnpm installRun
$ pnpm devthen open a new browser window and navigate to http://localhost:5173
$ pnpm buildThe WebGL entry files is located in /src/webgl/index.ts. It initializes a basic scene with a few meshes and all the basic stuff needed to run the scene.
All materials are located in /src/webgl/materials. All the pre-existing materials are THREE.NodeMaterial instances to take advantage of their node architecture, but feel free to use a regular THREE.Material instance if you prefer.
All meshes have assigned multiple three-start components, which are located in /src/webgl/behaviors.
Check the three-start documentation for more information on how to create a new component.
The starter is intialized with a few pre-defined modules, which are located in /src/webgl/modules.
Such modules are:
AssetLoaderModule: loads assets from the filesystemOrbitControlsModule: adds orbit controls to the cameraPhysicsModule: adds physics to the sceneInspectorModule: adds a GUI to the sceneWhen creating a new module remember to add it to the ThreeStartRegister interface in /src/types.d.ts.
Check the three-start documentation for more information on how to create a new module.
This starter uses the built-in Inspector from ThreeJS to add a GUI to the scene and inspect all the render passes.
It is initialized in its own module, which is located in /src/webgl/modules/Inspector.ts.
Check the many ThreeJS examples for more examples on how to add new fields to the GUI.
Physics is managed by the PhysicsModule, which is located in /src/webgl/modules/Physics.ts. It uses the crashcat physics engine.
The whole simulation is inizialized by the PhysicsModule. If you don't need physics, just remove it from the modules list in /src/webgl/index.ts.
The available rigid body types are located in /src/webgl/behaviors/physics/ and are:
BoxSphereTriangle (ideal for static meshes, i.e. terrains)ConvexHull (ideal for dynamic/kinematic meshes)A body type can be assigned to a mesh as a three-start component
import { addComponent } from 'three-start'
import { BodyBox } from './behaviors/physics'
import { type BodyParams as BodyBoxParams } from './behaviors/physics/BodyBox'
import type { RigidBodySettings } from 'crashcat'
// ...
const cube = new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshBasicMaterial({ color: 0x00ff00 }),
)
addComponent(
cube,
BodyBox,
{
motionType: MotionType.DYNAMIC,
restitution: 0.2,
friction: 0.3,
mass: 1,
} as RigidBodySettings,
{
width: 1,
height: 1,
depth: 1,
} as BodyBoxParams,
)
scene.add(cube)The third argument passed to addComponent is the crashcat's rigid body settings.
Assets are loaded by the AssetLoaderModule, which is located in /src/webgl/modules/AssetLoader.ts.
The module can load both textures and models. when loaded, each file is stored in an internal map by its filename.
const { modules } = starter.ctx
// ...
// Load modules and textures
await modules.assetLoader.loadTexture('path/to/my-texture.png')
await modules.assetLoader.loadModel('path/to/my-model.glb')
// ...
// Get a specific model or texture by filename
const texture = modules.assetLoader.getTexture('my-texture')
const model = modules.assetLoader.getModel('my-model')暂无开放 Issues,或尚未同步最近议题。