Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaxiangfeng committed Oct 24, 2022
1 parent e0fd522 commit c3d4379
Show file tree
Hide file tree
Showing 30 changed files with 488 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# react-3d-model
# react-3dmodelx

> 3D models viewer with react.js。文档地址:https://xiaxiangfeng.github.io/react-3d-model/index.html#/
Expand All @@ -7,14 +7,14 @@
## 从 NPM 下载包

```npm
npm i react-3d-model
npm i react-3dmodelx
```

## Basic usage

```tsx
import React from 'react';
import Model from 'react-3d-model';
import Model from 'react-3dmodelx';

export default () => (
<div style={{ maxWidth: 800, width: '100%', height: 400, margin: 'auto' }}>
Expand Down
7 changes: 7 additions & 0 deletions dist/esm/Collada/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';
declare const _default: React.ForwardRefExoticComponent<{
src: string;
backgroundColor: string;
isRotation?: boolean | undefined;
} & React.RefAttributes<unknown>>;
export default _default;
52 changes: 52 additions & 0 deletions dist/esm/Collada/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { useRef, useEffect, useImperativeHandle, forwardRef } from 'react';
import * as THREE from 'three';
import { ColladaLoader } from 'three/examples/jsm/loaders/ColladaLoader';
import useScene from "../useScene";

function Collada(_ref, ref) {
var src = _ref.src,
backgroundColor = _ref.backgroundColor,
isRotation = _ref.isRotation;
var canvasRef = useRef(null);

var _useScene = useScene(canvasRef, backgroundColor, isRotation),
add2Scene = _useScene.add2Scene,
scene = _useScene.scene,
animate = _useScene.animate,
renderer = _useScene.renderer,
render = _useScene.render;

useImperativeHandle(ref, function () {
return {
getSnapshot: function getSnapshot() {
var _renderer$current;

render();
return (_renderer$current = renderer.current) === null || _renderer$current === void 0 ? void 0 : _renderer$current.domElement.toDataURL('image/png', 1);
}
};
});
useEffect(function () {
var _scene$current, _scene$current2;

var ambientLight = new THREE.AmbientLight(0xcccccc, 0.4);
(_scene$current = scene.current) === null || _scene$current === void 0 ? void 0 : _scene$current.add(ambientLight);
var directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(1, 1, 0).normalize();
(_scene$current2 = scene.current) === null || _scene$current2 === void 0 ? void 0 : _scene$current2.add(directionalLight);
var loader = new ColladaLoader();
loader.load(src, function (data) {
add2Scene(data.scene);
animate();
});
}, []);
return /*#__PURE__*/React.createElement("canvas", {
ref: canvasRef,
style: {
width: '100%',
height: '100%'
}
});
}

export default /*#__PURE__*/forwardRef(Collada);
6 changes: 6 additions & 0 deletions dist/esm/FBX/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
declare const _default: React.ForwardRefExoticComponent<{
src: string;
backgroundColor: string;
} & React.RefAttributes<unknown>>;
export default _default;
51 changes: 51 additions & 0 deletions dist/esm/FBX/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { useRef, useEffect, useImperativeHandle, forwardRef } from 'react';
import * as THREE from 'three';
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader';
import useScene from "../useScene";

function FBX(_ref, ref) {
var src = _ref.src,
backgroundColor = _ref.backgroundColor;
var canvasRef = useRef(null);

var _useScene = useScene(canvasRef, backgroundColor),
add2Scene = _useScene.add2Scene,
scene = _useScene.scene,
animate = _useScene.animate,
renderer = _useScene.renderer,
render = _useScene.render;

useImperativeHandle(ref, function () {
return {
getSnapshot: function getSnapshot() {
var _renderer$current;

render();
return (_renderer$current = renderer.current) === null || _renderer$current === void 0 ? void 0 : _renderer$current.domElement.toDataURL('image/png', 1);
}
};
});
useEffect(function () {
var _scene$current, _scene$current2;

var ambientLight = new THREE.AmbientLight(0xcccccc, 0.4);
(_scene$current = scene.current) === null || _scene$current === void 0 ? void 0 : _scene$current.add(ambientLight);
var directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(1, 1, 0).normalize();
(_scene$current2 = scene.current) === null || _scene$current2 === void 0 ? void 0 : _scene$current2.add(directionalLight);
var loader = new FBXLoader();
loader.load(src, function (data) {
add2Scene(data);
animate();
});
}, []);
return /*#__PURE__*/React.createElement("canvas", {
ref: canvasRef,
style: {
width: '100%',
height: '100%'
}
});
}

export default /*#__PURE__*/forwardRef(FBX);
6 changes: 6 additions & 0 deletions dist/esm/GLTF/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
declare const _default: React.ForwardRefExoticComponent<{
src: string;
backgroundColor: string;
} & React.RefAttributes<unknown>>;
export default _default;
47 changes: 47 additions & 0 deletions dist/esm/GLTF/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useRef, useEffect, useImperativeHandle, forwardRef } from 'react';
import * as THREE from 'three';
import { RoomEnvironment } from 'three/examples/jsm/environments/RoomEnvironment.js';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import useScene from "../useScene";

function GLTF(_ref, ref) {
var src = _ref.src,
backgroundColor = _ref.backgroundColor;
var canvasRef = useRef(null);

var _useScene = useScene(canvasRef, backgroundColor),
add2Scene = _useScene.add2Scene,
scene = _useScene.scene,
renderer = _useScene.renderer,
render = _useScene.render;

useImperativeHandle(ref, function () {
return {
getSnapshot: function getSnapshot() {
var _renderer$current;

render();
return (_renderer$current = renderer.current) === null || _renderer$current === void 0 ? void 0 : _renderer$current.domElement.toDataURL('image/png', 1);
}
};
});
useEffect(function () {
var environment = new RoomEnvironment();
var pmremGenerator = new THREE.PMREMGenerator(renderer.current);
scene.current && (scene.current.environment = pmremGenerator.fromScene(environment, 0.04).texture);
var loader = new GLTFLoader();
loader.load(src, function (gltf) {
add2Scene(gltf.scene);
render();
});
}, []);
return /*#__PURE__*/React.createElement("canvas", {
ref: canvasRef,
style: {
width: '100%',
height: '100%'
}
});
}

export default /*#__PURE__*/forwardRef(GLTF);
6 changes: 6 additions & 0 deletions dist/esm/OBJ/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
declare const _default: React.ForwardRefExoticComponent<{
src: string;
backgroundColor: string;
} & React.RefAttributes<unknown>>;
export default _default;
51 changes: 51 additions & 0 deletions dist/esm/OBJ/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { useRef, useEffect, useImperativeHandle, forwardRef } from 'react';
import * as THREE from 'three';
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader';
import useScene from "../useScene";

function OBJ(_ref, ref) {
var src = _ref.src,
backgroundColor = _ref.backgroundColor;
var canvasRef = useRef(null);

var _useScene = useScene(canvasRef, backgroundColor),
add2Scene = _useScene.add2Scene,
scene = _useScene.scene,
animate = _useScene.animate,
render = _useScene.render,
renderer = _useScene.renderer;

useImperativeHandle(ref, function () {
return {
getSnapshot: function getSnapshot() {
var _renderer$current;

render();
return (_renderer$current = renderer.current) === null || _renderer$current === void 0 ? void 0 : _renderer$current.domElement.toDataURL('image/png', 1);
}
};
});
useEffect(function () {
var _scene$current, _scene$current2;

var ambientLight = new THREE.AmbientLight(0xcccccc, 0.4);
(_scene$current = scene.current) === null || _scene$current === void 0 ? void 0 : _scene$current.add(ambientLight);
var directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(1, 1, 0).normalize();
(_scene$current2 = scene.current) === null || _scene$current2 === void 0 ? void 0 : _scene$current2.add(directionalLight);
var loader = new OBJLoader();
loader.load(src, function (data) {
add2Scene(data);
animate();
});
}, []);
return /*#__PURE__*/React.createElement("canvas", {
ref: canvasRef,
style: {
width: '100%',
height: '100%'
}
});
}

export default /*#__PURE__*/forwardRef(OBJ);
5 changes: 5 additions & 0 deletions dist/esm/PLY/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare function PLY({ src, backgroundColor }: {
src: string;
backgroundColor: string;
}): JSX.Element;
export default PLY;
42 changes: 42 additions & 0 deletions dist/esm/PLY/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { useRef, useEffect } from 'react';
import * as THREE from 'three';
import { PLYLoader } from 'three/examples/jsm/loaders/PLYLoader';
import useScene from "../useScene";

function PLY(_ref) {
var src = _ref.src,
backgroundColor = _ref.backgroundColor;
var canvasRef = useRef(null);

var _useScene = useScene(canvasRef, backgroundColor),
add2Scene = _useScene.add2Scene,
scene = _useScene.scene,
animate = _useScene.animate;

useEffect(function () {
var _scene$current, _scene$current2;

var ambientLight = new THREE.AmbientLight(0xcccccc, 0.4);
(_scene$current = scene.current) === null || _scene$current === void 0 ? void 0 : _scene$current.add(ambientLight);
var directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(1, 1, 0).normalize();
(_scene$current2 = scene.current) === null || _scene$current2 === void 0 ? void 0 : _scene$current2.add(directionalLight);
var loader = new PLYLoader();
loader.load(src, function (geometry) {
geometry.computeVertexNormals();
var material = new THREE.MeshStandardMaterial();
var mesh = new THREE.Mesh(geometry, material);
add2Scene(mesh);
animate();
});
}, []);
return /*#__PURE__*/React.createElement("canvas", {
ref: canvasRef,
style: {
width: '100%',
height: '100%'
}
});
}

export default PLY;
5 changes: 5 additions & 0 deletions dist/esm/STL/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare function STL({ src, backgroundColor }: {
src: string;
backgroundColor: string;
}): JSX.Element;
export default STL;
41 changes: 41 additions & 0 deletions dist/esm/STL/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useRef, useEffect } from 'react';
import * as THREE from 'three';
import { STLLoader } from 'three/examples/jsm/loaders/STLLoader';
import useScene from "../useScene";

function STL(_ref) {
var src = _ref.src,
backgroundColor = _ref.backgroundColor;
var canvasRef = useRef(null);

var _useScene = useScene(canvasRef, backgroundColor),
add2Scene = _useScene.add2Scene,
scene = _useScene.scene,
animate = _useScene.animate;

useEffect(function () {
var _scene$current, _scene$current2;

var ambientLight = new THREE.AmbientLight(0xcccccc, 0.4);
(_scene$current = scene.current) === null || _scene$current === void 0 ? void 0 : _scene$current.add(ambientLight);
var directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(1, 1, 0).normalize();
(_scene$current2 = scene.current) === null || _scene$current2 === void 0 ? void 0 : _scene$current2.add(directionalLight);
var loader = new STLLoader();
loader.load(src, function (geometry) {
var material = new THREE.MeshStandardMaterial();
var mesh = new THREE.Mesh(geometry, material);
add2Scene(mesh);
animate();
});
}, []);
return /*#__PURE__*/React.createElement("canvas", {
ref: canvasRef,
style: {
width: '100%',
height: '100%'
}
});
}

export default STL;
24 changes: 24 additions & 0 deletions dist/esm/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import PLY from './PLY';
import STL from './STL';
declare const _default: {
GLTF: import("react").ForwardRefExoticComponent<{
src: string;
backgroundColor: string;
} & import("react").RefAttributes<unknown>>;
Collada: import("react").ForwardRefExoticComponent<{
src: string;
backgroundColor: string;
isRotation?: boolean | undefined;
} & import("react").RefAttributes<unknown>>;
FBX: import("react").ForwardRefExoticComponent<{
src: string;
backgroundColor: string;
} & import("react").RefAttributes<unknown>>;
OBJ: import("react").ForwardRefExoticComponent<{
src: string;
backgroundColor: string;
} & import("react").RefAttributes<unknown>>;
PLY: typeof PLY;
STL: typeof STL;
};
export default _default;
Loading

0 comments on commit c3d4379

Please sign in to comment.