Skip to content

Commit

Permalink
Bug/three examples dependencies (#20)
Browse files Browse the repository at this point in the history
* included imported three examples into the bundle

* sync three examples script

* script bugfix

* added libs build command to PR CI
  • Loading branch information
AndyGura authored Nov 26, 2024
1 parent ca1bf64 commit e4f8200
Show file tree
Hide file tree
Showing 23 changed files with 831 additions and 21 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/pull_request_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,22 @@ jobs:
working-directory: ./packages/ammo
run: npm run build && npm run test

- name: Build matter
working-directory: ./packages/matter
run: npm run build

- name: Build pixi
working-directory: ./packages/pixi
run: npm run build

- name: Test rapier2d
working-directory: ./packages/rapier2d
run: npm run build && npm run test

- name: Test rapier3d
working-directory: ./packages/rapier3d
run: npm run build && npm run test

- name: Build three
working-directory: ./packages/three
run: npm run build
1 change: 1 addition & 0 deletions packages/three/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
etc
src
18 changes: 18 additions & 0 deletions packages/three/etc/sync_three_examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
SOURCE_A="./node_modules/three/examples/jsm"
SOURCE_B="./node_modules/@types/three/examples/jsm"
TARGET="./src/three-examples"

update_files() {
local source_dir=$1
find "$TARGET" -type f | while IFS= read -r target_file; do
relative_path="${target_file#$TARGET/}"
source_file="$source_dir/$relative_path"
if [[ -f "$source_file" ]]; then
cp "$source_file" "$target_file"
fi
done
}

update_files "$SOURCE_A"
update_files "$SOURCE_B"
6 changes: 3 additions & 3 deletions packages/three/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prettier-format": "prettier --config ../core/.prettierrc 'src/**/*.ts' --write",
"prepublish": "rm -rf ./dist/ && tsc && cp -R ./src/gltf-loader ./dist",
"sync-gltf-loader": "cp ./node_modules/three/examples/jsm/loaders/GLTFLoader.js ./src/gltf-loader && cp ./node_modules/@types/three/examples/jsm/loaders/GLTFLoader.d.ts ./src/gltf-loader && cp ./node_modules/three/examples/jsm/utils/BufferGeometryUtils.js ./src/gltf-loader && cp ./node_modules/@types/three/examples/jsm/utils/BufferGeometryUtils.d.ts ./src/gltf-loader",
"build": "tsc && cp -R ./src/gltf-loader ./dist"
"prepublish": "rm -rf ./dist/ && tsc && cp -R ./src/three-examples ./dist",
"sync-three-examples": "sh ./etc/sync_three_examples.sh && npm run prettier-format",
"build": "tsc && cp -R ./src/three-examples ./dist"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { WebGLRendererParameters } from 'three';
import { ThreeSceneComponent } from './three-scene.component';
import { ThreeCameraComponent } from './three-camera.component';
import { ThreeVisualTypeDocRepo } from '../types';
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer';
import { EffectComposer } from 'three-examples/postprocessing/EffectComposer';
import { ThreeRendererComponent } from './three-renderer.component';
import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass';
import { RenderPass } from 'three-examples/postprocessing/RenderPass';

export class ThreeComposerRendererComponent extends ThreeRendererComponent {
public readonly nativeComposer: EffectComposer;
Expand Down
10 changes: 9 additions & 1 deletion packages/three/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './gltf-loader/GLTFLoader';
export * from './components/three-display-object.component';
export * from './components/three-scene.component';
export * from './components/three-renderer.component';
Expand All @@ -7,3 +6,12 @@ export * from './components/three-camera.component';
export * from './three-factory';
export * from './three-loader';
export * from './types';

export * from './three-examples/loaders/GLTFLoader';
export * from './three-examples/postprocessing/EffectComposer';
export * from './three-examples/postprocessing/MaskPass';
export * from './three-examples/postprocessing/Pass';
export * from './three-examples/postprocessing/RenderPass';
export * from './three-examples/postprocessing/ShaderPass';
export * from './three-examples/shaders/CopyShader';
export * from './three-examples/utils/BufferGeometryUtils';
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import {
SRGBColorSpace,
InstancedBufferAttribute
} from 'three';
import { toTrianglesDrawMode } from './BufferGeometryUtils';
import { toTrianglesDrawMode } from '../utils/BufferGeometryUtils.js';

class GLTFLoader extends Loader {

Expand Down Expand Up @@ -544,8 +544,8 @@ class GLTFLightsExtension {
const nodeDef = nodeDefs[ nodeIndex ];

if ( nodeDef.extensions
&& nodeDef.extensions[ this.name ]
&& nodeDef.extensions[ this.name ].light !== undefined ) {
&& nodeDef.extensions[ this.name ]
&& nodeDef.extensions[ this.name ].light !== undefined ) {

parser._addNodeRef( this.cache, nodeDef.extensions[ this.name ].light );

Expand Down Expand Up @@ -1723,9 +1723,9 @@ class GLTFMeshGpuInstancing {
for ( const primitive of meshDef.primitives ) {

if ( primitive.mode !== WEBGL_CONSTANTS.TRIANGLES &&
primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP &&
primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN &&
primitive.mode !== undefined ) {
primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP &&
primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN &&
primitive.mode !== undefined ) {

return null;

Expand Down Expand Up @@ -1810,8 +1810,8 @@ class GLTFMeshGpuInstancing {
instancedMesh.instanceColor = new InstancedBufferAttribute( attr.array, attr.itemSize, attr.normalized );

} else if ( attributeName !== 'TRANSLATION' &&
attributeName !== 'ROTATION' &&
attributeName !== 'SCALE' ) {
attributeName !== 'ROTATION' &&
attributeName !== 'SCALE' ) {

mesh.geometry.setAttribute( attributeName, attributes[ attributeName ] );

Expand Down Expand Up @@ -2252,7 +2252,7 @@ const PATH_PROPERTIES = {

const INTERPOLATION = {
CUBICSPLINE: undefined, // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
// keyframe track will be initialized with a default interpolation type, then modified.
// keyframe track will be initialized with a default interpolation type, then modified.
LINEAR: InterpolateLinear,
STEP: InterpolateDiscrete
};
Expand Down Expand Up @@ -2466,8 +2466,8 @@ function createPrimitiveKey( primitiveDef ) {
if ( dracoExtension ) {

geometryKey = 'draco:' + dracoExtension.bufferView
+ ':' + dracoExtension.indices
+ ':' + createAttributesKey( dracoExtension.attributes );
+ ':' + dracoExtension.indices
+ ':' + createAttributesKey( dracoExtension.attributes );

} else {

Expand Down Expand Up @@ -3790,9 +3790,9 @@ class GLTFParser {
const material = materials[ i ];

if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLES ||
primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ||
primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ||
primitive.mode === undefined ) {
primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ||
primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ||
primitive.mode === undefined ) {

// .isSkinnedMesh isn't in glTF spec. See ._markDefs()
mesh = meshDef.isSkinnedMesh === true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Clock, WebGLRenderer, WebGLRenderTarget } from 'three';

import { FullScreenQuad, Pass } from './Pass.js';
import { ShaderPass } from './ShaderPass.js';

export { FullScreenQuad } from './Pass.js';
export { Pass };

export class EffectComposer {
constructor(renderer: WebGLRenderer, renderTarget?: WebGLRenderTarget);
renderer: WebGLRenderer;
renderTarget1: WebGLRenderTarget;
renderTarget2: WebGLRenderTarget;
writeBuffer: WebGLRenderTarget;
readBuffer: WebGLRenderTarget;
passes: Pass[];
copyPass: ShaderPass;
clock: Clock;
renderToScreen: boolean;

swapBuffers(): void;
addPass(pass: Pass): void;
insertPass(pass: Pass, index: number): void;
removePass(pass: Pass): void;
isLastEnabledPass(passIndex: number): boolean;
render(deltaTime?: number): void;
reset(renderTarget?: WebGLRenderTarget): void;
setSize(width: number, height: number): void;
setPixelRatio(pixelRatio: number): void;
dispose(): void;
}
Loading

0 comments on commit e4f8200

Please sign in to comment.