New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-3d-viewer

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-3d-viewer

A 3D model viewer component based on react.js

  • 1.0.7
  • npm
  • Socket score

Version published
Weekly downloads
431
decreased by-45.37%
Maintainers
1
Weekly downloads
 
Created
Source

English | 简体中文

react-3d-viewer

一个基于react.js的组件化3d模型查看工具. Demo请戳 http://dwqdaiwenqi.github.io/react-3d-viewer/site/

特征

  • 组件化的
  • .setState()方法更新UI
  • 支持 gltf、obj、mtl、json、dae 模型格式 - 其他格式以后支持
  • 提供 <DirectionLight/> and <AmbientLight/> 组件 - 其他灯光组件以后提供

使用

从npm或cdn上获取react-3d-viewer

npm i react-3d-viewer

Commonjs

import {OBJModel} from 'react-3d-viewer'

render(){
  return(
    <div>
      <OBJModel src="./a.obj"/>
    </div>
  )
}
import {Tick,MTLModel} from 'react-3d-viewer'

render(){
  return(
    <div>
     <MTLModel 
        enableZoom = {false}
        position={{x:0,y:-100,z:0}}
        rotation={this.state.rotation}
        mtl="./src/lib/model/freedom.mtl"
        src="./src/lib/model/freedom.obj"
     />
    </div>
  )
}
componentWillMount(){
    this.tick.animate = false
}
componentDidMount(){
  this.tick = Tick(()=>{
    var {rotation} = this.state
    rotation.y += 0.005
    this.setState({rotation})

  })
}

HTML

<script src="https://unpkg.com/react-3d-viewer@latest/dist/scripts/main.js"></script>
<script src="https://unpkg.com/react@latest/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@latest/umd/react-dom.production.min.js"></script>
<div id="example"></div>
<script >
  // 别这么做。。。
  ReactDOM.render(
  React.createElement('div',{ style: { width: 600, margin: '0px auto' } },
  React.createElement(React3DViewer.JSONModel, {src:'./src/lib/model/kapool.js'})
  )
  ,document.getElementById('example'));
</script>

更多Demo,这儿

属性

属性名类型默认值描述
widthnumber500容器宽
heightnumber500容器高
onLoadfunctionundefined函数加载完成后调用
onProgressfunctionundefined函数加载过程中调用
enableKeysboolentrue启用或不启用键盘控制
enableRotateboolentrue启用或不启用相机的水平和垂直方向旋转
enableZoomboolentrueEnable or disable zooming (dollying) of the camera
enabledboolentrue是否启用控制
srcstringundefined文件的路径
mtlstringundefined.mtl文件的路径
anitialiasboolentrue是否启用抗锯齿
positionobject{x:0,y:0,z:0}对象的坐标
rotationobject{x:0,y:0,z:0}对象的旋转

如何工作的

<FormatModel>组件创建了相机、场景、灯光和WebGL渲染器。它往文档中添加了一个填满了视口的DOM节点(<canvas>元素)。 内部scene是实时渲染的,在componentDidUpdate中检测props,改变对象的属性。

License

MIT

FAQs

Package last updated on 29 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc