hpg-r3f-model-scene
Version:
Pretty Footer react component used in ant.design
84 lines (83 loc) • 3.19 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React, { useEffect, useRef } from 'react';
import { useFrame } from '@react-three/fiber';
import { getNodeWith } from '../../utils';
import { getMaterialByJson } from '../../utils/gltf';
import { useEventBus } from '../../common/events';
import { MaterialFunc } from '../../utils/enums';
import { setMaterialActions, setMaterialOnMessage } from '../../utils/setMaterial';
var inode;
var Earth = function Earth(props) {
var material = props.material,
materialChange = props.materialChange,
exportScene = props.exportScene;
// const [colorMapDefault, normalMapDefault] = useLoader(TextureLoader, [
// 'https://oss-sxt.51ygp.com/statics/images/8k_earth_daymap.jpg',
// 'https://oss-sxt.51ygp.com/statics/images/8k_earth_normal_map.jpg',
// ]);
var earthRef = useRef(null);
useFrame(function (_ref) {
var clock = _ref.clock;
} // const elapsedTime = clock.getElapsedTime();
// console.log(earthRef.current, 'earthRef.current');
// earthRef.current.rotation.y = elapsedTime / 6;
);
var onMaterialChange = function onMaterialChange(node) {
if (materialChange) {
materialChange(node);
}
};
// const physicalMaterial = new MeshPhysicalMaterial({
// color: new Color(material.color),
// });
// const physicalMaterial = new MeshPhysicalMaterial();
useEffect(function () {
// material.color = new Color('#ff0000');
// console.log(material1.toJSON(), 'earthRef.current', earthRef.current);
getMaterialByJson(material).then(function (_physicalMaterial) {
earthRef.current.material = _physicalMaterial;
inode = getNodeWith(_physicalMaterial);
onMaterialChange(inode);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
var getMaterial = function getMaterial() {
return earthRef.current.material;
};
/* 对发出来的事件进行监听 */
var _useEventBus = useEventBus;
setMaterialActions.forEach(function (d) {
_useEventBus(d, /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
var result;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return setMaterialOnMessage(d, getMaterial(), params);
case 2:
result = _context.sent;
if (d === MaterialFunc.EXPORT_SCENE) {
if (exportScene) {
exportScene(result);
}
}
case 4:
case "end":
return _context.stop();
}
}, _callee);
}));
return function (_x) {
return _ref2.apply(this, arguments);
};
}());
});
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("mesh", {
ref: earthRef
}, /*#__PURE__*/React.createElement("sphereGeometry", {
args: [1, 256, 256]
})));
};
export default Earth;