Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans Add BaseImporterPlugin, @threepipe/plugin-extra-importers for .3ds, .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
il y a 2 ans |
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684 |
- # ThreePipe
-
- A new way to work with three.js, 3D models and rendering on the web.
-
- [ThreePipe](https://threepipe.org/) —
- [Github](https://github.com/repalash/threepipe) —
- [Examples](https://threepipe.org/examples/) —
- [API Reference](https://threepipe.org/docs/) —
- [WebGi](https://webgi.xyz/docs/)
-
- [](https://www.npmjs.com/package/threepipe)
- [](https://discord.gg/apzU8rUWxY)
- [](https://opensource.org/license/apache-2-0/)
- [](https://twitter.com/repalash)
-
- ThreePipe is a 3D framework built on top of [three.js](https://threejs.org/) in TypeScript with a focus on rendering quality, modularity, and extensibility.
-
- Key features include:
- - Simple, intuitive API for creating 3D model viewers/configurators/editors on web pages, with many built-in presets for common workflows and use-cases.
- - Companion [editor](https://threepipe.org/examples/tweakpane-editor/) to create, edit and configure 3D scenes in the browser.
- - Modular architecture that allows you to easily extend the viewer, scene objects, materials, shaders, rendering, post-processing and serialization with custom functionality.
- - Plugin system along with a rich library of built-in plugins that allows you to easily add new features to the viewer.
- - [uiconfig](https://github.com/repalash/uiconfig.js) compatibility to automatically generate configuration UIs in the browser.
- - Modular rendering pipeline with built-in deferred rendering, post-processing, RGBM HDR rendering, etc.
- - Material extension framework to modify/inject/build custom shader code into existing materials at runtime from plugins.
- - Extendable asset import, export and management pipeline with built-in support for gltf, glb, obj+mtl, fbx, materials(pmat/bmat), json, zip, png, jpeg, svg, webp, ktx2, ply, 3dm and many more.
- - Automatic serialization of all viewer and plugin settings in GLB(with custom extensions) and JSON formats.
- - Automatic disposal of all three.js resources with built-in reference management.
-
- ## Examples
-
- Code samples and demos covering various usecases and test are present in the [examples](./examples/) folder.
-
- Try them: https://threepipe.org/examples/
-
- View the source code by pressing the code button on the top left of the example page.
-
- To make changes and run the example, click on the CodePen button on the top right of the source code.
-
- ## Table of Contents
-
- - [ThreePipe](#threepipe)
- - [Examples](https://threepipe.org/examples/)
- - [Table of Contents](#table-of-contents)
- - [Getting Started](#getting-started)
- - [HTML/JS Quickstart (CDN)](#htmljs-quickstart-cdn)
- - [React](#react)
- - [Vue.js](#vuejs)
- - [Svelte](#svelte)
- - [NPM/YARN Package](#npmyarn)
- - [Installation](#installation)
- - [Loading a 3D Model](#loading-a-3d-model)
- - [License](#license)
- - [Status](#status)
- - [Documentation (API Reference)](#documentation)
- - [WebGi](#webgi)
- - [Contributing](#contributing)
- - [Features](#features)
- - [File Formats](#file-formats)
- - [Loading files](#loading-files)
- - [3D models](#3d-models)
- - [Materials](#materials)
- - [Images/Textures](#imagestextures)
- - [zip files](#zip-files)
- - [txt, json files](#txt-json-files)
- - [Data URLs](#data-urls)
- - [Local files, File and Blob](#local-files-file-and-blob)
- - [Background, Environment maps](#background-environment-maps)
- - [SVG strings](#svg-strings)
- - [Exporting files](#exporting-files)
- - [Exporting 3D models](#exporting-3d-models)
- - [Exporting Materials](#exporting-materials)
- - [Exporting Canvas Images](#exporting-canvas-images)
- - [Exporting Images/Textures](#exporting-imagestextures)
- - [Exporting Render Targets](#exporting-render-targets)
- - [Render Pipeline](#render-pipeline)
- - [Material Extension](#material-extension)
- - [UI Configuration](#ui-configuration)
- - [Serialization](#serialization)
- - [Plugin System](#plugin-system)
- - [Viewer API](#viewer-api)
- - [ThreeViewer](#threeviewer)
- - [RenderManager](#rendermanager)
- - [RootScene](#rootscene)
- - [ICamera](#icamera)
- - [AssetManager](#assetmanager)
- - [AssetImporter](#assetimporter)
- - [AssetExporter](#assetexporter)
- - [MaterialManager](#materialmanager)
- - [Other classes and interfaces](#other-classes-and-interfaces)
- - [Plugins](#threepipe-plugins)
- - [TonemapPlugin](#tonemapplugin) - Add tonemap to the final screen pass
- - [DropzonePlugin](#dropzoneplugin) - Drag and drop local files to import and load
- - [ProgressivePlugin](#progressiveplugin) - Post-render pass to blend the last frame with the current frame
- - [SSAAPlugin](#ssaaplugin) - Add Super Sample Anti-Aliasing by applying jitter to the camera.
- - [DepthBufferPlugin](#depthbufferplugin) - Pre-rendering of depth buffer
- - [NormalBufferPlugin](#normalbufferplugin) - Pre-rendering of normal buffer
- - [GBufferPlugin](#gbufferplugin) - Pre-rendering of depth-normal and flags buffers in a single pass
- - [SSAOPlugin](#ssaoplugin) - Add SSAO(Screen Space Ambient Occlusion) for physical materials.
- - [CanvasSnapshotPlugin](#canvassnapshotplugin) - Add support for taking snapshots of the canvas
- - [PickingPlugin](#pickingplugin) - Adds support for selecting objects in the viewer with user interactions and selection widgets
- - [TransformControlsPlugin](#transformcontrolsplugin) - Adds support for moving, rotating and scaling objects in the viewer with interactive widgets
- - [ContactShadowGroundPlugin](#contactshadowgroundplugin) - Adds a ground plane at runtime with contact shadows
- - [GLTFAnimationPlugin](#gltfanimationplugin) - Add support for playing and seeking gltf animations
- - [PopmotionPlugin](#popmotionplugin) - Integrates with popmotion.io library for animation/tweening
- - [CameraViewPlugin](#cameraviewplugin) - Add support for saving, loading, animating, looping between camera views
- - [RenderTargetPreviewPlugin](#rendertargetpreviewplugin) - Preview any render target in a UI panel over the canvas
- - [GeometryUVPreviewPlugin](#geometryuvpreviewplugin) - Preview UVs of any geometry in a UI panel over the canvas
- - [FrameFadePlugin](#framefadeplugin) - Post-render pass to smoothly fade to a new rendered frame over time
- - [VignettePlugin](#vignetteplugin) - Add Vignette effect by patching the final screen pass
- - [ChromaticAberrationPlugin](#chromaticaberrationplugin) - Add Chromatic Aberration effect by patching the final screen pass
- - [FilmicGrainPlugin](#filmicgrainplugin) - Add Filmic Grain effect by patching the final screen pass
- - [NoiseBumpMaterialPlugin](#noisebumpmaterialplugin) - Sparkle Bump/Noise Bump material extension for PhysicalMaterial
- - [CustomBumpMapPlugin](#custombumpmapplugin) - Custom Bump Map material extension for PhysicalMaterial
- - [ClearcoatTintPlugin](#clearcoattintplugin) - Clearcoat Tint material extension for PhysicalMaterial
- - [FragmentClippingExtensionPlugin](#fragmentclippingextensionplugin) - Fragment/SDF Clipping material extension for PhysicalMaterial
- - [HDRiGroundPlugin](#hdrigroundplugin) - Add support for ground projected hdri/skybox to the webgl background shader.
- - [VirtualCamerasPlugin](#virtualcamerasplugin) - Add support for rendering virtual cameras before the main one every frame.
- - [EditorViewWidgetPlugin](#editorviewwidgetplugin) - Adds an interactive ViewHelper/AxisHelper that syncs with the main camera.
- - [Object3DWidgetsPlugin](#object3dwidgetsplugin) - Automatically create light and camera helpers/gizmos when they are added to the scene.
- - [Object3DGeneratorPlugin](#object3dwidgetsplugin) - Provides UI and API to create scene objects like lights, cameras, meshes, etc.
- - [DeviceOrientationControlsPlugin](#deviceorientationcontrolsplugin) - Adds a controlsMode to the mainCamera for device orientation controls(gyroscope rotation control).
- - [PointerLockControlsPlugin](#pointerlockcontrolsplugin) - Adds a controlsMode to the mainCamera for pointer lock controls.
- - [ThreeFirstPersonControlsPlugin](#threefirstpersoncontrolsplugin) - Adds a controlsMode to the mainCamera for first person controls from threejs.
- - [Rhino3dmLoadPlugin](#rhino3dmloadplugin) - Add support for loading .3dm files
- - [PLYLoadPlugin](#plyloadplugin) - Add support for loading .ply files
- - [STLLoadPlugin](#stlloadplugin) - Add support for loading .stl files
- - [KTX2LoadPlugin](#ktx2loadplugin) - Add support for loading .ktx2 files
- - [KTXLoadPlugin](#ktxloadplugin) - Add support for loading .ktx files
- - [SimplifyModifierPlugin](#simplifymodifierplugin) - Boilerplate for plugin to simplify geometries
- - [MeshOptSimplifyModifierPlugin](#meshoptsimplifymodifierplugin) - Simplify geometries using meshoptimizer library
- - [Packages](#threepipe-packages)
- - [@threepipe/plugin-tweakpane](#threepipeplugin-tweakpane) Tweakpane UI Plugin
- - [@threepipe/plugin-blueprintjs](#threepipeplugin-blueprintjs) BlueprintJs UI Plugin
- - [@threepipe/plugin-tweakpane-editor](#threepipeplugin-tweakpane-editor) - Tweakpane Editor Plugin
- - [@threepipe/plugins-extra-importers](#threepipeplugins-extra-importers) - Plugin for loading more file types supported by loaders in three.js
- - [@threepipe/plugin-blend-importer](#threepipeplugin-blend-importer) - Blender to add support for loading .blend file
- - [@threepipe/plugin-geometry-generator](#threepipeplugin-geometry-generator) - Generate parametric geometry types that can be re-generated from UI/API.
- - [@threepipe/plugin-gaussian-splatting](#threepipeplugin-gaussian-splatting) - Gaussian Splatting plugin for loading and rendering splat files
-
- ## Getting Started
-
- ### HTML/JS Quickstart (CDN)
-
- ```html
-
- <canvas id="three-canvas" style="width: 800px; height: 600px;"></canvas>
- <script type="module">
- import {ThreeViewer, DepthBufferPlugin} from 'https://threepipe.org/dist/index.mjs'
-
- const viewer = new ThreeViewer({canvas: document.getElementById('three-canvas')})
-
- // Add some plugins
- viewer.addPluginSync(new DepthBufferPlugin())
-
- // Load an environment map
- const envPromise = viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
- const modelPromise = viewer.load('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
- autoCenter: true,
- autoScale: true,
- })
-
- Promise.all([envPromise, modelPromise]).then(([env, model]) => {
- console.log('Loaded', model, env, viewer)
- })
- </script>
- ```
- Check it in action: https://threepipe.org/examples/#html-js-sample/
-
- Check out the details about the [ThreeViewer API](#viewer-api) and more [plugins](#threepipe-plugins) below.
-
- ### React
-
- A sample [react](https://react.dev) component in tsx to render a model with an environment map.
-
- ```tsx
- import React from 'react'
- function ThreeViewerComponent({src, env}: {src: string, env: string}) {
- const canvasRef = React.useRef(null)
- React.useEffect(() => {
- const viewer = new ThreeViewer({canvas: canvasRef.current})
-
- const envPromise = viewer.setEnvironmentMap(env)
- const modelPromise = viewer.load(src)
- Promise.all([envPromise, modelPromise])
- return () => {
- viewer.dispose()
- }
- }, [])
- return (
- <canvas id="three-canvas" style={{width: 800, height: 600}} ref={canvasRef} />
- )
- }
- ```
-
- Check it in action: https://threepipe.org/examples/#react-tsx-sample/
-
- Other examples in js: https://threepipe.org/examples/#react-js-sample/ and jsx: https://threepipe.org/examples/#react-jsx-sample/
-
- ### Vue.js
-
- A sample [vue.js](https://vuejs.org/) component in js to render a model with an environment map.
-
- ```js
- const ThreeViewerComponent = {
- setup() {
- const canvasRef = ref(null);
-
- onMounted(() => {
- const viewer = new ThreeViewer({ canvas: canvasRef.value });
-
- const envPromise = viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr');
- const modelPromise = viewer.load('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf');
-
- Promise.all([envPromise, modelPromise])
-
- onBeforeUnmount(() => {
- viewer.dispose();
- });
- });
-
- return { canvasRef };
- },
- };
- ```
-
- Check it in action: https://threepipe.org/examples/#vue-html-sample/
-
- Another example with Vue SFC(Single file component): https://threepipe.org/examples/#vue-sfc-sample/
-
- ### Svelte
-
- A sample [svelte](https://svelte.dev/) component in js to render a model with an environment map.
-
- ```html
- <script>
- import {onDestroy, onMount} from 'svelte';
- import {ThreeViewer} from 'threepipe';
-
- let canvasRef;
- let viewer;
- onMount(() => {
- viewer = new ThreeViewer({canvas: canvasRef});
-
- const envPromise = viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr');
- const modelPromise = viewer.load('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf');
-
- Promise.all([envPromise, modelPromise])
- });
- onDestroy(() => viewer.dispose())
- </script>
-
- <canvas bind:this={canvasRef} id="three-canvas" style="width: 800px; height: 600px"></canvas>
- ```
-
- Check it in action: https://threepipe.org/examples/#svelte-sample/
-
- ### NPM/YARN
-
- ### Installation
-
- ```bash
- npm install threepipe
- ```
-
- ### Loading a 3D Model
-
- First, create a canvas element in your HTML page:
- ```html
- <canvas id="three-canvas" style="width: 800px; height: 600px;"></canvas>
- ```
-
- Then, import the viewer and create a new instance:
-
- ```typescript
- import {ThreeViewer, IObject3D} from 'threepipe'
-
- // Create a viewer
- const viewer = new ThreeViewer({canvas: document.getElementById('three-canvas') as HTMLCanvasElement})
-
- // Load an environment map
- await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
-
- // Load a model
- const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
- autoCenter: true,
- autoScale: true,
- })
- ```
-
- That's it! You should now see a 3D model on your page.
-
- The 3D model can be opened in the [editor](https://threepipe.org/examples/tweakpane-editor/) to view and edit the scene settings, objects, materials, lights, cameras, post-processing, etc. and exported as a GLB file. All settings are automatically serialized and saved in the GLB file, which can be loaded into the viewer. Any plugins used in the editor can be added to the viewer to add the same functionality. The plugin data is automatically loaded(if the plugin is added) when the model is added to the scene.
-
- The viewer initializes with a Scene, Camera, Camera controls(Orbit Controls), several importers, exporters and a default rendering pipeline. Additional functionality can be added with plugins.
-
- Check out the GLTF Load example to see it in action or to check the JS equivalent code: https://threepipe.org/examples/#gltf-load/
-
- Check out the [Plugins](#plugin-system) section below to learn how to add additional functionality to the viewer.
-
- ## License
- The core framework([src](https://github.com/repalash/threepipe/tree/master/src), [dist](https://github.com/repalash/threepipe/tree/master/dist), [examples](https://github.com/repalash/threepipe/tree/master/examples) folders) and any [plugins](https://github.com/repalash/threepipe/tree/master/plugins) without a separate license are under the Free [Apache 2.0 license](https://github.com/repalash/threepipe/tree/master/LICENSE).
-
- Some plugins(in the [plugins](https://github.com/repalash/threepipe/tree/master/plugins) folder) might have different licenses. Check the individual plugin documentation and the source folder/files for more details.
-
- ## Status
- The project is in `alpha` stage and under active development. Many features will be added but the core API will not change significantly in future releases.
-
- Check out [WebGi](https://webgi.xyz/) for an advanced tailor-made solution for e-commerce, jewelry, automobile, apparel, furniture etc.
-
- ## Documentation
-
- Check the list of all functions, classes and types in the [API Reference Docs](https://threepipe.org/docs/).
-
- ## WebGi
- Check out WebGi - Premium Photo-realistic 3D rendering framework and tools for web applications and online commerce along with custom modules and rendering solutions for e-commerce, jewelry, automobile, apparel, furniture and other retail applications.
-
- [Homepage](https://webgi.xyz/) — [Docs](https://webgi.xyz/docs/)
-
- [](https://twitter.com/pixotronics)
-
- ## Contributing
- Contributions to ThreePipe are welcome and encouraged! Feel free to open issues and pull requests on the GitHub repository.
-
- # Features
-
- ## File Formats
-
- ThreePipe Asset Manager supports the import of the following file formats out of the box:
- * **Models**: gltf, glb, obj+mtl, fbx, drc
- * **Materials**: mat, pmat, bmat (json based), registered material template slugs
- * **Images**: webp, png, jpeg, jpg, svg, ico, avif, hdr, exr
- * **Misc**: json, vjson, zip, txt
-
- Plugins can add additional formats:
- * Models
- * 3dm - Using [Rhino3dmLoadPlugin](#Rhino3dmLoadPlugin)
- * ply - Using [PLYLoadPlugin](#PLYLoadPlugin)
- * usdz - Using [USDZLoadPlugin](#USDZLoadPlugin)
- * stl - Using [STLLoadPlugin](#STLLoadPlugin)
- * ktx - Using [KTXLoadPlugin](#KTXLoadPlugin)
- * ktx2 - Using [KTX2LoadPlugin](#KTX2LoadPlugin)
-
- Plugins to support more model formats are available in the package [@threepipe/plugins-extra-importers](#threepipeplugins-extra-importers) including .3ds,
- .3mf, .collada, .amf, .bvh, .vox, .gcode, .mdd, .pcd, .tilt, .wrl, .mpd, .vtk, .xyz
-
- ## Loading files
-
- ThreePipe uses the [AssetManager](https://threepipe.org/docs/classes/AssetManager.html) to load files.
- The AssetManager has support for loading files from URLs, local files and data URLs.
- The AssetManager also adds support for loading files from a zip archive. The zip files are automatically unzipped, and the files are loaded from the zip archive.
-
- [viewer.load()](https://threepipe.org/docs/classes/ThreeViewer.html#load) is a high-level wrapper for loading files from the AssetManager.
- It automatically adds the loaded object to the scene and returns a promise that resolves to the loaded object,
- the materials are also automatically registered to the material manager.
-
- AssetManager internally uses [AssetImporter](https://threepipe.org/docs/classes/AssetImporter.html),
- which provides a low-level API
- for managing three.js [LoadingManager](https://threejs.org/docs/#api/en/loaders/LoadingManager)
- and adding and registering loaders for different file types.
-
- If the purpose is not to add files to the scene then [viewer.assetManager.importer.import()](https://threepipe.org/docs/classes/AssetImporter.html#import) method can be used
- to import files from the `AssetImporter`.
- viewer.assetManager.loadImported()](https://threepipe.org/docs/classes/AssetManager.html#loadImported)
- can then be called to load the imported files after any processing.
- The `viewer.load()`, `viewer.assetManager.addAsset()`
- and `viewer.assetManager.addAssetSingle()` methods perform combination of `import` and `loadImported`.
-
- ### 3D models
-
- The 3d models are added to `viewer.scene.modelRoot` on `viewer.load` unless some option is specified.
-
- ```typescript
- const objectGlb = await viewer.load<IObject3D>('https://example.com/file.glb')
- const objectFbx = await viewer.load<IObject3D>('https://example.com/file.fbx')
- const objectObj = await viewer.load<IObject3D>('https://example.com/file.obj') // .mtl referenced in obj is automatically loaded
- // ... load any 3d model file as an object
- ```
- Here, we are casting to [IObject3D](https://threepipe.org/docs/interfaces/IObject3D.html) type
- to get the proper type and autocomplete for the object.
- `IObject3D` inherits [Object3D](https://threejs.org/docs/#api/en/core/Object3D) from three.js and adds some additional properties.
-
- For JavaScript, the type can be omitted.
- ```javascript
- const objectGlb = await viewer.load('https://example.com/file.glb')
- ```
-
- When loading models, several options can be passed to automatically process the model first time, like `autoScale`, `autoCenter`, `addToRoot` etc. Check [AddObjectOptions](https://threepipe.org/docs/interfaces/AddObjectOptions.html) and [ImportAddOptions](https://threepipe.org/docs/interfaces/ImportAddOptions.html) for more details.
-
- ### Materials
-
- The materials downloaded as PMAT/BMAT/JSON etc from threepipe,
- webgi or the editor can be loaded
- and registered with the [MaterialManager](https://threepipe.org/docs/classes/MaterialManager)
- using the `viewer.load` method.
-
- Custom material types can also be registered by plugins(like dmat for diamonds), which can also be loaded automatically using the `viewer.load` method.
-
- ```typescript
- const pMaterial = await viewer.load<PhysicalMaterial>('https://example.com/file.pmat')
- const bMaterial = await viewer.load<UnlitMaterial>('https://example.com/file.bmat')
- // ... load any material file as a material
- ```
- Casting to [PhysicalMaterial](https://threepipe.org/docs/classes/PhysicalMaterial) or [UnlitMaterial](https://threepipe.org/docs/classes/UnlitMaterial) is optional but recommended to get the proper type and autocomplete for the material.
-
- To assign the material on any object, set it to `object.material`
-
- ```typescript
- // find a loaded mesh in the scene
- const object = viewer.scene.getObjectByName('objectName');
- // assign the material
- object.material = pMaterial;
- ```
-
- To copy the properties without changing the material reference, use `material.copy()` or `material.setValues()` methods.
-
- ```typescript
- object.material.copy(pMaterial);
-
- // or use material manager to apply to multiple materials.
- viewer.assetManager.materialManager.applyMaterial(pMaterial, 'METAL') // apply props to all materials/objects with the name METAL
- ```
-
- TODO: add examples for material load and copy
-
- ### Images/Textures
-
- Images can be loaded using the `viewer.load` method.
- There is built-in support for loading all image formats supported by the browser (webp, png, jpeg, jpg, svg, ico, avif) and hdr, exr, hdr.png formats for all browsers.
- More formats like ktx2, ktx, etc. can be added using plugins.
-
- ```typescript
- const texture = await viewer.load<ITexture>('https://example.com/file.png')
- // ... load any image file as a texture
- ```
- Casting to [ITexture](https://threepipe.org/docs/interfaces/ITexture.html) is optional
- but recommended to get the proper type and autocomplete for the texture.
- It inherits from three.js [Texture](https://threejs.org/docs/#api/en/textures/Texture) and adds some additional properties.
-
- To assign the texture on any material, set it to `material.map`
-
- ```typescript
- // find a loaded mesh in the scene
- const object = viewer.scene.getObjectByName('objectName');
- const material = object.material as PhysicalMaterial;
- // assign the texture
- material.map = texture;
- material.setDirty() // to let the viewer know that the material has changed and needs to re-render the scene. This will also trigger fade effect if FrameFadePlugin is added.
- ```
- Check out the image load example to see it in action or to check the JS equivalent code: https://threepipe.org/examples/#image-load/
-
- ### Zip files
-
- .zip files are automatically unzipped and the files are sent to re-load recursively when loaded with `viewer.load`.
- Any level of zip hierarchy is flattened.
- Loading files like .gltf with references to assets inside the zip file,
- any relative references are also automatically resolved.
- This is supported for file types like gltf, glb, obj,
- etc which support references to external files and has `root` set to `true in [IImporter](https://threepipe.org/docs/interfaces/IImporter.html).
-
- ```typescript
- const objectGltf = await viewer.load<IObject3D>('https://example.com/model.gltf.zip')
- ```
- If we know that the zip file contains a single gltf with all the assets, we can cast the result to [IObject3D](https://threepipe.org/docs/interfaces/IObject3D.html) type.
-
- To load multiple assets from zip files like multiple textures or materials, use `viewer.assetManager.addAsset` method which returns a promise of array of loaded assets.
-
- ```typescript
- const textures = await viewer.assetManager.addAsset<ITexture[]>('https://example.com/textures.zip')
- const materials = await viewer.assetManager.addAsset<IMaterial[]>('https://example.com/materials.zip')
- ```
-
- The auto import of zip contents can be disabled to get the files and blobs in the zip
- ```typescript
- const zip = await viewer.load<any>('https://example.com/file.zip', {autoImportZipContents: false})
- ```
-
- TODO - add example for loading zip files.
-
- ### txt, json files
-
- Text and JSON files can be loaded using the `viewer.load` method and return strings and objects respectively.
-
- ```typescript
- const text = await viewer.load<string>('https://example.com/file.txt')
- const json = await viewer.load<any>('https://example.com/file.json')
- ```
-
- ### Data URLs
-
- Data URLs can be loaded using the `viewer.load` method. The correct mime-type is required to be set in the data URL for finding the correct importer.
-
- ```typescript
- const dataUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA' // ... some data url
- const texture = await viewer.load<ITexture>(dataUrl)
- ```
-
- ### Local files, File and Blob
-
- Local files can be loaded using the `viewer.load` method by passing a [IAsset](https://threepipe.org/docs/interfaces/IAsset) object with [File](https://developer.mozilla.org/en-US/docs/Web/API/File) or [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object.
-
- ```typescript
- const file: File|Blob = fileObject // create a new file, blob or get from input element
- const text = await viewer.load<IObject>({
- // a path/name is required to determine the proper importer by extension. `file.name` can also be used if available
- path: 'file.glb',
- file
- })
- ```
- The same can be done for any file type.
-
- To load a `Map` of files(like when multiple files are dragged and dropped on the webpage) with internal references to other files, use `viewer.assetManager.importer.importFiles` method. Check the source for [DropzonePlugin](#dropzoneplugin) for an example.
-
- ### Background, Environment maps
-
- The background and environment maps can be set using the `viewer.setBackgroundMap` and `viewer.setEnvironmentMap` methods respectively. These accept both loaded textures from `viewer.load` and direct URLs. Files can be of any image format including hdr, exr.
-
- ```typescript
- await viewer.setEnvironmentMap('https://example.com/file.hdr')
- await viewer.setBackgroundMap('https://example.com/file.png')
- ```
-
- The same texture can be set to both by setting `setBackground` or `setEnvironment` to true in the options:
- ```typescript
- await viewer.setEnvironmentMap('https://example.com/file.hdr', {setBackground: true})
- ```
-
- Check the HDR Load example to see it in action: https://threepipe.org/examples/#hdr-load/
-
- ### SVG strings
- SVG strings can be converted to data urls using the [svgUrl](https://repalash.com/ts-browser-helpers/functions/svgUrl.html) string template function
-
- ```typescript
- const svgDataUrl = svgUrl`<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> ... </svg>`;
- const texture = await viewer.load<ITexture>(dataUrl)
- ```
-
- ### Custom file types
-
- Custom file importers/loaders can be registered to the `AssetImporter` using the `addImporter` method.
-
- ```typescript
- class CustomLoader extends FileLoader implements ILoader{
- constructor(manager?: LoadingManager) {
- super(manager);
- }
- load(url: string, onLoad: (data: any) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void): Mesh {
- this.setResponseType('json')
- return super.load(url, (json: any)=>{
- const mat = new PhysicalMaterial(json)
- onLoad?.(mat)
- }, onProgress, onError)
- }
- }
-
- viewer.assetManager.importer.addImporter(new Importer(CustomLoader, ['ext'], ['mime/type'], false))
-
- // load the file
- const mat = await viewer.load<PhysicalMaterial>('https://example.com/file.ext')
- ```
-
- ## Exporting files
-
- Threepipe has support for exporting various asset type with AssetManager,
- as well as support to export viewer and plugin configuration, arbitrary objects etc using the [serialization](#serialization) system.
-
- [viewer.export()](https://threepipe.org/docs/classes/ThreeViewer.html#export) is a high-level wrapper for exporting scene objects, materials, textures, render targets, viewer/scene configuration and plugin configurations.
-
- AssetManager internally uses [AssetExporter](https://threepipe.org/docs/classes/AssetExporter.html) to export files.
- AssetExporter includes some basic exporters for glb, exr, textures,
- and materials and a system to register exporters for different file types with plugins or custom exporters.
-
- ### Exporting 3D models
-
- Export the root scene as glb
- ```typescript
- const blob = await viewer.exportScene({
- viewerConfig: true, // default = true. export all viewer and plugin configuration. if false only the model root object is exported.
- })
- // download the file
- downloadBlob(blob, 'scene.glb')
- ```
-
- Export a single object from the scene as glb
- ```typescript
- const object = viewer.scene.getObjectByName('objectName');
- const glb: Blob = await viewer.export(object, {
- exportExt: 'glb', // default = glb for models
- embedUrlImages: true, // default = false. embed images in glb even when url is available.
- })
- // download the file
- downloadBlob(glb, 'object.glb')
- ```
-
- Check the example [glb-export](https://threepipe.org/examples/#glb-export/) to see a demo.
-
- ### Exporting Materials
-
- Export a material
- ```typescript
- const material = viewer.assetManager.materialManager.findMaterialsByName('materialName')[0];
- // or
- // const material = viewer.scene.getObjectByName('objectName').material;
- const blob = await viewer.export(material)
- // download the file
- downloadBlob(blob, 'material.' + blob.ext)
- ```
-
- Check the example [pmat-material-export](https://threepipe.org/examples/#pmat-material-export/) to see a demo.
-
- ### Exporting Canvas Images
-
- Canvas Screenshot/snapshot can be exported as png, jpeg or webp(if supported by the browser)
- ```typescript
- const blob = await viewer.getScreenshotBlob({mimeType: 'image/' + type, quality: 0.85})
- // or to get data url:
- // const dataUrl = await viewer.getScreenshotDataUrl({mimeType: 'image/' + type, quality: 0.85})
- // download the file
- downloadBlob(blob, 'screenshot.' + blob.ext)
- ```
-
- Check the example [image-snapshot-export](https://threepipe.org/examples/#image-snapshot-export/) to see a demo.
-
- ### Exporting Textures
-
- Textures can be exported to JSON using `viewer.export` or `AssetExporter`
-
- ```typescript
- const texture = await viewer.load('https://example.com/file.jpeg')
- const blob = await viewer.export(texture)
- downloadBlob(blob, texture.name + '.' + blob.ext)
- ```
-
- Render target textures can be exported with `viewer.renderManager.exportRenderTarget` or `viewer.export`,
- read about [Exporting Render Targets](#exporting-render-targets) below.
-
- TODO: add examples for texture export
-
- Textures and Uint8 Data Textures can be exported as a data url or copied to a new canvas
- ```typescript
- // get a base64 data url
- const dataUrl = textureToDataUrl(texture, 4096, false, 'image/png') // texture or data texture, max-size, flipY, mimeType
- // or copy to a new canvas
- const canvas = textureToCanvas(texture, 4096) // texture or data texture, max-size
- ```
-
- Data Textures of type Half float and Float can be exported with `viewer.export`
- ```typescript
- const dataTex = await viewer.load('https://example.com/file.hdr')
- const blob = await viewer.export(dataTexture, {exportExt: 'exr'})
- ```
- Check the example [hdr-to-exr](https://threepipe.org/examples/#hdr-to-exr/) to see a demo of HDR to EXR conversion.
-
- TODO: add support to export unsigned byte textures as png, jpeg, webp
-
- ### Exporting Images/Textures
-
- Exporting Textures as Images with image of types ImageBitmap, HTMLImageElement,
- HTMLOrSVGImageElement, CanvasImageSource, HTMLCanvasElement,
- OffscreenCanvas can be exported to png data urls with [imageBitmapToBase64](https://repalash.com/ts-browser-helpers/functions/imageBitmapToBase64.html) function.
-
- ```typescript
- const texture = await viewer.load('https://example.com/file.jpeg')
-
- const dataUrl = await imageBitmapToBase64(texture.image, 'image/png', 0.85);
- ```
-
- TODO: add support for texture export as images in AssetExporter
-
- ### Exporting Render Targets
-
- Unsigned byte render targets can be exported as png, jpeg or webp(if supported by the browser)
- ```typescript
- const depthPlugin = viewer.addPluginSync(DepthBufferPlugin, UnsignedByteType)
- // wait for the first render
- const blob = await viewer.export(depthPlugin.target!, {exportExt: 'png'})
- if (blob) downloadBlob(blob, target.texture.name + '.' + blob.ext)
- ```
-
- Half float and float render targets can be exported as exr
- ```typescript
- const depthPlugin = viewer.addPluginSync(DepthBufferPlugin, HalfFloatType)
- // wait for the first render
- const blob = await viewer.export(depthPlugin.target!, {exportExt: 'exr'})
- if (blob) downloadBlob(blob, target.texture.name + '.' + blob.ext)
- ```
-
- Note: `exportExt` is determined automatically if not specified.
-
- ## Render pipeline
-
- Threepipe includes a [RenderManager](https://threepipe.org/docs/classes/RenderManager.html) for managing the composition pipeline, and provides helpers for rendering and render target management.
-
- The RenderManager includes a [EffectComposer](https://threejs.org/docs/#api/en/postprocessing/EffectComposer) from three.js for rendering passes and a [WebGLRenderer](https://threejs.org/docs/#api/en/renderers/WebGLRenderer) for rendering,
- but the pass management and sorting is managed by the RenderManager itself.
-
- The RenderManager inherits from [RenderTargetManager](https://threepipe.org/docs/classes/RenderTargetManager.html)
- which provides utilities for creating, tracking and destroying dedicated and temporary render targets.
-
- ### Render Targets
-
- Render targets can be created
- using the `viewer.renderManager.createTarget` and `viewer.renderManager.createTargetCustom` methods.
- These can then be disposed using the `viewer.renderManager.disposeTarget` method when not needed anymore.
-
- Or to create temp targets for one time use `viewer.renderManager.getTempTarget` and `viewer.renderManager.releaseTempTarget` methods.
- can be used.
- All created render targets are tracked in the RenderManager,
- and are resized and disposed automatically when needed along with the viewer.
-
-
- ```typescript
- const newTarget = viewer.renderManager.createTarget({sizeMultiplier: 1})
- // or
- const newTarget2 = viewer.renderManager.createTarget({size: {
- width: 1024,
- height: 1024,
- },
- type: HalfFloatType
- })
- // or clone an existing target
- const newTarget3 = viewer.renderManager.composerTarget.clone()
- // for multi-sample render target
- const newTarget4 = viewer.renderManager.createTarget({sizeMultiplier: 1, samples: 4})
-
- // or create a custom target
- const newTarget5 = viewer.renderManager.createTargetCustom(
- {width: 1024, height: 1024},
- {type: HalfFloatType},
- WebGLCubeRenderTarget
- )
-
- // dispose targets
- viewer.renderManager.disposeTarget(newTarget)
- viewer.renderManager.disposeTarget(newTarget2)
- viewer.renderManager.disposeTarget(newTarget3)
- viewer.renderManager.disposeTarget(newTarget4)
- viewer.renderManager.disposeTarget(newTarget5)
-
- // get a temporary target
- const tempTarget = viewer.renderManager.getTempTarget({sizeMultiplier: 1})
- // release the temporary target
- viewer.renderManager.releaseTempTarget(tempTarget)
- ```
-
- Note: Render targets created with a sizeMultiplier are automatically resized when the canvas is resized.
-
-
- ### Passes
-
- By default, the render pipeline includes 2 passes -
- [RenderPass](https://threejs.org/docs/#api/en/postprocessing/RenderPass) for rendering the scene hierarchy and [ScreenPass](https://threejs.org/docs/#api/en/postprocessing/ShaderPass)
- for rendering the final output on the canvas.
-
- More passes can be added and removed from the pipeline
- using the [registerPass](https://threepipe.org/docs/classes/RenderManager.html#registerPass) and [unregisterPass](https://threepipe.org/docs/classes/RenderManager.html#unregisterPass) methods.
-
- The pipeline passes need
- to follow the interface of [IPipelinePass](https://threepipe.org/docs/interfaces/IPipelinePass.html) and [IPipelinePassPlugin](https://threepipe.org/docs/interfaces/IPipelinePassPlugin.html).
- Which adds some important parameters over the three.js Pass,
- like pass id and support for defining where the pass should be added in the pipeline and it's dependants.
-
- ```typescript
- const pass = new GBufferRenderPass('customPass', viewer.renderManager.createTarget({sizeMultiplier: 1}))
- pass.before = ['render'] // Add the pass before the render pass
- pass.after = [] // Add the pass after these passes (none in this case)
- pass.required = ['render'] // render pass is required to be in the pipeline for this
- viewer.renderManager.registerPass(pass)
- ```
- Note:
- See [PipelinePassPlugin](https://threepipe.org/docs/classes/PipelinePassPlugin.html) for an abstract plugin
- that provides the boilerplate to create a plugin that registers a custom pass in the pipeline.
- Check [NormalBufferPlugin](https://threepipe.org/docs/classes/NormalBufferPlugin.html) for an example of that.
-
- Note: All effects in post-processing or material extension need not be a separate pass in the pipeline.
- Most effects can be achieved with either extending the scene object material shaders or the Screen Pass material shader
- using [Material extension](#material-extension) system
-
- ## Material Extension
-
- Threepipe includes a Material extension system along with a material manager.
- The material manager is used to register materials and material extensions.
-
- The material extensions are used to extend any material in the scene,
- or any plugin/pass with additional uniforms, defines, shader snippets and provides hooks.
-
- The material extensions are automatically applied to all materials in the scene that are compatible,
- when the extension is registered or when the material is added to the scene.
-
- Threepipe includes several built-in materials like
- [PhysicalMaterial](https://threepipe.org/docs/classes/PhysicalMaterial.html),
- [UnlitMaterial](https://threepipe.org/docs/classes/UnlitMaterial.html),
- [ExtendedShaderMaterial](https://threepipe.org/docs/classes/ExtendedShaderMaterial.html), [LegacyPhongMaterial](https://threepipe.org/docs/classes/LegacyPhongMaterial.html),
- that include support for extending the material.
- Any three.js material can be made extendable,
- check the `ShaderPass2` class for a simple example that adds support for material extension to three.js ShaderPass.
-
- The material extensions must follow the [MaterialExtension](https://threepipe.org/docs/interfaces/MaterialExtension.html) interface.
- Many plugins create their own material extensions either for the scene materials or shader passes(like the screen pass).
- Some plugins like `DepthBufferPlugin` also provides helper material extensions for other custom plugins
- to fetch value in the depth buffer.
-
- A sample material extension
- ```typescript
- const extension: MaterialExtension = {
- shaderExtender: (shader)=> {
- // change the shader properties like shader.fragmentShader, etc
- },
- parsFragmentSnippet: ` // add some code before the main function in the fragment shader
- uniform sampler2D tTexture;
- uniform float opacity;
- `,
- extraUniforms: {
- tTexture: ()=>({value: getTexture()}),
- opacity: {value: 1}
- // add additional uniforms, these can be IUniform or functions that return IUniform
- },
- extraDefines: {
- ['DEPTH_PACKING']: BasicDepthPacking,
- ['SOME_DEFINE']: ()=>"1",
- // add additional defines, these can be values or functions that return values
- },
- priority: 100, // priority when using multiple extensions on the same material
- isCompatible: (material) => material.isMeshBasicMaterial, // check if the material is compatible with this extension,
- computeCacheKey: (material) => material.uuid, // a custom cache key for the material extension. Shader is recompiled when this is changed
- onObjectRender: (object: Object3D, material: IMaterial) => {
- // called when some object is rendererd which has a material with this extension.
- },
- // uiConfig
- // check more properties and hooks in the MaterialExtension interface
- }
-
- // The extension can be registered to all the materials using the MaterialManager
- viewer.assetManager.materialManager.registerMaterialExtension(extension)
-
- // or register it on a single material (like the Screen Pass)
- viewer.renderManager.screenPass.material.registerMaterialExtensions([extension])
- ```
-
- ## UI Configuration
-
- Most of the classes and plugins in Threepipe include [uiconfig.js](https://repalash.com/uiconfig.js/) support
- and can be used to create configuration UIs, 3d configurators and even full-editors.
- The UIs are automatically generated based on the configuration object under `.uiConfig` property on all objects.
- These are of type [UiObjectConfig](https://repalash.com/uiconfig.js/interfaces/UiObjectConfig.html).
- In some classes, the ui configs are also generated using typescript decorators.
-
- The `uiConfig` is also added to all three.js objects and materials when they are added to the scene.
-
- The UIs can be generated at runtime using any of the UI plugins like [TweakpaneUIPlugin](#threepipeplugin-tweakpane), [BlueprintJsUiPlugin](#threepipeplugin-blueprintjs)
-
- An example showing how to create a UI for a material
-
- ```typescript
- const ui = viewer.addPluginSync(TweakpaneUiPlugin)
-
- const object = viewer.scene.getObjectByName('objectName');
- const material = object.material as PhysicalMaterial;
-
- ui.appendChild(material.uiConfig)
- ```
-
- See it in action: https://threepipe.org/examples/#material-uiconfig/
-
- Check more examples showing [Viewer UI](https://threepipe.org/examples/#viewer-uiconfig/),
- [Scene UI](https://threepipe.org/examples/#scene-uiconfig/),
- [Object UI](https://threepipe.org/examples/#object-uiconfig/), [Camera UI](https://threepipe.org/examples/#camera-uiconfig/)
-
- [TweakpaneEditorPlugin](#threepipeplugin-tweakpane-editor) further uses the Tweakpane configuration panel along with various plugins to create an 3d editor.
-
- Custom UI configuration can be created to generate custom UI for the editor or tweaking.
- This can be done by using typescript decorators or defining the UI in javascript as a [UiObjectConfig](https://repalash.com/uiconfig.js/interfaces/UiObjectConfig.html) object.
-
- Here is a sample of extending the orbit controls class with decorators to automatically generate UI.
- ```typescript
- @uiPanelContainer('Orbit Controls')
- export class OrbitControlsWithUi extends OrbitControls implements IUiConfigContainer {
- // for autocomplete
- uiConfig?: UiObjectConfig<void, 'panel'>
-
- @uiToggle() enabled = true
-
- @uiToggle() dollyZoom = false
- @uiToggle() enableDamping = true
- @uiInput() dampingFactor = 0.08
-
- @uiToggle() autoRotate = false
- @uiInput() autoRotateSpeed = 2.0
-
- @uiToggle() enableZoom = true
- @uiInput() zoomSpeed = 0.15
- @uiInput() maxZoomSpeed = 0.20
-
- @uiToggle() enableRotate = true
- @uiInput() rotateSpeed = 2.0
-
- @uiToggle() enablePan = true
- @uiInput() panSpeed = 1.0
-
- @uiInput() autoPushTarget = false
- @uiInput() autoPullTarget = false
- @uiInput() minDistance = 0.35
- @uiInput() maxDistance = 1000
-
- @uiInput() minZoom = 0.01
- @uiInput() maxZoom = 1000
-
- @uiInput() minPolarAngle = 0
- @uiInput() maxPolarAngle = Math.PI
-
- @uiInput() minAzimuthAngle = -10000 // should be -Infinity but this breaks the UI
- @uiInput() maxAzimuthAngle = 10000
-
- }
- ```
-
- Check out the full source code:
- [./src/three/controls/OrbitControls3.ts](./src/three/controls/OrbitControls3.ts) for proper implementation
-
- See it in action: https://threepipe.org/examples/#camera-uiconfig/ Open the Camera UI and click on the Orbit Controls panel.
-
- There are many available decorators like `uiToggle`, `uiSlider`, `uiInput`, `uiNumber`, `uiColor`, `uiImage`.
- Check the complete list in the [uiconfig.js documentation](https://repalash.com/uiconfig.js/).
-
- The UI configuration can also be created using json objects in both typescript and javascript
- ```javascript
- const viewer = new ThreeViewer({...})
-
- const ui = viewer.addPluginSync(TweakpaneUiPlugin)
-
- const state = {
- position: new Vector3(),
- scale: 1,
- }
-
- ui.appendChild({
- type: 'folder',
- label: 'Custom UI',
- children: [
- {
- type: 'vec3',
- label: 'Position',
- property: [state, 'position']
- },
- {
- type: 'slider',
- label: ()=>'Scale', // everything can be a function as well.
- property: [state, 'scale'],
- bounds: [1, 2],
- stepSize: 0.1,
- }
- ]
- })
- ```
- TODO: create example/codepen for this
-
-
- ## Serialization
-
- Easy serialization of all threepipe and most three.js objects are supported out of the box using the Asset Manager.
- Fine control over serialization is also supported
- using the [ThreeSerialization](https://threepipe.org/docs/classes/ThreeSerialization.html) class
-
- Call `ThreeSerialization.serialize` on any object to serialize it.
- and `ThreeSerialization.deserialize` to deserialize the serialized object.
-
- This is done by performing a nested serialization of all the properties of the object.
- It's possible to implement custom serializers for custom types and classes and is done for three.js primitives,
- objects and plugins in threepipe
-
- To make a custom data class that is serializable,
- mark it using `@serializable` decorator and any properties using `@serialize` decorator.
- ```typescript
- @serializable('DataClass')
- class DataClass{
- @serialize() prop1 = 1
- @serialize() prop2 = 'string'
- @serialize() prop3 = new Vector3()
- @serialize() prop4 = new PhysicalMaterial()
- @serialize() prop4 = {
- prop1: 1,
- prop2: 'string',
- prop3: new Vector3(),
- prop4: new PhysicalMaterial(),
- }
- }
-
- const data = new DataClass()
- const serialized = ThreeSerialization.serialize(data)
- const deserialized = ThreeSerialization.deserialize(serialized)
- ```
-
- The classes without a `@serializable` decorator are serialized as plain objects.
- These can still include `@serialize` decorator to mark the properties are serializable
- but these classes cannot be deserialized into a new instance of the class.
- The ThreeViewer and plugins are an example of these.
- When deserialized they need an object to deserialize into.
- This ensures there is always just one instance.
- With this, the serialization system works like `toJSON` and `fromJSON` methods in three.js.
-
- Check the [plugin system](#plugin-system) below for more details on how to mark properties as serializable for plugins.
-
- ```typescript
- class CustomClass{
- @serialize() prop1 = 1
- @serialize() prop2 = 'string'
- @serialize() prop3 = new Vector3()
- @serialize() prop4 = new PhysicalMaterial()
- }
- const obj = new DataClass()
- const serialized = ThreeSerialization.serialize(data)
- // now to deserialize we need to pass in the object to deserialize into
- ThreeSerialization.deserialize(serialized, obj)
- ```
-
- ## Plugin System
-
- Threepipe includes a plugin system for adding additional features to the viewer in a modular way.
- The plugins can be added synchronously or asynchronously using `viewer.addPluginSync` and `viewer.addPlugin` methods respectively.
-
- It is recommended to create custom plugins for reusable features,
- as they provide built-in features for ui configuration,
- serialization, integration with editors etc and are easy to manage and tree-shake in the code.
-
- Check out the list of plugins in the [Plugin List](#threepipe-plugins) section below.
-
- To create new plugins,
- simply implement the `IViewerPlugin` interface or extend the [AViewerPluginSync](https://threepipe.org/docs/classes/AViewerPluginSync.html) or [AViewerPluginAsync](https://threepipe.org/docs/classes/AViewerPluginAsync.html) classes.
- The only difference is that in async the `onAdded` and `onRemove` functions are async
-
- Here is a sample plugin
- ```typescript
- @uiFolder("Sample Plugin") // This creates a folder in the Ui. (Supported by TweakpaneUiPlugin)
- export class SamplePlugin extends AViewerPluginSync<"sample-1" | "sample-2"> {
- // These are the list of events that this plugin can dispatch.
- static readonly PluginType = "SamplePlugin"; // This is required for serialization and handling plugins. Also used in viewer.getPluginByType()
-
- @uiToggle() // This creates a checkbox in the Ui. (Supported by TweakpaneUiPlugin)
- @serialize() // Adds this property to the list of serializable. This is also used when serializing to glb in AssetExporter.
- enabled = true;
-
- // A plugin can have custom properties.
-
- @uiSlider("Some Number", [0, 100], 1) // Adds a slider to the Ui, with custom bounds and step size (Supported by TweakpaneUiPlugin)
- @serialize("someNumber")
- @onChange(SamplePlugin.prototype._updateParams) // this function will be called whenevr this value changes.
- val1 = 0;
-
- // A plugin can have custom properties.
- @uiInput("Some Text") // Adds a slider to the Ui, with custom bounds and step size (Supported by TweakpaneUiPlugin)
- @onChange(SamplePlugin.prototype._updateParams) // this function will be called whenevr this value changes.
- @serialize()
- val2 = "Hello";
-
- @uiButton("Print Counters") // Adds a button to the Ui. (Supported by TweakpaneUiPlugin)
- public printValues = () => {
- console.log(this.val1, this.val2);
- this.dispatchEvent({ type: "sample-1", detail: { sample: this.val1 } }); // This will dispatch an event.
- }
-
- constructor() {
- super();
- this._updateParams = this._updateParams.bind(this);
- }
-
- private _updateParams() {
- console.log("Parameters updated.");
- this.dispatchEvent({ type: "sample-2" }); // This will dispatch an event.
- }
-
- onAdded(v: ThreeViewer): void {
- super.onAdded(v);
-
- // Do some initialization here.
- this.val1 = 0;
- this.val2 = "Hello";
-
- v.addEventListener("preRender", this._preRender);
- v.addEventListener("postRender", this._postRender);
- v.addEventListener("preFrame", this._preFrame);
- v.addEventListener("postFrame", this._postFrame);
-
- this._viewer!.scene.addEventListener("addSceneObject", this._objectAdded); // this._viewer can also be used while this plugin is attached.
- }
-
- onRemove(v: ThreeViewer): void {
- // remove dispose objects
-
- v.removeEventListener("preRender", this._preRender);
- v.removeEventListener("postRender", this._postRender);
- v.removeEventListener("preFrame", this._preFrame);
- v.removeEventListener("postFrame", this._postFrame);
-
- this._viewer!.scene.removeEventListener("addSceneObject", this._objectAdded); // this._viewer can also be used while this plugin is attached.
-
- super.onRemove(v);
- }
-
- private _objectAdded = (ev: IEvent<any>) => {
- console.log("A new object, texture or material is added to the scene.", ev.object);
- };
- private _preFrame = (ev: IEvent<any>) => {
- // This function will be called before each frame. This is called even if the viewer is not dirty, so it's a good place to do viewer.setDirty()
- };
- private _preRender = (ev: IEvent<any>) => {
- // This is called before each frame is rendered, only when the viewer is dirty.
- };
- // postFrame and postRender work the same way as preFrame and preRender.
- }
- ```
-
- Notes:
- * All plugins that are present in the dependencies array when the plugin is added to the viewer, are created and attached to the viewer in `super.onAdded`
- * Custom events can be dispatched with `this.dispatchEvent`, and subscribed to with `plugin.addEventListener`. The event type must be described in the class signature for typescript autocomplete to work.
- * Event listeners and other hooks can be added and removed in `onAdded` and `onRemove` functions for the viewer and other plugins.
- * To the viewer render the next frame, `viewer.setDirty()` can be called, or set `this.dirty = true` in preFrame and reset in postFrame to stop the rendering. (Note that rendering may continue if some other plugin sets the viewer dirty like `ProgressivePlugin` or any of the animation plugins). Check `isConverged` in `ProgressivePlugin` to check if its the final frame.
- * All Plugins which inherit from AViewerPlugin support serialisation. Create property `serializeWithViewer = false` to disable serialisation with the viewer in config and glb or `toJSON: any = undefined` to disable serialisation entirely
- * `plugin.toJSON()` and `plugin.fromJSON()` or `ThreeSerialization` can be used to serialize and deserialize plugins. `viewer.exportPluginConfig` and `viewer.importPluginConfig` also exist for this.
- * @serialize('label') decorator can be used to mark any public/private variable as serializable. label (optional) corresponds to the key in JSON.
- * @serialize supports instances of ITexture, IMaterial, all primitive types, simple JS objects, three.js math classes(Vector2, Vector3, Matrix3...), and some more.
- * uiDecorators can be used to mark properties and functions that will be shown in the Ui. The Ui shows up automatically when TweakpaneUiPlugin/BlueprintJsUiPlugin is added to the viewer. Plugins have special features in the UI for download preset and saving state.
-
- Check various plugins in the source code for more examples.
-
- # Viewer API
-
- [ThreeViewer](https://threepipe.org/docs/classes/ThreeViewer.html) - is the main entry point to 3d rendering on the canvas.
- - `.renderManager`: [ViewerRenderManager](https://threepipe.org/docs/classes/ViewerRenderManager.html) & [RenderManager](https://threepipe.org/docs/classes/RenderManager.html) & [RenderTargetManager](https://threepipe.org/docs/classes/RenderTargetManager.html) - Render manager for managing the rendering and composition pipeline, and provides helpers for rendering and render target management
- - `.renderer`: [IWebGLRenderer](https://threepipe.org/docs/interfaces/IWebGLRenderer.html) - for rendering. Instance of three.js [WebGLRenderer](https://threejs.org/docs/#api/en/renderers/WebGLRenderer)
- - `.composer`: [EffectComposer2](https://threepipe.org/docs/classes/EffectComposer2.html) - for rendering passes. Instance of three.js [EffectComposer](https://threejs.org/docs/#api/en/postprocessing/EffectComposer)
- - `.context`: [WebGLRenderingContext](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext) - WebGL rendering context
- - `.renderPass`: [ExtendedRenderPass](https://threepipe.org/docs/classes/ExtendedRenderPass.html) - Render pass for rendering the scene. Instance of three.js [RenderPass](https://threejs.org/docs/#api/en/postprocessing/RenderPass) with extra features
- - `.screenPass`: [ScreenPass](https://threepipe.org/docs/classes/ScreenPass.html) - Screen pass for rendering the final output. Instance of three.js [ShaderPass](https://threejs.org/docs/#api/en/postprocessing/ShaderPass) with extra features.
- - `.scene`: [RootScene](https://threepipe.org/docs/classes/RootScene.html) - Main scene used for rendering. Instance of three.js [Scene](https://threejs.org/docs/#api/en/scenes/Scene)
- - `.mainCamera`: [PerspectiveCamera2](https://threepipe.org/docs/classes/PerspectiveCamera2.html) - Main camera currently being used for rendering. Instance of three.js [PerspectiveCamera](https://threejs.org/docs/#api/en/cameras/PerspectiveCamera)
- - `.assetManager`: [AssetManager](https://threepipe.org/docs/classes/AssetManager.html) - Asset manager for loading, managing and exporting assets
- - `.importer`: [AssetImporter](https://threepipe.org/docs/classes/AssetImporter.html) - for importing assets
- - `.exporter`: [AssetExporter](https://threepipe.org/docs/classes/AssetExporter.html) - for exporting assets
- - `.materialManager`: [MaterialManager](https://threepipe.org/docs/classes/MaterialManager.html) - for managing materials and material extensions
- - `.plugins`: `Record`<`string`, [IViewerPlugin](https://threepipe.org/docs/interfaces/IViewerPlugin.html)> - Plugins added to the viewer
- - `.uiConfig`: [UiObjectConfig](https://repalash.com/uiconfig.js/interfaces/UiObjectConfig.html) - UI confguration for the viewer. Used to automatically generate UIs for the viewer and plugins.
-
- ## ThreeViewer
-
- Source Code: [src/viewer/ThreeViewer.ts](./src/viewer/ThreeViewer.ts)
-
- API Reference: [ThreeViewer](https://threepipe.org/docs/classes/ThreeViewer.html)
-
- `ThreeViewer` is the main entry point to the viewer. It provides all the API for managing the scene, camera, rendering, plugins, etc.
-
- It is initialized with either a canvas element or a `HTMLElement` for the container.
- The canvas element is used for rendering, and the options are used to configure the viewer.
- If the canvas element is not provided, a new canvas element is created and appended to the container.
-
- More options can be passed in the constructor to configure various built-in plugins and rendering features in the viewer.
-
- ### Constructor
-
- ```typescript
- import {ThreeViewer, CameraViewPlugin} from 'threepipe'
-
- // Create a viewer. All options except canvas/container are optional
- const viewer = new ThreeViewer({
- canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
- // or a container like:
- // container: document.getElementById('mcontainer'),
- // container: document.body,
-
- // Set the render scale to render at device resolution and clamp to max 2.
- renderScale: 'auto',
- // or Set the render scale to render at device resolution
- // renderScale: window.devicePixelRatio,
- // modify the screen shader: See ScreenPass and ScreenPass.glsl for more details
- screenShader: `diffuseColor = diffuseColor * 2.0;`,
-
- // Add TonemapPlugin
- tonemap: true,
- // Use MSAA(anti-aliasing)
- msaa: false,
- // Use Uint8 RGBM HDR Render Pipeline. Provides better performance with post-processing. RenderManager Uses Half-float if set to false.
- rgbm: true,
- // Use rendered gbuffer as depth-prepass / z-prepass.
- zPrepass: false,
-
- // Options for AssetManager
- assetManager: {
- // Use a custom CacheStorage
- storage: caches.open('threepipe-assetmanager'),
- },
-
- // Use DropzonePlugin to add support for file drag and drop
- // Enable and set properties
- dropzone: {
- // Set allowed extensions
- allowedExtensions: ['png', 'glb', 'gltf'],
- // Automatically add downloaded assets
- autoAdd: true
- // autoImport: true,
- // domElement: document.body,
- // addOptions: { ... }
- // importOptions: { ... }
- },
- // By default its false
- // dropzone: false,
- // To Enable without options
- // dropzone: true
-
- // Add some plugins after viewer creation.
- plugins: [CameraViewPlugin, new CustomPlugin()],
-
- // Shorthand to load files immediately after viewer initialization
- load: {
- src: 'https://example.com/file.glb',
- environment: 'https://example.com/file.hdr',
- background: 'https://example.com/file.png',
- },
- onLoad: (viewer) => {
- // Called when all the files are loaded
- },
- })
- ```
-
- Check the interface [ThreeViewerOptions](https://threepipe.org/docs/interfaces/ThreeViewerOptions.html) for all the options.
-
- To dispose off the viewer and all its resources call [`viewer.dispose()`](https://threepipe.org/docs/classes/ThreeViewer.html#dispose) method.
-
- To dispose only the scene objects and not the complete viewer, use `viewer.scene.disposeSceneModels()`
-
- ### Plugin Functions
-
- ```typescript
- import {ThreeViewer, TonemapPlugin, DepthBufferPlugin, NormalBufferPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- // Add a plugin
- const plugin = viewer.addPluginSync(new TonemapPlugin())
- // plugins can be added with just the class also
- const plugin2 = viewer.addPluginSync(TonemapPlugin)
-
- // Add multiple plugins at once
- viewer.addPluginsSync([
- TonemapPlugin,
- new NormalBufferPlugin(),
- DepthBufferPlugin,
- // ...
- ])
-
- // Get a plugin
- const plugin3 = viewer.getPlugin(TonemapPlugin)
-
- // Get or add a plugin, when not sure if the plugin is already added
- const plugin4 = viewer.getOrAddPluginSync(TonemapPlugin)
-
- // Remove a plugin
- viewer.removePluginSync(TonemapPlugin)
-
- ```
-
- Note: all sync functions above have async counterparts like `addPlugin`, `getOrAddPlugin`,
- `removePlugin` that are used for async plugins.
- There are no async plugins built-in to threepipe yet.
-
- ### Import/Export Functions
-
- ```typescript
- import {ThreeViewer} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- // Load a 3d model
- const object = await viewer.load<IObject3D>('https://example.com/file.glb')
-
- // Load a material
- const material = await viewer.load<PhysicalMaterial>('https://example.com/file.pmat')
-
- // Load an image
- const texture = await viewer.load<ITexture>('https://example.com/file.png')
-
- // Import a model without adding to the scene
- const imported = await viewer.import('https://example.com/file.glb')
-
- // Export the complete scene with viewer configuraion
- const exportedScene = await viewer.exportScene({})
-
- // Export an object
- const exported = await viewer.export(object)
-
- // Export a material
- const exportedMaterial = await viewer.export(material)
-
- // Export a texture
- const exportedTexture = await viewer.export(texture)
-
- // Export viewer and plugins configurations
- const exportedConfig = await viewer.export(viewer)
-
- // Export plugin configuration
- const exportedPlugin = await viewer.exportPlugin(viewer.getPlugin(PluginClass))
-
- // Set Background Image
- await viewer.setBackgroundMap('https://example.com/file.png')
-
- // Set Environment Map
- await viewer.setEnvironmentMap('https://example.com/file.hdr')
-
- // Add an imported object or a created three.js object to the scene
- viewer.addSceneObject(imported)
- ```
-
- [`viewer.load`](https://threepipe.org/docs/classes/ThreeViewer.html#load) - Loads a single asset by path or [IAsset](https://threepipe.org/docs/interfaces/IAsset.html) object, and adds to the scene if its 3d object or loads it if it's a configuration It is the same as [AssetManager.addAssetSingle](https://threepipe.org/docs/classes/AssetManager.html#addAssetSingle). Use [AssetManager.addAsset](https://threepipe.org/docs/classes/AssetManager.html#addAsset) to load multiple assets from the same path like in case of zip bundles.
-
- [`viewer.import`](https://threepipe.org/docs/classes/ThreeViewer.html#import) - Load a single asset but does not add to the scene or load the configuration. It is the same as [AssetManager.importer.importSingle](https://threepipe.org/docs/classes/AssetImporter.html#importSingle). Use [AssetManager.importer.import](https://threepipe.org/docs/classes/AssetImporter.html#import) to import multiple assets from the same path like in case of zip bundles.
-
- [`viewer.export`](https://threepipe.org/docs/classes/ThreeViewer.html#export) - Exports an object, material, texture, render target or plugin configuration and returns a Blob. It is similar to [AssetManager.exporter.exportObject](https://threepipe.org/docs/classes/AssetExporter.html#exportObject) but adds support for exporting plugin and self(viewer) configs.
-
- [`viewer.exportScene`](https://threepipe.org/docs/classes/ThreeViewer.html#exportScene) - Exports the scene model root and all configurations into a bundled `glb` file and returns a blob.
-
- [`viewer.exportPlugin`](https://threepipe.org/docs/classes/ThreeViewer.html#exportPlugin) - Exports a plugin configuration and returns a blob.
-
- [`viewer.setBackgroundMap`](https://threepipe.org/docs/classes/ThreeViewer.html#setBackgroundMap) - Sets the background map to the given texture or url. Also sets it as environment map if `setEnvironment` is `true` in the options.
-
- [`viewer.setEnvironmentMap`](https://threepipe.org/docs/classes/ThreeViewer.html#setEnvironmentMap) - Sets the environment map to the given texture or url. Also sets it as background if `setBackground` is `true` in the options.
-
- [`viewer.addSceneObject`](https://threepipe.org/docs/classes/ThreeViewer.html#addSceneObject) - Adds an imported object or a created three.js object to the scene model root. If an imported scene model root is passed, it will be loaded with viewer configuration, unless `importConfig` is `false` in the options.
-
- ### Frame/Rendering Events
-
- ```typescript
- import {ThreeViewer} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- // Add a callback to be called before every frame, irrespective of whether enything is being rendered that frame
- viewer.addEventListener('preFrame', (ev)=>{
- console.log(ev);
- // change something
- viewer.setDirty() // let the viewer know to re-render the scene from this frame
- })
-
- // Add a callback to be called after every frame, irrespective of whether enything was rendered that frame
- viewer.addEventListener('postFrame', (ev)=>{
- console.log(ev);
- // change something
- viewer.setDirty() // let the viewer know to re-render the scene from next frame
- })
-
- // Add a callback to be called before every render, only if something is being rendered that frame
- viewer.addEventListener('preRender', (ev)=>{
- // canvas is about to be rendered, or re-rendered for progressive rendering
- console.log(ev, viewer.renderManager.frameCount);
- })
-
- // Add a callback to be called after every render, only if something was rendered that frame
- viewer.addEventListener('postRender', (ev)=>{
- // canvas is rendered, or re-rendered for progressive rendering
- console.log(ev);
- })
-
- // Listen to viewer.setDirty() calls
- viewer.addEventListener('update', (ev)=>{
- // viewer.setDirty() was called by some plugin or code
- console.log(ev);
- })
-
- // to remove an event listener, first keep a reference to the callback
- const callback = (ev)=>{ return }
- viewer.addEventListener('preFrame', callback)
- // then remove it
- viewer.removeEventListener('preFrame', callback)
-
- // Add a callback to be called only once for an event
- viewer.doOnce('postFrame', () => viewer.canvas.toDataURL('image/png'))
-
- // Enable/disable rendering in the viewer
- viewer.renderEnabled = false
- // do something with the canvas or load assets
- await viewer.load('https://example.com/file.glb')
- await viewer.load('https://example.com/file1.glb')
- await viewer.load('https://example.com/file2.glb')
- viewer.renderEnabled = true // all the assets will be rendered together in the next frame
-
- ```
-
- Check the [IViewerEvent](https://threepipe.org/docs/interfaces/IViewerEvent.html) interface for all the event types.
-
- [`viewer.addEventListener`](https://threepipe.org/docs/classes/ThreeViewer.html#addEventListener) - Adds a callback to be called on the given event. The callback is called with an [IViewerEvent](https://threepipe.org/docs/interfaces/IViewerEvent.html) object.
-
- [`viewer.removeEventListener`](https://threepipe.org/docs/classes/ThreeViewer.html#removeEventListener) - Removes a callback from the given event.
-
- [`viewer.doOnce`](https://threepipe.org/docs/classes/ThreeViewer.html#doOnce) - Adds a callback to be called only once for the given event. The listener will be added and automatically removed after the first call.
-
- ### Utility Functions
-
- ```typescript
- import {ThreeViewer} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- // Set the final render size directly and fit in container based on mode.
- viewer.setRenderSize({width: 800, height: 600}, 'cover')
-
- // Set size of the canvas
- viewer.setSize({width: 800, height: 600})
- // Set the render scale
- viewer.renderManager.renderScale = Math.min(window.devicePixelRatio, 2)
-
-
- // Traverse scene objects
- viewer.traverseSceneObjects((object) => {
- console.log(object)
- // do something with object
- })
-
- // If the size is set by css or manually by javascript use `resize` to update the viewer
- viewer.resize()
-
- // Trigger re-render with `setDirty` when something changes and viewer is not notified internally
- viewer.setDirty()
-
- // Get snapshot of the canvas as a blob
- const blob = await viewer.getScreenshotBlob({mimeTye: 'image/png', quality: 90})
-
- // Get snapshot of the canvas as a data url
- const dataUrl = await viewer.getScreenshotDataUrl({mimeTye: 'image/jpeg', quality: 85})
-
- // Dispose viewer and all resources
- viewer.canvas.remove() // canvas needs to be removed separately from the DOM
- viewer.dispose()
-
- ```
-
- [`viewer.setRenderSize`](https://threepipe.org/docs/classes/ThreeViewer.html#setRenderSize) - Sets the rendering resolution and fits the canvas in container based on the mode. The modes are `cover`, `contain`, `fill`, `scale-down` and `none`. The canvas size and render scale is calculated automatically to match the render render.
-
- [`viewer.setSize`](https://threepipe.org/docs/classes/ThreeViewer.html#setSize) - Sets the size of the canvas and updates the renderer and the camera. If no width/height is passed, canvas is set to 100% of the container.
-
- [`viewer.traverseSceneObjects`](https://threepipe.org/docs/classes/ThreeViewer.html#traverseSceneObjects) - Loop through all the objects in the scene model root hierarchy and calls the callback function with each object.
-
- [`viewer.resize`](https://threepipe.org/docs/classes/ThreeViewer.html#resize) - Mark that the canvas is resized. If the size is changed, the renderer and all render targets are resized.
-
- [`viewer.setDirty`](https://threepipe.org/docs/classes/ThreeViewer.html#setDirty) - Triggers re-render on next `requestAnimationFrame` call.
-
- [`viewer.getScreenshotBlob`](https://threepipe.org/docs/classes/ThreeViewer.html#getScreenshotBlob) - Returns a blob of the canvas screenshot. The blob can be used to download the screenshot or upload to a server.
-
- [`viewer.getScreenshotDataUrl`](https://threepipe.org/docs/classes/ThreeViewer.html#getScreenshotDataUrl) - Returns a data url of the canvas screenshot. The data url can be used to display the screenshot in an image element.
-
- [`viewer.dispose`](https://threepipe.org/docs/classes/ThreeViewer.html#dispose) - Disposes the viewer and all its resources. Use this to dispose the viewer when it is no longer needed. Note: the canvas element is not removed from the DOM and needs to be removed separately.
-
- ## RenderManager
-
- Source Code: [src/viewer/ViewerRenderManager.ts](./src/viewer/ViewerRenderManager.ts), [src/rendering/RenderManager.ts](./src/rendering/RenderManager.ts), [src/rendering/RenderTargetManager.ts](./src/rendering/RenderTargetManager.ts)
-
- API Reference: [ViewerRenderManager](https://threepipe.org/docs/classes/ViewerRenderManager.html), [RenderManager](https://threepipe.org/docs/classes/RenderManager.html), [RenderTargetManager](https://threepipe.org/docs/classes/RenderTargetManager.html)
-
- It manages the rendering, composition/postprocessing of the scene and provides helpers for rendering and render target management.
-
- ```typescript
- const viewer = new ThreeViewer({...})
-
- const renderManager = viewer.renderManager
-
- // Get the effect composer
- const composer = renderManager.composer
-
- // Get the three.js webgl renderer
- const renderer = renderManager.renderer
-
- // Get the main Render Pass in the pipeline
- const renderPass = renderManager.renderPass
-
- // Get the main Screen Pass in the pipeline
- const screenPass = renderManager.screenPass
-
- // Set the render scale
- renderManager.renderScale = Math.min(window.devicePixelRatio, 2)
-
- // Register a custom composer pass
- const customPass: IPipelinePass = new CustomPass()
- renderManager.registerPass(customPass)
-
- // Unregister a custom composer pass
- renderManager.unregisterPass(customPass)
-
- // The pipeline is automatically created and sorted based on dependencies in pipeline pass.
- // To check the built pipeline
- console.log(renderManager.pipeline)
-
- // Set a custom render pipeline
- renderManager.autoBuildPipeline = false
- renderManager.pipeline = ['depth', 'render', 'screen']
-
- // Check the total frames rendererd
- console.log(renderManager.totalFrameCount)
-
- // Get the current frame count in progressive rendering
- console.log(renderManager.frameCount)
-
- // Force reset shadows when some object is moved
- renderManager.resetShadows()
-
- // Render Target Management
-
- // Get the main composer target
- const composerTarget = renderManager.composerTarget
- // clone the target to get a copy of the target with all the default options
- const clonedTarget = composeTarget.clone()
-
- // Create a render target, same size as the canvas. The target are automatically resized when the canvas is resized
- const renderTarget = renderManager.createTarget({
- sizeMultiplier: 1, // size multiplier from the canvas. 0.5 will be half width and height of the canvas
- type: UnsignedByteType,
- // ... // See CreateRenderTargetOptions for all options
- })
-
- // Create a render target of custom size
- const renderTarget = renderManager.createTarget({
- size: {
- width: 1024,
- height: 1024,
- },
- type: HalfFloatType,
- // ...
- })
-
- // Dispose the render target
- renderManager.disposeTarget(renderTarget)
-
- // Create and release temporary targets for in-pass rendering.
- const tempTarget = renderManager.getTempTarget({
- sizeMultiplier: 0.5,
- type: HalfFloatType,
- // ...
- })
- // do something
- renderManager.releaseTempTarget(tempTarget)
-
- // Set how many temporary targets can remain in memory for a specific set of options
- renderManager.maxTempPerKey = 10 // default = 5
-
- // Copy/Blit a texture to the canvas or another render target with standard or a custom material
- renderManager.blit(destination, {source: sourceTexture})
-
- // Clear color of the canvas
- renderManager.clearColor({r: 0, g: 0, b: 0, a: 1, depth: true, viewport: new Vector4(...)})
-
- // Clear of a render target
- renderManager.clearColor(renderTarget, {r: 0, g: 0, b: 0, a: 1, target: renderTarget})
-
- // Export a render target to a blob. The type is automatically picked from exr to png based on the render target
- const blob = renderManager.exportRenderTarget(renderTarget, 'auto')
-
- // Export a render target to png/jpeg data url. This will clamp any floating point targets to fit in png/jpeg
- const dataUrl = renderManager.renderTargetToDataUrl(renderTarget, 'image/png')
-
- // Read render target pixels to array buffer. Returns Uint8Array|Uint16Array|Float32Array based on the render target type
- const buffer = renderManager.renderTargetToBuffer(renderTarget)
-
- ```
-
- [`renderManager.composer`](https://threepipe.org/docs/classes/ViewerRenderManager.html#composer) - The three.js [EffectComposer](https://threejs.org/docs/#api/en/postprocessing/EffectComposer) used for rendering the pipeline.
-
- [`renderManager.renderer`](https://threepipe.org/docs/classes/ViewerRenderManager.html#renderer) - The three.js [WebGLRenderer](https://threejs.org/docs/#api/en/renderers/WebGLRenderer) used for rendering
-
- [`renderManager.context`](https://threepipe.org/docs/classes/ViewerRenderManager.html#context) - Access the WebGL rendering context for the canvas.
-
- [`renderManager.renderPass`](https://threepipe.org/docs/classes/ViewerRenderManager.html#renderPass) - The main render pass used in the render pipeline. Instance of three.js [RenderPass](https://threejs.org/docs/#api/en/postprocessing/RenderPass) with extra features like z prepass, rgbm rendering, blurred transmission, msaa and other optimizations.
-
- [`renderManager.screenPass`](https://threepipe.org/docs/classes/ViewerRenderManager.html#screenPass) - The main screen pass used in the render pipeline. Instance of three.js [ShaderPass](https://threejs.org/docs/#api/en/postprocessing/ShaderPass) with extra features like material extension, custom fragment, overriding read buffer, re-render to screen on change, etc
-
- [`renderManager.renderScale`](https://threepipe.org/docs/classes/RenderManager.html#renderScale) - Sets the render scale. All targets are scaled by this factor. This is equivalent to calling `EffectComposer.setPixelRatio` and `WebGLRenderer.setPixelRatio` in three.js.
-
- [`renderManager.resetShadows`](https://threepipe.org/docs/classes/RenderManager.html#resetShadows) - Resets all shadow maps in the scene. This is useful when some object is moved and the shadows need to be updated. This is automatically called when `scene.setDirty` or any `object.setDirty` is called, and during animation with plugins.
-
- ### Rendering Pipeline
-
- [`renderManager.registerPass`](https://threepipe.org/docs/classes/RenderManager.html#registerPass) - Registers a custom composer pass to the render pipeline. See [IPipelinePass](https://threepipe.org/docs/interfaces/IPipelinePass.html) interface.
-
- [`renderManager.unregisterPass`](https://threepipe.org/docs/classes/RenderManager.html#unregisterPass) - Unregisters a custom composer pass from the render pipeline.
-
- [`renderManager.pipeline`](https://threepipe.org/docs/classes/RenderManager.html#pipeline) - The render pipeline array. The array is automatically sorted based on dependencies in the pipeline passes.
-
- [`renderManager.autoBuildPipeline`](https://threepipe.org/docs/classes/RenderManager.html#autoBuildPipeline) - If `true`, the pipeline is automatically created and sorted based on dependencies in pipeline pass. If `false`, the pipeline is built only once and is not changed after that. The default value is `true`.
-
- [`renderManager.totalFrameCount`](https://threepipe.org/docs/classes/RenderManager.html#totalFrameCount) - The total frames rendered since the render manager was created.
-
- [`renderManager.frameCount`](https://threepipe.org/docs/classes/RenderManager.html#frameCount) - The current frame count in progressive rendering. This is useful for progressive rendering effects like progressive shadows, gi, denoising, baking, anti-aliasing, and many other effects.
-
- ### Render Targets management
-
- [`renderManager.composerTarget`](https://threepipe.org/docs/classes/RenderManager.html#composerTarget), [`renderManager.composerTarget1`](https://threepipe.org/docs/classes/RenderManager.html#composerTarget1) - The main targets used in [EffectComposer2](https://threepipe.org/docs/classes/EffectComposer2)
-
- [`renderManager.createTarget`](https://threepipe.org/docs/classes/RenderTargetManager.html#createTarget) - Creates a render target with the given options. The render target is automatically resized when the canvas is resized if `sizeMultiplier` is used. See [CreateRenderTargetOptions](https://threepipe.org/docs/interfaces/CreateRenderTargetOptions.html) for options
-
- [`renderManager.disposeTarget`](https://threepipe.org/docs/classes/RenderTargetManager.html#disposeTarget) - Disposes a render target and removes it from the render target manager.
-
- [`renderManager.getTempTarget`](https://threepipe.org/docs/classes/RenderTargetManager.html#getTempTarget) - Gets a temporary render target with the given options. The render target is automatically resized when the canvas is resized if `sizeMultiplier` is used. See [CreateRenderTargetOptions](https://threepipe.org/docs/interfaces/CreateRenderTargetOptions.html) for options
-
- [`renderManager.releaseTempTarget`](https://threepipe.org/docs/classes/RenderTargetManager.html#releaseTempTarget) - Releases a temporary render target and adds it back to the render target manager.
-
- [`renderManager.maxTempPerKey`](https://threepipe.org/docs/classes/RenderTargetManager.html#maxTempPerKey) - Sets how many temporary targets can remain in memory for a specific set of options. The default value is `5`.
-
- ### Helpers
-
- [`renderManager.blit`](https://threepipe.org/docs/classes/RenderManager.html#blit) - Blits a texture to the canvas or another render target with standard or a custom material. See [RendererBlitOptions](https://threepipe.org/docs/interfaces/RendererBlitOptions.html) for options.
-
- [`renderManager.clearColor`](https://threepipe.org/docs/classes/RenderManager.html#clearColor) - Clears the color of the canvas or a render target.
-
- [`renderManager.exportRenderTarget`](https://threepipe.org/docs/classes/RenderManager.html#exportRenderTarget) - Exports a render target to a blob. The type is automatically picked from exr to png based on the render target.
-
- [`renderManager.renderTargetToDataUrl`](https://threepipe.org/docs/classes/RenderManager.html#renderTargetToDataUrl) - Exports a render target to png/jpeg data url string. This will clamp any floating point targets to fit in png/jpeg. See [RenderTargetToDataUrlOptions](https://threepipe.org/docs/interfaces/RenderTargetToDataUrlOptions.html) for options.
-
- [`renderManager.renderTargetToBuffer`](https://threepipe.org/docs/classes/RenderManager.html#renderTargetToBuffer) - Reads render target pixels to a Uint8Array|Uint16Array|Float32Array array buffer.
-
- ## RootScene
-
- Source Code: [src/core/object/RootScene.ts](./src/core/object/RootScene.ts)
-
- API Reference: [RootScene](https://threepipe.org/docs/classes/RootScene.html)
-
- RootScene is the main scene that is rendered in the canvas.
- It is an instance of three.js [Scene](https://threejs.org/docs/#api/en/scenes/Scene) with extra features including separation between model root and others,
- backgroundColor, background map and background intensity,
- environment map rotation and intensity, fixed env map direction patch, event bubbling in the scene hierarchy, scene config serialization, main camera management,
- automatic active near far management based on scene bounds, disposing complete scene hierarchy, etc
-
- ```typescript
-
- const viewer = new ThreeViewer({...})
-
- const scene = viewer.scene
-
- // List oll loaded objects in the model root
- console.log(scene.modelRoot.children)
-
- // Set the background color
- scene.setBackgroundColor('#ffffff')
- // or
- // scene.backgroundColor = new Color('#ffffff')
- // or
- // scene.backgroundColor.set('#ffffff')
- // scene.onBackgroundChange() // this must be called when not using a setter or set function.
-
- // Set a texture as background (or use viewer.setBackgroundMap). When both color and texture are set, they are multiplied
- scene.background = customTexture
-
- // Set the background same as the environment map
- scene.background = 'environment' // background is automatically changed when the environment changes.
- // or
- // scene.background = scene.environment
-
- // Set the background intensity
- scene.backgroundIntensity = 2
-
- // Set a texture as environment map (or use viewer.setEnvironmentMap)
- scene.environment = customTexture
-
- // Set the environment intensity
- scene.envMapIntensity = 2
-
- // Set the environment map rotation
- scene.environment.rotation = Math.PI / 2
-
- // Set Fixed env direction (rotate environment according the the camera)
- scene.fixedEnvMapDirection = true
-
- // Get the main camera used for rendering
- const camera: PerspectiveCamera2 = scene.mainCamera
- // Set camera props
- camera.position.set(0, 0, 10)
- camera.target.set(0, 0, 0)
- camera.setDirty() // this needs to be called to notify the viewer to re-render the scene
-
- // Traverse the model root hierarchy (or just use viewer.traverseSceneObjects)
- scene.modelRoot.traverse((object) => {
- console.log(object)
- // do something with object
- })
-
- // Access the default camera (same as mainCamera if not changed explicitly)
- const defaultCamera: ICamera = scene.defaultCamera
-
- // Dispose all assets in the modelRoot
- scene.disposeSceneModels()
-
- // Remove all objects from the modelRoot
- scene.clearSceneModels()
-
- // Dispose the scene and all its resources and children
- scene.dispose()
-
- // Get bounds of the scene model root
- const bounds = scene.getBounds(true, true) // true for precise bounds and ignore invisible
-
- // Add an object to the scene or its model root depending on the options (or just use viewer.addSceneObject)
- scene.addObject(object, {addToRoot: false}) // adds to the scene directly when addToRoot is true
-
- // Load an imported model root from the asset importer
- scene.loadModelRoot(object)
-
- // notify that something has changed in the scene for re-render
- scene.setDirty()
-
- // notify that some object has changed in the scene for scene refresh(like shadow refresh, ground etc) and re-render
- scene.refreshScene()
- // or
- scene.setDirty({refreshScene: true})
-
- // set geometryChanged: false to prevent shadow recompute
- scene.refreshScene({geometryChanged: false})
-
- // refresh active near far. (in most cases this is done automatically and need not be called)
- scene.refreshActiveNearFar()
- ```
-
- [`scene.modelRoot`](https://threepipe.org/docs/classes/RootScene.html#modelRoot) - The root object. All the objects loaded in the viewer are added to this object. And this is exported when exporting the gltf. Everything else like meta or UI objects can be added outside this.
-
- [`scene.backgroundColor`](https://threepipe.org/docs/classes/RootScene.html#backgroundColor) - The background color of the scene. Can be a `Color | null`. This is not the same as `scene.background`. When both backgroundColor and background are set, they are multiplied.
-
- [`scene.background`](https://threepipe.org/docs/classes/RootScene.html#background) - The background of the scene. This is the same as `scene.background` in three.js. This can be a texture or a color or null, but it's preferred to use `scene.backgroundColor` for color, and this for texture, then both can be used together.
-
- [`scene.setBackgroundColor`](https://threepipe.org/docs/classes/RootScene.html#setBackgroundColor) - Set the background color from a string, number or color. Same as setting `backgroundColor` to a new color value.
-
- [`scene.backgroundIntensity`](https://threepipe.org/docs/classes/RootScene.html#backgroundIntensity) - The background intensity of the scene. This is the same as `scene.backgroundIntensity` in three.js.
-
- [`scene.environment`](https://threepipe.org/docs/classes/RootScene.html#environment) - The environment map of the scene. This is the same as `scene.environment` in three.js.
-
- `scene.environment.rotation` - The rotation of the environment map around the y-axis.
-
- [`scene.envMapIntensity`](https://threepipe.org/docs/classes/RootScene.html#envMapIntensity) - The environment intensity of the scene.
-
- [`scene.fixedEnvMapDirection`](https://threepipe.org/docs/classes/RootScene.html#fixedEnvMapDirection) - If `true`, the environment map is rotated according to the camera. This is the same as `scene.fixedEnvMapDirection` in three.js.
-
- [`scene.mainCamera`](https://threepipe.org/docs/classes/RootScene.html#mainCamera) - The main camera used for rendering. This is the same as `scene.mainCamera` in three.js.
-
- [`scene.defaultCamera`](https://threepipe.org/docs/classes/RootScene.html#defaultCamera) - The default camera used for rendering. This is the same as `scene.defaultCamera` in three.js.
-
- [`scene.disposeSceneModels`](https://threepipe.org/docs/classes/RootScene.html#disposeSceneModels) - Disposes all assets in the modelRoot.
-
- [`scene.clearSceneModels`](https://threepipe.org/docs/classes/RootScene.html#clearSceneModels) - Removes all objects from the modelRoot.
-
- [`scene.dispose`](https://threepipe.org/docs/classes/RootScene.html#dispose) - Disposes the scene and all its resources and children.
-
- [`scene.getBounds`](https://threepipe.org/docs/classes/RootScene.html#getBounds) - Gets the bounds of the scene model root. Returns an instance of three.js [Box3](https://threejs.org/docs/#api/en/math/Box3) with min and max bounds according to parameters.
-
- [`scene.addObject`](https://threepipe.org/docs/classes/RootScene.html#addObject) - Adds an object to the scene or its model root depending on the options. If `addToRoot` is `true`, the object is added to the model root, else it is added to the scene directly.
-
- [`scene.setDirty`](https://threepipe.org/docs/classes/RootScene.html#setDirty) - Notifies that something has changed in the scene for re-render.
-
- [`scene.refreshScene`](https://threepipe.org/docs/classes/RootScene.html#refreshScene) - Notifies that some object has changed in the scene for scene refresh(like shadow refresh, ground etc) and re-render. Slower than `setDirty`, as it refreshes shadows, updates bounds, etc.
-
- [`scene.refreshActiveNearFar`](https://threepipe.org/docs/classes/RootScene.html#refreshActiveNearFar) - Refreshes active near far. (in most cases this is done automatically and need not be called)
-
- [`scene.loadModelRoot`](https://threepipe.org/docs/classes/RootScene.html#loadModelRoot) - Loads an imported model root from the asset importer. This is used internally and in most cases, you don't need to call this.
-
- ### Scene Events
-
- RootScene dispatches many events that are useful when writing app logic or plugins
-
- `'sceneUpdate'` - Listen to `refreshScene` called in RootScene. When some object changes.
-
- `'addSceneObject'` - When a new object is added to the scene
-
- `'mainCameraChange'` - When the main camera is changed to some other camera.
-
- `'mainCameraUpdate'` - When some properties in the current main camera has changed.
-
- `'environmentChanged'` - When the environment map changes
-
- `'backgroundChanged'` - When the background map or color changes
-
- `'materialUpdate`' - When a material in the scene has updated. (setDirty called on the material)
-
- `'objectUpdate`' - When a object in the scene has updated. (setDirty called on the object)
-
- `'textureUpdate`' - When a texture in the scene has updated. (setDirty called on the texture)
-
- `'cameraUpdate`' - When a camera in the scene has updated.
- (setDirty called on the camera)
-
- `'geometryUpdate`' - When a geometry in the scene has updated.
- (setDirty called on the geometry)
-
- `'geometryChanged`' - When a geometry is changed on any mesh
-
- `'materialChanged'` - When a material is changed on any mesh
-
- Check [IObject3DEventTypes](https://threepipe.org/docs/interfaces/IObject3DEventTypes.html) and[ISceneEventTypes](https://threepipe.org/docs/interfaces/ISceneEventTypes.html) for more information.
-
-
- ## ICamera
-
- Source Code: [src/core/camera/PerspectiveCamera2.ts](./src/core/camera/PerspectiveCamera2.ts), [src/core/ICamera.ts](./src/core/ICamera.ts)
-
- API Reference: [PerspectiveCamera2](https://threepipe.org/docs/classes/PerspectiveCamera2.html), [ICamera](https://threepipe.org/docs/interfaces/ICamera.html)
-
- ICamera is an interface for a camera that extends the three.js [Camera](https://threejs.org/docs/#api/en/cameras/Camera).
- PerspectiveCamera2 implements the interface,
- extending from three.js [PerspectiveCamera](https://threejs.org/docs/#api/en/cameras/PerspectiveCamera) with extra features like target, automatic aspect management, automatic near far management(from RootScene), camera control attachment and hooks(like OrbitControls) and the ability to set as the main camera in the root scene.
-
- ```typescript
- import {OrbitControls3} from './OrbitControls3'
-
- const viewer = new ThreeViewer({...})
-
- const camera: PerspectiveCamera2 = viewer.scene.mainCamera
-
- // Set the camera position
- camera.position.set(0, 0, 10)
-
- // Set the camera target (where the camera looks at)
- camera.target.set(0, 0, 0)
-
- // Set the camera fov
- camera.fov = 45
-
- // Set the camera aspect ratio
- camera.autoAspect = false // disable automatic aspect management based on the canvas size
- camera.aspect = 1
-
- // Set camera near far bounds.
- // Near, Far plane will be calculated automatically within these limits
- // Try changing these values when encountering z-fighting issues or far-plane clipping
- camera.minNearPlane = 0.5 // min near plane
- camera.maxFarPlane = 10 // max far plane
-
- // Set a custom camera near far
- camera.autoNearFar = false // disable automatic near far management based on the scene bounds
- camera.minNearPlane = 0.1 // near plane
- camera.maxFarPlane = 1000 // far plane
-
- // this needs to be called to notify the viewer to re-render the scene
- // in most cases this is done internally. But calling this does not have much impact
- camera.setDirty()
-
- // Check if user can interact with the camera. Also checks if its the main camera.
- console.log(camera.canUserInteract)
-
- // Get the camera controls (orbit controls for the default camera)
- const controls: OrbitControls3 = camera.controls
- // Disable controls
- controls.enabled = false
-
- // Change the controls mode
- camera.controlsMode = 'none' // this will remove the current controls.
-
- // Register a custom camera controls
- camera.setControlsCtor('customOrbit', (camera, domElement) => new CustomOrbitControls(camera, domElement))
-
- // Set the camera controls
- camera.controlsMode = 'customOrbit' // this will initialize the controls with the customOrbit constructor and set it on the camera
-
- // Disable interactions to the camera. (eg when animating)
- camera.setInteractions(false, 'animation')
- // Enable interactions back
- camera.setInteractions(true, 'animation') // this will enable interactions when all the keys have been set to true(which were set to false earlier)
-
- // Force refresh aspect ratio (this is done automatically with a ResizeObserver on the canvas in the viewer)
- camera.refreshAspect()
-
- // Set the camera as the main camera
- camera.activateMain()
- // Deactivate the camera as the main camera
- camera.deactivateMain()
- ```
-
- [`camera.target`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#target) - The target of the camera. This is the same as `controls.target` in three.js. The target is always in world-space coordinates, as opposed to position, rotation, and scale which are always relative to their parent.
-
- [`camera.autoAspect`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#autoAspect) - If `true`, the aspect ratio is automatically calculated based on the canvas size.
-
- [`camera.aspect`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#aspect) - The aspect ratio of the camera. This is the same as `camera.aspect` in three.js. This is only used when `camera.autoAspect` is `false`.
-
- [`camera.minNearPlane`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#minNearPlane) - The minimum near plane of the camera. This is the same as `camera.near` in three.js when `camera.autoNearFar` is `false`, otherwise it is the minimum near plane distance from the camera allowed when computing automatically
-
- [`camera.maxFarPlane`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#maxFarPlane) - The maximum far plane of the camera. This is the same as `camera.far` in three.js when `camera.autoNearFar` is `false`, otherwise it is the maximum far plane distance from the camera allowed when computing automatically
-
- [`camera.autoNearFar`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#autoNearFar) - If `true` (default), the near and far planes are automatically calculated based on the scene bounds.
-
- [`camera.setDirty`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#setDirty) - Notifies that something has changed in the camera for re-render.
-
- [`camera.canUserInteract`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#canUserInteract) - Checks if user can interact with the camera. Also checks if it's the main camera.
-
- [`camera.controls`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#controls) - Get the current camera controls set on the camera. This can be changed by changing `controlsMode`
-
- [`camera.controlsMode`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#controlsMode) - Get or set the current controls that are attached to the camera. More modes can be registered with `setControlsCtor`. Default for the default camera is `orbit` and `none` for any new cameras.
-
- [`camera.setControlsCtor`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#setControlsCtor) - Register a custom camera controls constructor. The controls can be set by setting `controlsMode` to the key/name of the controls.
-
- [`camera.setInteractions`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#setInteractions) - If `true`, the camera can be interacted with. This is useful when animating the camera or using the window scroll or programmatically automating the viewer. Using this multiple plugins can disable interactions and it will be enabled again when all of them enable it back.
-
- [`camera.refreshAspect`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#refreshAspect) - Force refresh aspect ratio (this is done automatically with a ResizeObserver on the canvas in the viewer or when `viewer.resize()` is called)
-
- [`camera.activateMain`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#activateMain) - Set the camera as the main camera. This is the same as doing `scene.mainCamera = camera`. The camera needs to be in the scene hierarchy for this to work.
-
- [`camera.deactivateMain`](https://threepipe.org/docs/classes/PerspectiveCamera2.html#deactivateMain) - Deactivate the camera as the main camera.
-
- See also [CameraViewPlugin](#cameraviewplugin) for camera focus animation.
-
- Note: The constructor signature of `PerspectiveCamera2` is different `PerspectiveCamera`(from three.js), since it requires the canvas and the controlsMode during creation.
- Because of this `PerspectiveCamera0` is provided with the same signature as `PerspectiveCamera` for compatibility, in case the controls functionality is not required.
-
- ## AssetManager
-
- Source Code: [src/assetmanager/AssetManager.ts](./src/assetmanager/AssetManager.ts)
-
- API Reference: [AssetManager](https://threepipe.org/docs/classes/AssetManager.html)
-
- `AssetManager` is a class that manages the loading and exporting of assets and provides helpers for caching assets. It is used internally in the viewer and can be used to load assets outside the viewer. It provides a modular framework for adding more asset loaders and exporters.
-
- ```typescript
- const viewer = new ThreeViewer({...})
-
- const assetManager = viewer.assetManager
-
- // Add an asset or an asset bundle
- const assets = await assetManager.addAsset('https://example.com/model.zip')
- // or
- const assets = await assetManager.addAsset({
- path: 'https://example.com/model.zip',
- file: blob,
- })
-
- // Get the storage used in the asset manager for caching
- const storage: Cache | Storage = assetManager.storage
-
- // Get the importer. Provides low level functions to import assets
- const importer = assetManager.importer
-
- // import a file by asset or url
- const file = await importer.import('https://example.com/model.gltf')
-
- // Import a Map<string, File> from drag drop
- const res = await importer.importFiles(mapOfFiles, {})
-
- // Register a custom path that maps to a File object. Useful when some file types have path references to other files.
- importer.registerFile('/myFile.png', file) // this returns the three.js loader for that kind of file.
- // Unregister the path
- importer.unregisterFile('/myFile.png')
-
- // Unregister all files and clear the loader cache(memory, not storage)
- importer.clearCache()
-
- // Add custom importers (check extra load plugins for more examples)
- importer.addImporter(new Importer(class extends PLYLoader implements ILoader {
- transform(res: BufferGeometry, _: AnyOptions): Mesh | undefined {
- return res ? new Mesh(res, new PhysicalMaterial({color: new Color(1, 1, 1)})) : undefined
- }
- }, ['ply'], ['text/plain+ply'], false))
-
- // Get the exporter. Provides low level functions to export assets
- const exporter = assetManager.exporter
-
- // Export any IObject3D, IMaterial, ITexture, IRenderTarget
- const exported = exporter.exportObject(obj, options)
-
- // Add a custom exporter
- exporter.addExporter({
- ext: ['gltf', 'glb'], // file extensions
- extensions: [], // extensions for the exporter
- ctor: (assetExporter, iexporter) => {
- return new GLTFExporter2()
- }
- })
-
-
- // Material Manager
-
- const materialManager = assetManager.materialManager
-
- // Create a material of type
- const mat = materialManager.create('physical')
- const mat2 = materialManager.create('unlit')
-
- // find or create a material by uuid
- const mat = materialManager.findOrCreate('00000000-0000-0000-0000-000000000000', {color: '#ffffff'})
-
- // find a material creation template
- const template = materialManager.findTemplate('physical')
-
- // Get all materials
- const materials = materialManager.getAllMaterials()
-
- // Get all materials of type
- const materials = materialManager.getMaterialsOfType(PhysicalMaterial.TypeSlug)
-
- // register a custom material to the manager for tracking and extensions
- // Note all materials created in threepipe internally are registered automatically on creation or when added to any scene object.
- materialManager.registerMaterial(customMat)
- // unregister
- materialManager.unregisterMaterial(customMat)
-
- // clear all material references
- materialManager.clearMaterials()
-
- // Register a custom material template
- materialManager.registerTemplate({
- generator: (params: any) => new PhysicalMaterial(params),
- name: 'custom',
- materialType: PhysicalMaterial.TYPE,
- params: {
- color: '#ffffff',
- roughness: 0.5,
- metalness: 0.5,
- },
- })
- const mat3 = materialManager.create('custom')
-
- // convert a standard three.js material to threepipe material
- const mat4 = materialManager.convertToIMaterial(new ShadowMaterial(), {materialTemplate: 'test'})
-
- // register a custom material extension for all materials in the viewer
- materialManager.registerMaterialExtension(customExtension)
- // unregister
- materialManager.unregisterMaterialExtension(customExtension)
- // remove all extensions
- materialManager.clearExtensions()
-
- // Apply a material properties to other material(s) in the scene by name or uuid
- materialManager.applyMaterial(goldMaterial, 'METAL') // this will copy the properties from goldMaterial to all the materials(or objects) in the viewer with the name METAL.
-
- // export a material as JSON. Note: use AssetExporter instead to export all the embedded assets and properties properly.
- const blob = materialManager.exportMaterial(mat)
-
- // dispose manager and all materials.
- materialManager.dispose()
- ```
-
- [`assetManager.addAsset`](https://threepipe.org/docs/classes/AssetManager.html#addAsset) - Add an asset or an asset bundle. Returns a promise that resolves to an array of asset objects. An asset can contain multiple objects, hence an array is returned. Use shorthand `viewer.load(path)` to load a single asset from a single file.
-
- [`assetManager.storage`](https://threepipe.org/docs/classes/AssetManager.html#storage) - Get the storage used in the asset manager for caching. This is the storage that can be passed in the `ThreeViewer` contructor options.
-
- [`assetManager.importer`](https://threepipe.org/docs/classes/AssetManager.html#importer) - Get the importer. Provides low-level functions to import assets. This is an instance of [AssetImporter](https://threepipe.org/docs/classes/AssetImporter.html).
-
- [`assetManager.exporter`](https://threepipe.org/docs/classes/AssetManager.html#exporter) - Get the exporter. Provides low-level functions to export assets. This is an instance of [AssetExporter](https://threepipe.org/docs/classes/AssetExporter.html).
-
- ### AssetImporter
-
- [`importer.import`](https://threepipe.org/docs/classes/AssetImporter.html#import) - Import a file by asset or url. Returns a promise that resolves to a [File](https://threepipe.org/docs/classes/File.html) object.
-
- [`importer.importFiles`](https://threepipe.org/docs/classes/AssetImporter.html#importFiles) - Import a Map<string, File> from drag and drop. Returns a promise that resolves to a Map<string, any[]> of imported object arrays.
-
- [`importer.registerFile`](https://threepipe.org/docs/classes/AssetImporter.html#registerFile) - Register a custom path that maps to a File object. Useful when some file types have path references to other files. Like when importing a .zip with a .gltf file that references a .bin file, or when loading remote files from custom local cache implementation.
-
- [`importer.unregisterFile`](https://threepipe.org/docs/classes/AssetImporter.html#unregisterFile) - Unregister the path.
-
- [`importer.clearCache`](https://threepipe.org/docs/classes/AssetImporter.html#clearCache) - Unregister all the registered files and clear the loader cache(memory cache, not cache-storage).
-
- [`importer.addImporter`](https://threepipe.org/docs/classes/AssetImporter.html#addImporter) - Add custom importers (check extra load plugins for more examples). This allows to pass a class to a ILoader, that is used to import assets. Loaders are only created when a file is being loaded of that type. And they remain in the loader cache until `clearCache` or `clearLoaderCache` is called.
-
- ### AssetExporter
-
- [`exporter.exportObject`](https://threepipe.org/docs/classes/AssetExporter.html#exportObject) - Export any IObject3D, IMaterial, ITexture, IRenderTarget. Returns a promise that resolves to an exported object. Use `viewer.export` or `AssetExporterPlugin`, which provide more features and shortcuts to export viewer, scene and plugins as well.
-
- [`exporter.addExporter`](https://threepipe.org/docs/classes/AssetExporter.html#addExporter) - Add a custom exporter for a custom file type.
-
- ### MaterialManager
-
- [`materialManager.create`](https://threepipe.org/docs/classes/MaterialManager.html#create) - Create a new material of a given type and with passed properties. Returns an implementation of [IMaterial](https://threepipe.org/docs/interfaces/IMaterial.html).
-
- [`materialManager.findOrCreate`](https://threepipe.org/docs/classes/MaterialManager.html#findOrCreate) - Find or create a material by uuid. Returns an instance of [IMaterial](https://threepipe.org/docs/interfaces/IMaterial.html). If a material with the uuid exists, it is returned, else a new material is created with the passed properties.
-
- [`materialManager.findTemplate`](https://threepipe.org/docs/classes/MaterialManager.html#findTemplate) - Find a material creation template. Returns an instance of [IMaterialTemplate](https://threepipe.org/docs/interfaces/IMaterialTemplate.html). Material templates are used to create materials of a given type with default properties.
-
- [`materialManager.getAllMaterials`](https://threepipe.org/docs/classes/MaterialManager.html#getAllMaterials) - Get all materials registered with the manager.
-
- [`materialManager.getMaterialsOfType`](https://threepipe.org/docs/classes/MaterialManager.html#getMaterialsOfType) - Get all materials of a specific type. Pass in the typeslug from the class like `pmat` or `dmat` to identify the material.
-
- [`materialManager.registerMaterial`](https://threepipe.org/docs/classes/MaterialManager.html#registerMaterial) - Register a new material to the manager for tracking and extensions. Note: all materials created in threepipe internally or any that are set to any object in the scene are registered automatically on creation or when used
-
- [`materialManager.unregisterMaterial`](https://threepipe.org/docs/classes/MaterialManager.html#unregisterMaterial) - Unregister a material from the manager.
-
- [`materialManager.clearMaterials`](https://threepipe.org/docs/classes/MaterialManager.html#clearMaterials) - Clear all registered material references.
-
- [`materialManager.registerTemplate`](https://threepipe.org/docs/classes/MaterialManager.html#registerTemplate) - Register a custom material template. Requires an instance of [IMaterialTemplate](https://threepipe.org/docs/interfaces/IMaterialTemplate.html). Material templates are used to create materials of a given type with default properties.
-
- [`materialManager.convertToIMaterial`](https://threepipe.org/docs/classes/MaterialManager.html#convertToIMaterial) - Convert/upgrade a standard three.js material to threepipe material, by making it conform to [IMaterial](https://threepipe.org/docs/interfaces/IMaterial.html).
-
- [`materialManager.registerMaterialExtension`](https://threepipe.org/docs/classes/MaterialManager.html#registerMaterialExtension) - Register a custom material extension for all materials in the viewer. Requires an instance of [IMaterialExtension](https://threepipe.org/docs/interfaces/IMaterialExtension.html). Material extensions are used to add custom properties, methods, uniforms, defines, shader patches etc to predefined materials. The extensions are added to the material when the mateiral or extension is registered to the manager.
-
- [`materialManager.unregisterMaterialExtension`](https://threepipe.org/docs/classes/MaterialManager.html#unregisterMaterialExtension) - Unregister a material extension from the manager.
-
- [`materialManager.clearExtensions`](https://threepipe.org/docs/classes/MaterialManager.html#clearExtensions) - Remove all material extensions from the manager.
-
- [`materialManager.applyMaterial`](https://threepipe.org/docs/classes/MaterialManager.html#applyMaterial) - Apply a material properties to other material(s) in the scene by name or uuid. This is useful when you want to change the properties of all materials with a given name or uuid. This can also be a regex, in that case a regex.match will be performed on the material/object name.
-
- [`materialManager.exportMaterial`](https://threepipe.org/docs/classes/MaterialManager.html#exportMaterial) - Export a material as JSON. Note: use `viewer.export` or `AssetExporter` instead to export all the embedded assets properly.
-
- [`materialManager.dispose`](https://threepipe.org/docs/classes/MaterialManager.html#dispose) - Dispose manager and all materials.
-
- ## Other classes and interfaces
-
- Threepipe provides various interfaces and classes for for three.js objects with upgraded features like UI events, serialization, etc.
- These can be used while developing new apps to get better developer experience and features.
- When standard three.js instances are added to the scene, they are automatically upgraded automatically at runtime to make them work with the rest of the framework.
-
- Some important interfaces:
-
- * [IObject3D](https://threepipe.org/docs/interfaces/IObject3D.html) - Interface for an extended version of three.js [Object3D](https://threejs.org/docs/#api/en/core/Object3D).
- * [ILight](https://threepipe.org/docs/interfaces/ILight.html) - Interface for an extended version of three.js [Light](https://threejs.org/docs/#api/en/lights/Light).
- * [ICamera](https://threepipe.org/docs/interfaces/ICamera.html) - Interface for an extended version of three.js [Camera](https://threejs.org/docs/#api/en/cameras/Camera).
- * [IMaterial](https://threepipe.org/docs/interfaces/IMaterial.html) - Interface for an extended version of three.js [Material](https://threejs.org/docs/#api/en/materials/Material).
- * [ITexture](https://threepipe.org/docs/interfaces/ITexture.html) - Interface for an extended version of three.js [Texture](https://threejs.org/docs/#api/en/textures/Texture).
- * [IRenderTarget](https://threepipe.org/docs/interfaces/IRenderTarget.html) - Interface for an extended version of three.js [WebGLRenderTarget](https://threejs.org/docs/#api/en/renderers/WebGLRenderTarget).
- * [IGeometry](https://threepipe.org/docs/interfaces/IGeometry.html) - Interface for an extended version of three.js [BufferGeometry](https://threejs.org/docs/#api/en/core/BufferGeometry).
- * [IScene](https://threepipe.org/docs/interfaces/IScene.html) - Interface for an extended version of three.js [Scene](https://threejs.org/docs/#api/en/scenes/Scene).
- * [IRenderManager](https://threepipe.org/docs/interfaces/IRenderManager.html) - Interface for rendering and render target manager.
-
- Some important classes
-
- * [Mesh2](https://threepipe.org/docs/classes/Mesh2.html) - Extends three.js [Mesh](https://threejs.org/docs/#api/en/objects/Mesh) and implements [IObject3D](https://threepipe.org/docs/interfaces/IObject3D.html).
- * [PerspectiveCamera2](https://threepipe.org/docs/classes/PerspectiveCamera2.html) - Extends three.js [PerspectiveCamera](https://threejs.org/docs/#api/en/cameras/PerspectiveCamera) and implements [ICamera](https://threepipe.org/docs/interfaces/ICamera.html). (different constructor than PerspectiveCamera)
- * [PerspectiveCamera0](https://threepipe.org/docs/classes/PerspectiveCamera0.html) - Extends three.js [PerspectiveCamera](https://threejs.org/docs/#api/en/cameras/PerspectiveCamera) and implements [ICamera](https://threepipe.org/docs/interfaces/ICamera.html). (same constructor than PerspectiveCamera)
- * [BufferGeometry2](https://threepipe.org/docs/classes/BufferGeometry2.html) - Extends three.js [BufferGeometry](https://threejs.org/docs/#api/en/core/BufferGeometry) and implements [IGeometry](https://threepipe.org/docs/interfaces/IGeometry.html).
- * [RootScene](https://threepipe.org/docs/classes/RootScene.html) - Extends three.js [Scene](https://threejs.org/docs/#api/en/scenes/Scene) and implements [IScene](https://threepipe.org/docs/interfaces/IScene.html).
- * [RenderManager](https://threepipe.org/docs/classes/RenderManager.html) - Implements [IRenderManager](https://threepipe.org/docs/interfaces/IRenderManager.html).
- * [PhysicalMaterial](https://threepipe.org/docs/classes/PhysicalMaterial.html) - Extends three.js [MeshPhysicalMaterial](https://threejs.org/docs/#api/en/materials/MeshPhysicalMaterial) and implements [IMaterial](https://threepipe.org/docs/interfaces/IMaterial.html).
- * [UnlitMaterial](https://threepipe.org/docs/classes/UnlitMaterial.html) - Extends three.js [MeshBasicMaterial](https://threejs.org/docs/#api/en/materials/MeshBasicMaterial) and implements [IMaterial](https://threepipe.org/docs/interfaces/IMaterial.html).
- * [LineMaterial2](https://threepipe.org/docs/classes/LineMaterial2.html) - Extends three.js [LineMaterial](https://threejs.org/docs/#api/en/materials/LineMaterial) and implements [IMaterial](https://threepipe.org/docs/interfaces/IMaterial.html).
- * [UnlitLineMaterial](https://threepipe.org/docs/classes/UnlitLineMaterial.html) - Extends three.js [LineBasicMaterial](https://threejs.org/docs/#api/en/materials/LineBasicMaterial) and implements [IMaterial](https://threepipe.org/docs/interfaces/IMaterial.html).
- * [DirectionalLight2](https://threepipe.org/docs/classes/DirectionalLight2.html) - Extends three.js [DirectionalLight](https://threejs.org/docs/#api/en/lights/DirectionalLight) and implements [ILight](https://threepipe.org/docs/interfaces/ILight.html).
- * [SpotLight2](https://threepipe.org/docs/classes/SpotLight2.html) - Extends three.js [SpotLight](https://threejs.org/docs/#api/en/lights/SpotLight) and implements [ILight](https://threepipe.org/docs/interfaces/ILight.html).
- * [PointLight2](https://threepipe.org/docs/classes/PointLight2.html) - Extends three.js [PointLight](https://threejs.org/docs/#api/en/lights/PointLight) and implements [ILight](https://threepipe.org/docs/interfaces/ILight.html).
- * [HemisphereLight2](https://threepipe.org/docs/classes/HemisphereLight2.html) - Extends three.js [HemisphereLight](https://threejs.org/docs/#api/en/lights/HemisphereLight) and implements [ILight](https://threepipe.org/docs/interfaces/ILight.html).
- * [AmbientLight2](https://threepipe.org/docs/classes/AmbientLight2.html) - Extends three.js [AmbientLight](https://threejs.org/docs/#api/en/lights/AmbientLight) and implements [ILight](https://threepipe.org/docs/interfaces/ILight.html).
- * [RectAreaLight2](https://threepipe.org/docs/classes/RectAreaLight2.html) - Extends three.js [RectAreaLight](https://threejs.org/docs/#api/en/lights/RectAreaLight) and implements [ILight](https://threepipe.org/docs/interfaces/ILight.html).
-
- # Threepipe Plugins
-
- ThreePipe has a simple plugin system that allows you to easily add new features to the viewer. Plugins can be added to the viewer using the `addPlugin` and `addPluginSync` methods. The plugin system is designed to be modular and extensible. Plugins can be added to the viewer at any time and can be removed using the `removePlugin` and `removePluginSync` methods.
-
- ## TonemapPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#tonemap-plugin/) —
- [Source Code](./src/plugins/postprocessing/TonemapPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/TonemapPlugin.html)
-
- TonemapPlugin adds a post-processing material extension to the ScreenPass in render manager
- that applies tonemapping to the color. The tonemapping operator can be changed
- by setting the `toneMapping` property of the plugin. The default tonemapping operator is `ACESFilmicToneMapping`.
-
- Other Tonemapping properties can be like `exposure`, `contrast` and `saturation`
-
- TonemapPlugin is added by default in ThreeViewer unless `tonemap` is set to `false` in the options.
-
- ## DropzonePlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#dropzone-plugin/) —
- [Source Code](./src/plugins/interaction/DropzonePlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/DropzonePlugin.html)
-
- DropzonePlugin adds support for drag and drop of local files to automatically import, process and load them into the viewer.
-
- DropzonePlugin can be added by default in ThreeViewer
- by setting the `dropzone` property to `true` or an object of `DropzonePluginOptions` in the options.
-
- ```typescript
- import {DropzonePlugin, ThreeViewer} from 'threepipe'
- const viewer = new ThreeViewer({
- canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
- dropzone: true, // just set to true to enable drag drop functionatility in the viewer
- })
- ```
-
- To set custom options,
- pass an object of [DropzonePluginOptions](https://threepipe.org/docs/interfaces/DropzonePluginOptions.html) type to the `dropzone` property.
- ```typescript
- import {DropzonePlugin, ThreeViewer} from 'threepipe'
- const viewer = new ThreeViewer({
- canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
- dropzone: { // this can also be set to true and configured by getting a reference to the DropzonePlugin
- allowedExtensions: ['gltf', 'glb', 'hdr', 'png', 'jpg', 'json', 'fbx', 'obj', 'bin', 'exr'], // only allow these file types. If undefined, all files are allowed.
- addOptions: {
- disposeSceneObjects: true, // auto dispose of old scene objects
- autoSetEnvironment: true, // when hdr is dropped
- autoSetBackground: true, // when any image is dropped
- autoCenter: true, // auto center the object
- autoScale: true, // auto scale according to radius
- autoScaleRadius: 2,
- license: 'Imported from dropzone', // Any license to set on imported objects
- importConfig: true, // import config from file
- },
- // check more options in the DropzonePluginOptions interface
- },
- })
- ```
-
- ## ProgressivePlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#progressive-plugin/) —
- [Source Code](./src/plugins/pipeline/ProgressivePlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/ProgressivePlugin.html)
-
- Progressive Plugin adds a post-render pass to blend the last frame with the current frame.
-
- This is used as a dependency in other plugins for progressive rendering effect which is useful for progressive shadows, gi, denoising, baking, anti-aliasing, and many other effects. The helper function `convergedPromise` returns a new promise that can be used to wait for the progressive rendering to converge.
-
- ## SSAAPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#ssaa-plugin/) —
- [Source Code](./src/plugins/pipeline/SSAAPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/SSAAPlugin.html)
-
- SSAA Plugin adds support for [Super Sampling Anti-Aliasing](https://en.wikipedia.org/wiki/Supersampling) to the viewer. Simply add the plugin to the viewer to use it.
-
- It jitters the camera view offset over multiple frames, which are then blended by the [ProgressivePlugin](#progressiveplugin) to create a higher quality image. This is useful for reducing aliasing artifacts in the scene.
-
- By default, the pipeline only renders once per request animation frame. So we don't get any anti-aliasing while moving. For that, either use the TAA(Temporal Anti-aliasing) plugin or for the case of simple scenes - render multiple times per frame which can be done by setting `plugin.rendersPerFrame` or `viewer.rendersPerFrame`. Check out the [example](https://threepipe.org/examples/#ssaa-plugin/) to see the effect on frame rate.
-
- ```typescript
-
- const ssaa = viewer.addPluginSync(new SSAAPlugin())
-
- ssaa.enabled = true // toggle jittering(if you want to set custom view offset)
-
- ssaa.rendersPerFrame = 4 // render 4 times per frame (max 32 is useful)
- ```
-
- ## DepthBufferPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#depth-buffer-plugin/) —
- [Source Code](./src/plugins/pipeline/DepthBufferPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/DepthBufferPlugin.html)
-
- Depth Buffer Plugin adds a pre-render pass to the render manager and renders a depth buffer to a target. The render target can be accessed by other plugins throughout the rendering pipeline to create effects like depth of field, SSAO, SSR, etc.
-
- ```typescript
- import {ThreeViewer, DepthBufferPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const depthPlugin = viewer.addPluginSync(new DepthBufferPlugin(HalfFloatType))
-
- const depthTarget = depthPlugin.target;
-
- // Use the depth target by accesing `depthTarget.texture`.
- ```
-
- The depth values are based on camera near far values, which are controlled automatically by the viewer. To manually specify near, far values and limits, it can be set in the camera userData. Check the [example](https://threepipe.org/examples/#depth-buffer-plugin/) for more details.
-
- ## NormalBufferPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#normal-buffer-plugin/) —
- [Source Code](./src/plugins/pipeline/NormalBufferPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/NormalBufferPlugin.html)
-
- Normal Buffer Plugin adds a pre-render pass to the render manager and renders a normal buffer to a target. The render target can be accessed by other plugins throughout the rendering pipeline to create effects like SSAO, SSR, etc.
-
- Note: Use [`GBufferPlugin`](#GBufferPlugin) if using both `DepthBufferPlugin` and `NormalBufferPlugin` to render both depth and normal buffers in a single pass.
-
- ```typescript
- import {ThreeViewer, NormalBufferPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const normalPlugin = viewer.addPluginSync(new NormalBufferPlugin())
-
- const normalTarget = normalPlugin.target;
-
- // Use the normal target by accessing `normalTarget.texture`.
- ```
-
- ## GBufferPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#gbuffer-plugin/) —
- [Source Code](./src/plugins/pipeline/GBufferPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/GBufferPlugin.html)
-
- GBuffer Plugin adds a pre-render pass to the render manager and renders depth+normals to a target and some customizable flags to another. The multiple render target and textures can be accessed by other plugins throughout the rendering pipeline to create effects like SSAO, SSR, etc.
-
- ```typescript
- import {ThreeViewer, GBufferPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const gBufferPlugin = viewer.addPluginSync(new GBufferPlugin())
-
- const gBuffer = gBufferPlugin.target;
- const normalDepth = gBufferPlugin.normalDepthTexture;
- const gBufferFlags = gBufferPlugin.flagsTexture;
- ```
-
- ## SSAOPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#ssao-plugin/) —
- [Source Code](./src/plugins/pipeline/SSAOPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/SSAOPlugin.html)
-
- SSAO Plugin adds support for [Screen Space Ambient Occlusion](https://en.wikipedia.org/wiki/Screen_space_ambient_occlusion) to the viewer. Simply add the plugin to the viewer to use it.
-
- This is done by adding a pre-render pass to the render manager which renders SSAO to a custom render target. SSAOPlugin depends on [GBufferPlugin](#gbufferplugin), and is automatically added if not already.
-
- This render target is then used by all PhysicalMaterial(s) in the scene during the main RenderPass to get the AO data. SSAO can also be disabled from the UI of the material.
-
- Note: Use with [ProgressivePlugin](#progressiveplugin) and `TemporalAAPlugin` for best results.
-
- ```typescript
- import {ThreeViewer, SSAOPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const ssaoPlugin = viewer.addPluginSync(new SSAOPlugin())
-
- // get the buffer.
- console.log(ssaoPlugin.target);
-
- // disable ssao for a material in the scene
- material.userData.ssaoDisabled = true
- ```
- > In the target/buffer - The ssao data is in the `r` channel to remain compatible with ORM. `gba` contains the depth in vec3(xyz) format.
- > Note that its `ssaoDisabled`, so setting it to `true` will disable the effect.
-
-
- ## CanvasSnapshotPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#canvas-snapshot-plugin/) —
- [Source Code](./src/plugins/export/CanvasSnapshotPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/CanvasSnapshotPlugin.html)
-
- Canvas Snapshot Plugin adds support for taking snapshots of the canvas and exporting them as images and data urls. It includes options to take snapshot of a region, mime type, quality render scale and scaling the output image. Check out the interface [CanvasSnapshotOptions](https://threepipe.org/docs/interfaces/CanvasSnapshotOptions.html) for more details.
-
- ```typescript
- import {ThreeViewer, CanvasSnapshotPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const snapshotPlugin = viewer.addPluginSync(new CanvasSnapshotPlugin())
-
- // download a snapshot.
- await snapshotPlugin.downloadSnapshot('image.webp', { // all parameters are optional
- scale: 1, // scale the final image
- timeout: 0, // wait before taking the snapshot, in ms
- quality: 0.9, // quality of the image (0-1) only for jpeg and webp
- displayPixelRatio: 2, // render scale
- mimeType: 'image/webp', // mime type of the image
- waitForProgressive: true, // wait for progressive rendering to finish (ProgressivePlugin). true by default
- rect: { // region to take snapshot. eg. crop center of the canvas
- height: viewer.canvas.clientHeight / 2,
- width: viewer.canvas.clientWidth / 2,
- x: viewer.canvas.clientWidth / 4,
- y: viewer.canvas.clientHeight / 4,
- },
- })
-
- // get data url (string)
- const dataUrl = await snapshotPlugin.getDataUrl({ // all parameters are optional
- displayPixelRatio: 2, // render scale
- mimeType: 'image/webp', // mime type of the image
- })
-
- // get File
- const file = await snapshotPlugin.getFile('file.jpeg', { // all parameters are optional
- mimeType: 'image/jpeg', // mime type of the image
- })
- ```
-
- ## PickingPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#picking-plugin/) —
- [Source Code](./src/plugins/interaction/PickingPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/PickingPlugin.html)
-
- Picking Plugin adds support for selecting and hovering over objects in the viewer with user interactions and selection widgets.
-
- When the plugin is added to the viewer, it starts listening to the mouse move and click events over the canvas.
- When an object is clicked, it is selected,
- and if a UI plugin is added, the uiconfig for the selected object is populated in the interface.
- The events `selectedObjectChanged`, `hoverObjectChanged`, and `hitObject` can be listened to on the plugin.
-
- Picking plugin internally uses [ObjectPicker](https://threepipe.org/docs/classes/ObjectPicker.html),
- check out the documentation or source code for more information.
-
- ```typescript
- import {ThreeViewer, PickingPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const pickingPlugin = viewer.addPluginSync(new PickingPlugin())
-
- // Hovering events are also supported, but since its computationally expensive for large scenes it is disabled by default.
- pickingPlugin.hoverEnabled = true
-
- pickingPlugin.addEventListener('hitObject', (e)=>{
- // This is fired when the user clicks on the canvas.
- // The selected object hasn't been changed yet, and we have the option to change it or disable selection at this point.
-
- // e.intersects.selectedObject contains the object that the user clicked on.
- console.log('Hit: ', e.intersects.selectedObject)
- // It can be changed here
- // e.intersects.selectedObject = e.intersects.selectedObject.parent // select the parent
- // e.intersects.selectedObject = null // unselect
-
- // Check other properties on the event like intersects, mouse position, normal etc.
- console.log(e)
- })
-
- pickingPlugin.addEventListener('selectedObjectChanged', (e)=>{
- // This is fired when the selected object is changed.
- // e.object contains the new selected object. It can be null if nothing is selected.
- console.log('Selected: ', e.object)
- })
-
- // Objects can be programmatically selected and unselected
-
- // to select
- pickingPlugin.setSelectedObject(object)
-
- // get the selected object
- console.log(pickingPlugin.getSelectedObject())
- // to unselect
- pickingPlugin.setSelectedObject(null)
-
- // Select object with camera animation to the object
- pickingPlugin.setSelectedObject(object, true)
-
- pickingPlugin.addEventListener('hoverObjectChanged', (e)=>{
- // This is fired when the hovered object is changed.
- // e.object contains the new hovered object.
- console.log('Hovering: ', e.object)
- })
-
- ```
-
- ## TransformControlsPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#transform-controls-plugin/) —
- [Source Code](./src/plugins/interaction/TransformControlsPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/TransformControlsPlugin.html)
-
- Transform Controls Plugin adds support for moving, rotating and scaling objects in the viewer with interactive widgets.
-
- Under the hood, TransformControlsPlugin uses [TransformControls2](https://threepipe.org/docs/classes/TransformControls2) to provide the interactive controls, it is a extended version of three.js [TransformControls](https://threejs.org/docs/#examples/en/controls/TransformControls).
-
- When the plugin is added to the viewer, it interfaces with the [PickingPlugin](#pickingplugin) and shows the control gizmos when an object is selected and hides them when the object is unselected.
-
- If the `PickingPlugin` is not added to the viewer before the `TransformControlsPlugin`, it is added automatically with the plugin.
-
- ```typescript
- import {ThreeViewer, TransformControlsPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const transfromControlsPlugin = viewer.addPluginSync(new TransformControlsPlugin())
-
- // Get the underlying transform controls
- console.log(transfromControlsPlugin.transformControls)
- ```
-
- ## ContactShadowGroundPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#contact-shadow-ground-plugin/) —
- [Source Code](./src/plugins/extras/ContactShadowGroundPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/ContactShadowGroundPlugin.html)
-
- Contact Shadow Ground Plugin adds a ground plane with three.js contact shadows to the viewer scene.
-
- The plane is added to the scene root at runtime and not saved with scene export. Instead the plugin settings are saved with the scene.
-
- It inherits from the base class [BaseGroundPlugin](https://threepipe.org/docs/classes/BaseGroundPlugin.html) which provides generic ground plane functionality. Check the source code for more details. With the property `autoAdjustTransform`, the ground plane is automatically adjusted based on the bounding box of the scene.
-
- ```typescript
- import {ThreeViewer, ContactShadowGroundPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- viewer.addPluginSync(new ContactShadowGroundPlugin())
- ```
-
- ## GLTFAnimationPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#gltf-animation-plugin/) —
- [Source Code](./src/plugins/animation/GLTFAnimationPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/GLTFAnimationPlugin.html)
-
- Manages playback of GLTF animations.
-
- The GLTF animations can be created in any 3d software that supports GLTF export like Blender.
- If animations from multiple files are loaded, they will be merged in a single root object and played together.
-
- The time playback is managed automatically, but can be controlled manually by setting {@link autoIncrementTime} to false and using {@link setTime} to set the time.
-
- This plugin is made for playing, pausing, stopping, all the animations at once, while it is possible to play individual animations, it is not recommended.
-
- To play individual animations, with custom choreography, use the {@link GLTFAnimationPlugin.animations} property to get reference to the animation clips and actions. Create your own mixers and control the animation playback like in three.js
-
- ## PopmotionPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#popmotion-plugin/) —
- [Source Code](./src/plugins/animation/PopmotionPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/PopmotionPlugin.html)
-
- Provides animation/tweening capabilities to the viewer using the [popmotion.io](https://popmotion.io/) library.
-
- Overrides the driver in popmotion to sync with the viewer and provide ways to store and stop animations.
-
- ```typescript
- import {PopmotionPlugin, ThreeViewer} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const cube = viewer.scene.getObjectByName('cube');
-
- const popmotion = viewer.addPluginSync(new PopmotionPlugin())
-
- // Move the object cube 1 unit up.
- const anim = popmotion.animateTarget(cube, 'position', {
- to: cube.position.clone().add(new Vector3(0,1,0)),
- duration: 500, // ms
- onComplete: () => isMovedUp = true,
- onStop: () => throw(new Error('Animation stopped')),
- })
-
- // Alternatively, set the property directly in onUpdate.
- const anim1 = popmotion.animate({
- from: cube.position.y,
- to: cube.position.y + 1,
- duration: 500, // ms
- onUpdate: (v) => {
- cube.position.setY(v)
- cube.setDirty()
- },
- onComplete: () => isMovedUp = true,
- onStop: () => throw(new Error('Animation stopped')),
- onEnd: () => console.log('Animation ended'), // This runs after both onComplete and onStop
- })
-
- // await for animation. This promise will reject only if an exception is thrown in onStop or onComplete. onStop rejects if throwOnStop is true
- await anim.promise.catch((e)=>{
- console.log(e, 'animation stopped before completion')
- });
-
- // or stop the animation
- // anim.stop()
-
- // Animate the color
- await popmotion.animateAsync({ // Also await for the animation.
- from: '#' + cube.material.color.getHexString(),
- to: '#' + new Color().setHSL(Math.random(), 1, 0.5).getHexString(),
- duration: 1000, // 1s
- onUpdate: (v) => {
- cube.material.color.set(v)
- cube.material.setDirty()
- },
- })
- ```
-
- Note: The animation is started when the animate or animateAsync function is called.
-
- ## CameraViewPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#camera-view-plugin/) —
- [Source Code](./src/plugins/animation/CameraViewPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/CameraViewPlugin.html)
-
- CameraViewPlugin adds support to save and load camera views, which can then be animated to.
- It uses PopmotionPlugin internally to animate any camera to a saved view or to loop through all the saved views.
-
- It also provides a UI to manage the views.
-
- ```typescript
- import {CameraViewPlugin, ThreeViewer, CameraView, Vector3, Quaternion, EasingFunctions, timeout} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const cameraViewPlugin = viewer.addPluginSync(new CameraViewPlugin())
-
- const intialView = cameraViewPlugin.getView()
- // or = viewer.scene.mainCamera.getView()
-
- // create a new view
- const view = new CameraView(
- 'My View', // name
- new Vector3(0, 0, 10), // position
- new Vector3(0, 0, 0), // target
- new Quaternion(0, 0, 0, 1), // quaternion rotation
- 1 // zoom
- )
-
- // or clone a view
- const view2 = intialView.clone()
- view2.position.add(new Vector3(0, 5, 0)) // move up 5 units
-
- // animate the main camera to a view
- await cameraViewPlugin.animateToView(
- view,
- 2000, // in ms, = 2sec
- EasingFunctions.easeInOut,
- ).catch(()=>console.log('Animation stopped'))
-
- // stop any/all animations
- cameraViewPlugin.stopAllAnimations()
-
- // add views to the plugin
- cameraViewPlugin.addView(view)
- cameraViewPlugin.addView(view2)
- cameraViewPlugin.addView(intialView)
- cameraViewPlugin.addCurrentView() // adds the current view of the main camera
-
- // loop through all the views once
- cameraViewPlugin.animDuration = 2000 // default duration
- cameraViewPlugin.animEase = EasingFunctions.easeInOutSine // default easing
- await cameraViewPlugin.animateAllViews()
-
- // loop through all the views forever
- cameraViewPlugin.viewLooping = true
- await timeout(10000) // wait for some time
- // stop looping
- cameraViewPlugin.viewLooping = false
-
- ```
-
-
- ## RenderTargetPreviewPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#render-target-preview/) —
- [Source Code](./src/plugins/ui/RenderTargetPreviewPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/RenderTargetPreviewPlugin.html)
-
- RenderTargetPreviewPlugin is a useful development and debugging plugin that renders any registered render-target to the screen in small collapsable panels.
-
- ```typescript
- import {ThreeViewer, RenderTargetPreviewPlugin, NormalBufferPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const normalPlugin = viewer.addPluginSync(new NormalBufferPlugin(HalfFloatType))
-
- const previewPlugin = viewer.addPluginSync(new RenderTargetPreviewPlugin())
-
- // Show the normal buffer in a panel
- previewPlugin.addTarget(()=>normalPlugin.target, 'normal', false, false)
- ```
-
- ## GeometryUVPreviewPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#geometry-uv-preview/) —
- [Source Code](./src/plugins/ui/GeometryUVPreviewPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/GeometryUVPreviewPlugin.html)
-
- GeometryUVPreviewPlugin is a useful development and debugging plugin
- that adds a panel to the viewer to show the UVs of a geometry.
-
- ```typescript
- import {ThreeViewer, GeometryUVPreviewPlugin, SphereGeometry} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const previewPlugin = viewer.addPluginSync(new GeometryUVPreviewPlugin())
-
- const geometry = new SphereGeometry(1, 32, 32)
- // Show the normal buffer in a panel
- previewPlugin.addGeometry(geometry, 'sphere')
- ```
-
- ## FrameFadePlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#frame-fade-plugin/) —
- [Source Code](./src/plugins/pipeline/FrameFadePlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/FrameFadePlugin.html)
-
- FrameFadePlugin adds a post-render pass to the render manager and blends the last frame with the current frame over time. This is useful for creating smooth transitions between frames for example when changing the camera position, material, object properties, etc to avoid a sudden jump.
-
- ```typescript
- import {ThreeViewer, FrameFadePlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const fadePlugin = viewer.addPluginSync(new FrameFadePlugin())
-
- // Make some changes in the scene (any visual change that needs to be faded)
-
- // Start transition and wait for it to finish
- await fadePlugin.startTransition(400) // duration in ms
-
- ```
-
- To stop a transition, call `fadePlugin.stopTransition()`. This will immediately set the current frame to the last frame and stop the transition. The transition is also automatically stopped when the camera is moved or some pointer event occurs on the canvas.
-
- The plugin automatically tracks `setDirty()` function calls in objects, materials and the scene. It can be triggerred by calling `setDirty` on any material or object in the scene. Check the [example](https://threepipe.org/examples/#frame-fade-plugin/) for a demo. This can be disabled by options in the plugin.
-
- ## VignettePlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#vignette-plugin/) —
- [Source Code](./src/plugins/postprocessing/VignettePlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/VignettePlugin.html)
-
- VignettePlugin adds a post-processing material extension to the ScreenPass in render manager
- that applies a vignette effect to the final render. The parameters `power` and `color` can be changed to customize the effect.
-
- ```typescript
- import {ThreeViewer, VignettePlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const vignettePlugin = viewer.addPluginSync(VignettePlugin)
-
- // Change the vignette color
- vignettePlugin.power = 1
- vignettePlugin.color = new Color(0.5, 0, 0)
-
- // or
- // vignettePlugin.color.set('#ff0000'); vignettePlugin.setDirty() // Call setDirty to tell the plugin that color has changed
- ```
-
- ## ChromaticAberrationPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#chromatic-aberration-plugin/) —
- [Source Code](./src/plugins/postprocessing/ChromaticAberrationPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/ChromaticAberrationPlugin.html)
-
- ChromaticAberrationPlugin adds a post-processing material extension to the ScreenPass in render manager
- that applies a chromatic-aberration effect to the final render. The parameter `intensity` can be changed to customize the effect.
-
- ```typescript
- import {ThreeViewer, ChromaticAberrationPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const chromaticAberrationPlugin = viewer.addPluginSync(ChromaticAberrationPlugin)
-
- // Change the chromaticAberration color
- chromaticAberrationPlugin.intensity = 0.5
- ```
-
- ## FilmicGrainPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#filmic-grain-plugin/) —
- [Source Code](./src/plugins/postprocessing/FilmicGrainPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/FilmicGrainPlugin.html)
-
- FilmicGrainPlugin adds a post-processing material extension to the ScreenPass in render manager
- that applies a filmic-grain effect to the final render. The parameters `power` and `color` can be changed to customize the effect.
-
- ```typescript
- import {ThreeViewer, FilmicGrainPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const filmicGrainPlugin = viewer.addPluginSync(FilmicGrainPlugin)
-
- // Change the filmicGrain color
- filmicGrainPlugin.intensity = 10
- filmicGrainPlugin.multiply = false
- ```
-
- ## NoiseBumpMaterialPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#noise-bump-material-plugin/) —
- [Source Code](./src/plugins/material/NoiseBumpMaterialPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/NoiseBumpMaterialPlugin.html)
-
- NoiseBumpMaterialPlugin adds a material extension to PhysicalMaterial to add support for sparkle bump / noise bump by creating procedural bump map from noise to simulate sparkle flakes.
- It uses voronoise function from blender along with several additions to generate the noise for the generation.
- It also adds a UI to the material to edit the settings.
- It uses `WEBGI_materials_noise_bump` glTF extension to save the settings in glTF/glb files.
-
- ```typescript
- import {ThreeViewer, NoiseBumpMaterialPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const noiseBump = viewer.addPluginSync(NoiseBumpMaterialPlugin)
-
- // Add noise bump to a material
- NoiseBumpMaterialPlugin.AddNoiseBumpMaterial(material, {
- flakeScale: 300,
- })
-
- // Change properties with code or use the UI
- material.userData._noiseBumpMat!.bumpNoiseParams = [1, 1]
- material.setDirty()
-
- // Disable
- material.userData._noiseBumpMat!.hasBump = false
- material.setDirty()
- ```
-
- ## CustomBumpMapPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#custom-bump-map-plugin/) —
- [Source Code](./src/plugins/material/CustomBumpMapPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/CustomBumpMapPlugin.html)
-
- CustomBumpMapPlugin adds a material extension to PhysicalMaterial to support custom bump maps.
- A Custom bump map is similar to the built-in bump map, but allows using an extra bump map and scale to give a combined effect.
- This plugin also has support for bicubic filtering of the custom bump map and is enabled by default.
- It also adds a UI to the material to edit the settings.
- It uses `WEBGI_materials_custom_bump_map` glTF extension to save the settings in glTF/glb files.
-
- ```typescript
- import {ThreeViewer, CustomBumpMapPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const customBump = viewer.addPluginSync(CustomBumpMapPlugin)
-
- // Add noise bump to a material
- customBump.enableCustomBump(material, bumpMap, 0.2)
-
- // Change properties with code or use the UI
- material.userData._customBumpMat = texture
- material.setDirty()
-
- // Disable
- material.userData._hasCustomBump = false
- // or
- material.userData._customBumpMat = null
- material.setDirty()
- ```
-
- ## ClearcoatTintPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#clearcoat-tint-plugin/) —
- [Source Code](./src/plugins/material/ClearcoatTintPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/ClearcoatTintPlugin.html)
-
- ClearcoatTintPlugin adds a material extension to PhysicalMaterial which adds tint and thickness to the built-in clearcoat properties.
- It also adds a UI to the material to edit the settings.
- It uses `WEBGI_materials_clearcoat_tint` glTF extension to save the settings in glTF/glb files.
-
- ```typescript
- import {ThreeViewer, ClearcoatTintPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const clearcoatTint = viewer.addPluginSync(ClearcoatTintPlugin)
-
- material.clearcoat = 1
- // add initial properties
- ClearcoatTintPlugin.AddClearcoatTint(material, {
- tintColor: '#ff0000',
- thickness: 1,
- })
-
- // Change properties with code or use the UI
- material.userData._clearcoatTint!.tintColor = '#ff0000'
- material.setDirty()
-
- // Disable
- material.userData._clearcoatTint.enableTint = false
- material.setDirty()
- ```
-
- ## FragmentClippingExtensionPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#fragment-clipping-extension-plugin/) —
- [Source Code](./src/plugins/material/FragmentClippingExtensionPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/FragmentClippingExtensionPlugin.html)
-
- FragmentClippingExtensionPlugin adds a material extension to PhysicalMaterial to add support for fragment clipping.
- Fragment clipping allows to clip fragments of the material in screen space or world space based on a circle, rectangle, plane, sphere, etc.
- It uses fixed SDFs with params defined by the user for clipping.
- It also adds a UI to the material to edit the settings.
- It uses `WEBGI_materials_fragment_clipping_extension` glTF extension to save the settings in glTF/glb files.
-
- ```typescript
- import {ThreeViewer, FragmentClippingExtensionPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const fragmentClipping = viewer.addPluginSync(FragmentClippingExtensionPlugin)
-
- // add initial properties
- FragmentClippingExtensionPlugin.AddFragmentClipping(material, {
- clipPosition: new Vector4(0.5, 0.5, 0, 0),
- clipParams: new Vector4(0.1, 0.05, 0, 1),
- })
-
- // Change properties with code or use the UI
- material.userData._fragmentClipping!.clipPosition.set(0, 0, 0, 0)
- material.setDirty()
-
- // Disable
- material.userData._clearcoatTint.clipEnabled = false
- material.setDirty()
- ```
-
- ## HDRiGroundPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#hdri-ground-plugin/) —
- [Source Code](./src/plugins/extras/HDRiGroundPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/HDRiGroundPlugin.html)
-
- HDRiGroundPlugin patches the background shader in the renderer to add support for ground projected environment map/skybox. Works simply by setting the background same as the environemnt and enabling the plugin.
-
- The world radius, tripod height, and origin position(center offset) can be set in the plugin.
-
- The plugin is disabled by default when added. Set `.enabled` to enable it or pass `true` in the constructor.
- If the background is not the same as the environment when enabled, the user will be prompted for this, unless `promptOnBackgroundMismatch` is set to `false` in the plugin.
-
- ```typescript
- import {ThreeViewer, HDRiGrounPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const hdriGround = viewer.addPluginSync(new HDRiGrounPlugin())
-
- // Load an hdr environment map
- await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
- // set background to environment
- viewer.scene.background = 'environment'
- // or
- // viewer.scene.background = viewer.scene.environemnt
-
- // enable the plugin
- hdriGround.enabled = true
- ```
-
- Check the [example](https://threepipe.org/examples/#hdri-ground-plugin/) for a demo.
-
- ## VirtualCamerasPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#virtual-cameras-plugin/) —
- [Source Code](./src/plugins/rendering/VirtualCamerasPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/VirtualCamerasPlugin.html)
-
- VirtualCamerasPlugin adds support for rendering to multiple virtual cameras in the viewer. These cameras are rendered in preRender callback just before the main camera is rendered. The virtual cameras can be added to the plugin and removed from it.
-
- The feed to the virtual camera is rendered to a Render Target texture which can be accessed and re-rendered in the scene or used in other plugins.
-
- ```typescript
- import {ThreeViewer, VirtualCamerasPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const virtualCameras = viewer.addPluginSync(new VirtualCamerasPlugin())
-
- const camera = new PerspectiveCamera2('orbit', viewer.canvas, false, 45, 1)
- camera.name = name
- camera.position.set(0, 5, 0)
- camera.target.set(0, 0.25, 0)
- camera.userData.autoLookAtTarget = true // automatically look at the target (in setDirty)
- camera.setDirty()
- camera.addEventListener('update', ()=>{
- viewer.setDirty() // if the camera is not added to the scene it wont update automatically when camera.setDirty is called(like from the UI)
- })
-
- const vCam = virtualCameras.addCamera(camera)
- console.log(vCam.target) // target is a WebGLRenderTarget/IRenderTarget
- ```
-
- Check the [virtual camera](https://threepipe.org/examples/#virtual-camera/) example for using the texture in the scene.
-
- ## EditorViewWidgetPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#editor-view-widget-plugin/) —
- [Source Code](./src/plugins/interaction/EditorViewWidgetPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/EditorViewWidgetPlugin.html)
-
- EditorViewWidgetPlugin adds a ViewHelper in the parent of the viewer canvas to show the current camera view and allow the user to change the camera view to one of the primary world axes.
-
- Simply add the plugin to the viewer to see the widget.
-
- ```typescript
- import {ThreeViewer, EditorViewWidgetPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const plugin = viewer.addPluginSync(new EditorViewWidgetPlugin())
-
- // to hide the widget
- plugin.enabled = false
- ```
-
- ## Object3DWidgetsPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#object3d-widgets-plugin/) —
- [Source Code](./src/plugins/extras/Object3DWidgetsPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/Object3DWidgetsPlugin.html)
-
- Object3DWidgetsPlugin adds support for light and camera helpers/gizmos in the viewer.
- A helper is automatically created when any supported light or camera is added to the scene.
- Simply add the plugin to the viewer to see the widget.
-
- Support for additional types of helpers can be added dynamically or by other plugins by pushing a helper constructor to the `Object3DWidgetsPlugin.helpers` array, and calling `Object3DWidgetsPlugin.refresh()`.
-
- The helper class prototype should implement the `IObject3DHelper` interface. Check `DirectionalLightHelper2` for an example.
-
- ```typescript
- import {ThreeViewer, Object3DWidgetsPlugin, Object3DGeneratorPlugin} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- // Add the plugin to add support
- const plugin = viewer.addPluginSync(new Object3DWidgetsPlugin())
-
- // Add some lights or cameras to the scene. (This can be done before adding the plugin as well)
- // Using Object3DGeneratorPlugin to create a camera and add it to the scene.
- const generator = viewer.getOrAddPluginSync(Object3DGeneratorPlugin)
- generator.generate('camera-perspective', {
- position: new Vector3(5, 5, 0),
- name: 'My Camera'
- })
-
- // to hide the widgets
- plugin.enabled = false
-
- // to add support for a custom helper
- plugin.helpers.push(MyCustomHelper)
- plugin.refresh()
-
- ```
-
- ## Object3DGeneratorPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#object3d-generator-plugin/) —
- [Source Code](./src/plugins/extras/Object3DGeneratorPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/Object3DGeneratorPlugin.html)
-
- Object3DGeneratorPlugin adds support for creating different types of lights and camera objects in the viewer.
- Call the `generate` method with any type to generate a type of object(like lights, cameras, mesh etc).
-
- Support for the following types of generators is included in the plugin:
- * camera-perspective - Creates instance of `PerspectiveCamera2`
- * light-directional - Creates instance of `DirectionalLight2`
- * light-ambient - Creates instance of `AmbientLight2`
- * light-point - Creates instance of `PointLight2`
- * light-spot - Creates instance of `SpotLight2`
- * light-hemisphere - Creates instance of `HemisphereLight2`
- * light-rect-area - Creates instance of `RectAreaLight2`
-
- Additional types of generators can be added dynamically or by other plugins by adding a custom generator function to the `Object3DGeneratorPlugin.generators` object. This is done by [GeometryGeneratorPlugin](#threepipeplugin-geometry-generator) to add various type of primitive objects like plane, sphere, etc
- A custom generator can take in any kind object as parameters and should return an `IObject3D`.
-
- Sample Usage
- ```typescript
- import {ThreeViewer, Object3DWidgetsPlugin, Object3DGeneratorPlugin, Mesh2} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- const generator = viewer.addPluginSync(Object3DGeneratorPlugin)
- generator.generate('camera-perspective', {
- position: new Vector3(5, 5, 0),
- name: 'My Camera'
- })
- const light = generator.generate('light-spot', {
- position: new Vector3(5, 0, 0),
- })
-
- // to add support for a custom helper
- plugin.generators['custom-object'] = (params)=>{
- const object = new Mesh2(new PlaneGeometry(1,1), new PhysicalMaterial())
- object.name = params.name ?? 'Custom Mesh'
- if(params.position) object.position.copy(params.position)
- return object
- }
- const obj = generator.generate('custom-object', {
- position: new Vector3(5, 0, 0),
- })
-
- // Add Object3DWidgetsPlugin to see the added lights and cameras.
- viewer.addPluginSync(new Object3DWidgetsPlugin())
- ```
-
- Check the [example](https://threepipe.org/examples/#object3d-generator-plugin/) for the UI.
-
- ## DeviceOrientationControlsPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#device-orientation-controls-plugin/) —
- [Source Code](./src/plugins/interaction/DeviceOrientationControlsPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/DeviceOrientationControlsPlugin.html)
-
- DeviceOrientationControlsPlugin enables controlling the main camera rotation in the scene with device orientation. This only works on devices which have a gyroscope(but can also be emulated in devtools in chrome).
- After the plugin is added, it adds support for setting `deviceOrientation` as the key in `scene.mainCamera.controlMode`.
-
- When the controls is started (for the first time), the current camera rotation is and the device orientation is saved and used as reference. To reset the saved device orientation, call `resetView` in the controls.
-
- Sample Usage
- ```typescript
- import {ThreeViewer, DeviceOrientationControlsPlugin, Mesh2} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- viewer.addPluginSync(DeviceOrientationControlsPlugin)
-
- // after some user action
- viewer.scene.mainCamera.controlsMode = 'deviceOrientation'
-
- // to reset the saved device orientation
- viewer.scene.mainCamera.controls.resetView()
-
- // switch back to default orbit controls
- viewer.scene.mainCamera.controlsMode = 'orbit'
- ```
-
- ## PointerLockControlsPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#pointer-lock-controls-plugin/) —
- [Source Code](./src/plugins/interaction/PointerLockControlsPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/PointerLockControlsPlugin.html)
-
- PointerLockControlsPlugin adds support for using PointerLockControls from three.js. It works similar to controls in first person shooter, captures the mouse pointer and uses it to look around with the camera.
-
- After the plugin is added, it adds support for setting `pointerLock` as the key in `scene.mainCamera.controlMode`.
-
- Sample Usage
- ```typescript
- import {ThreeViewer, PointerLockControlsPlugin, Mesh2} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- viewer.addPluginSync(PointerLockControlsPlugin)
-
- // after some user action
- viewer.scene.mainCamera.controlsMode = 'pointerLock'
-
- // listen to lock/unlock events
- viewer.scene.mainCamera.controls?.addEventListener('lock', ()=> console.log('pointer locked'))
- viewer.scene.mainCamera.controls?.addEventListener('unlock', ()=> console.log('pointer unlocked'))
-
- // switch back to default orbit controls
- viewer.scene.mainCamera.controlsMode = 'orbit'
- ```
-
- ## ThreeFirstPersonControlsPlugin
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#three-first-person-controls-plugin/) —
- [Source Code](./src/plugins/interaction/ThreeFirstPersonControlsPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/ThreeFirstPersonControlsPlugin.html)
-
- ThreeFirstPersonControlsPlugin adds support for using FirstPersonControls from three.js. It works similar to idle look around in first person games, it does not captures the mouse pointer.
-
- After the plugin is added, it adds support for setting `threeFirstPerson` as the key in `scene.mainCamera.controlMode`.
-
- Sample Usage
- ```typescript
- import {ThreeViewer, ThreeFirstPersonControlsPlugin, Mesh2} from 'threepipe'
-
- const viewer = new ThreeViewer({...})
-
- viewer.addPluginSync(ThreeFirstPersonControlsPlugin)
-
- // after some user action
- viewer.scene.mainCamera.controlsMode = 'threeFirstPerson'
-
- // switch back to default orbit controls
- viewer.scene.mainCamera.controlsMode = 'orbit'
- ```
-
- ## Rhino3dmLoadPlugin
-
- [Example](https://threepipe.org/examples/#rhino3dm-load/) —
- [Source Code](./src/plugins/import/Rhino3dmLoadPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/Rhino3dmLoadPlugin.html)
-
- Adds support for loading .3dm files generated by [Rhino 3D](https://www.rhino3d.com/). This plugin includes some changes with how 3dm files are loaded in three.js. The changes are around loading layer and primitive properties when set as reference in the 3dm files.
-
- It also adds some helpful options to process the model after load.
-
- ```typescript
- import {Rhino3dmLoadPlugin} from 'threepipe'
- const rhino3dmPlugin = viewer.addPluginSync(new Rhino3dmLoadPlugin())
-
- rhino3dmPlugin.importMaterials = true // import materials source from 3dm file
- rhino3dmPlugin.forceLayerMaterials = true // force material source to be layer in 3dm file.
- rhino3dmPlugin.hideLineMesh = true // hide all lines and points in the model.
- rhino3dmPlugin.replaceWithInstancedMesh = true // replace meshes with the same parent, geometry and material with a single instance mesh.
-
- const mesh = await viewer.load('file.3dm')
- ```
-
- ## PLYLoadPlugin
-
- [Example](https://threepipe.org/examples/#ply-load/) —
- [Source Code](./src/plugins/import/PLYLoadPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/PLYLoadPlugin.html)
-
- Adds support for loading .ply ([Polygon file format](https://en.wikipedia.org/wiki/PLY_(file_format))) files.
-
- ```typescript
- import {PLYLoadPlugin} from 'threepipe'
- viewer.addPluginSync(new PLYLoadPlugin())
-
- const mesh = await viewer.load('file.ply')
- ```
-
- ## USDZLoadPlugin
-
- [Example](https://threepipe.org/examples/#usdz-load/) —
- [Source Code](./src/plugins/import/USDZLoadPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/USDZLoadPlugin.html)
-
- Adds support for loading .usdz and .usda ([Universal Scene Description](https://graphics.pixar.com/usd/docs/index.html)) files.
-
- ```typescript
- import {USDZLoadPlugin} from 'threepipe'
- viewer.addPluginSync(new USDZLoadPlugin())
-
- const mesh = await viewer.load('file.usdz')
- const mesh2 = await viewer.load('file.usda')
- ```
-
- ## STLLoadPlugin
-
- [Example](https://threepipe.org/examples/#stl-load/) —
- [Source Code](./src/plugins/import/STLLoadPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/STLLoadPlugin.html)
-
- Adds support for loading .stl ([Stereolithography](https://en.wikipedia.org/wiki/STL_(file_format))) files.
-
- ```typescript
- import {STLLoadPlugin} from 'threepipe'
- viewer.addPluginSync(new STLLoadPlugin())
-
- const mesh = await viewer.load('file.stl')
- ```
-
- ## KTX2LoadPlugin
-
- [Example](https://threepipe.org/examples/#ktx2-load/) —
- [Source Code](./src/plugins/import/KTX2LoadPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/KTX2LoadPlugin.html)
-
- Adds support for loading .ktx2 ([Khronos Texture](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/) files.
-
- KTX2LoadPlugin also adds support for exporting loaded .ktx2 files in glTF files with the [KHR_texture_basisu](https://www.khronos.org/registry/KHR/textures/2.0-extensions/KHR_texture_basisu/) extension.
-
- ```typescript
- import {KTX2LoadPlugin} from 'threepipe'
- viewer.addPluginSync(new KTX2LoadPlugin())
-
- const texture = await viewer.load('file.ktx2')
- ```
-
- ## KTXLoadPlugin
-
- [Example](https://threepipe.org/examples/#ktx-load/) —
- [Source Code](./src/plugins/import/KTXLoadPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/KTXLoadPlugin.html)
-
- Adds support for loading .ktx ([Khronos Texture](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/) files.
-
- Note: This plugin only adds support for loading .ktx file, and not exporting them in the bundled .glb. Use .ktx2 files instead of .ktx files for better compression and performance.
-
- ```typescript
- import {KTXLoadPlugin} from 'threepipe'
- viewer.addPluginSync(new KTXLoadPlugin())
-
- const texture = await viewer.load('file.ktx')
- ```
-
- ## SimplifyModifierPlugin
-
- [Example](https://threepipe.org/examples/#simplify-modifier-plugin/) —
- [Source Code](./src/plugins/extras/SimplifyModifierPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/SimplifyModifierPlugin.html)
-
- Boilerplate for implementing a plugin for simplifying geometries.
- This is a base class and cannot be used directly.
-
- A sample to use it:
- ```typescript
- class SimplifyModifierPluginImpl extends SimplifyModifierPlugin {
- protected _simplify(geometry: IGeometry, count: number) {
- return new SimplifyModifier().modify(geometry, count) as IGeometry
- }
- }
-
- const plugin = viewer.addPluginSync(new SimplifyModifierPluginImpl())
-
- const root = await viewer.load('file.glb')
- plugin.simplifyAll(root, {factor: 0.75})
- ```
- Check the [example](https://threepipe.org/examples/#simplify-modifier-plugin/) for full implementation.
-
- ## MeshOptSimplifyModifierPlugin
-
- [Example](https://threepipe.org/examples/#meshopt-simplify-modifier-plugin/) —
- [Source Code](./src/plugins/extras/MeshOptSimplifyModifierPlugin.ts) —
- [API Reference](https://threepipe.org/docs/classes/MeshOptSimplifyModifierPlugin.html)
-
- Simplify modifier using [meshoptimizer](https://github.com/zeux/meshoptimizer) library. It Loads the library at runtime from a customisable CDN URL.
-
- Note: It does not guarantee that the geometry will be simplified to the exact target count.
-
- ```typescript
- const simplifyModifier = viewer.addPluginSync(new MeshOptSimplifyModifierPlugin())
-
- const root = await viewer.load('file.glb')
- simplifyModifier.simplifyAll(root, {factor: 0.75})
- ```
-
- # @threepipe Packages
-
- Additional plugins can be found in the [plugins](plugins/) directory.
- These add support for integrating with other libraries, adding new features, and other functionality with different licenses.
-
- ## @threepipe/plugin-tweakpane
- [Tweakpane](https://tweakpane.github.io/docs/) UI plugin for ThreePipe
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#tweakpane-ui-plugin/) —
- [Source Code](./plugins/tweakpane/src/TweakpaneUiPlugin.ts) —
- [API Reference](https://threepipe.org/plugins/tweakpane/docs/classes/TweakpaneUiPlugin.html)
-
- NPM: `npm install @threepipe/plugin-tweakpane`
-
- CDN: https://threepipe.org/plugins/tweakpane/dist/index.mjs
-
- TweakpaneUiPlugin adds support for using [uiconfig-tweakpane](https://github.com/repalash/uiconfig-tweakpane)
- to create a configuration UI in applications using the [Tweakpane](https://tweakpane.github.io/docs/) library.
-
- The plugin takes the [uiconfig](https://github.com/repalash/uiconfig.js)
- that's defined in the viewer and all the objects to automatically render a UI in the browser.
-
- ```typescript
- import {IObject3D, ThreeViewer, TonemapPlugin} from 'threepipe'
- import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
-
- const viewer = new ThreeViewer({...})
-
- // Add the plugin
- const plugin = viewer.addPluginSync(new TweakpaneUiPlugin(true)) // true to show expanded the UI by default
-
- // Add the UI for the viewer
- plugin.appendChild(viewer.uiConfig)
- // Add UI for some plugins
- plugin.setupPlugins(TonemapPlugin, DropzonePlugin)
- ```
-
- ## @threepipe/plugin-blueprintjs
- [Blueprint.js](https://blueprintjs.com/) UI plugin for ThreePipe
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#blueprintjs-ui-plugin/) —
- [Source Code](./plugins/blueprintjs/src/BlueprintJsUiPlugin.ts) —
- [API Reference](https://threepipe.org/plugins/blueprintjs/docs/classes/BlueprintJsUiPlugin.html)
-
- NPM: `npm install @threepipe/plugin-blueprintjs`
-
- CDN: https://threepipe.org/plugins/blueprintjs/dist/index.mjs
-
- BlueprintJsUiPlugin adds support for using [uiconfig-blueprint](https://github.com/repalash/uiconfig-blueprint)
- to create a configuration UI in applications using the [BlueprintJs](https://blueprintjs.com/) library.
-
- The plugin takes the [uiconfig](https://github.com/repalash/uiconfig.js)
- that's defined in the viewer and all the objects to automatically render a UI in the browser.
-
- ```typescript
- import {IObject3D, ThreeViewer, TonemapPlugin} from 'threepipe'
- import {BlueprintJsUiPlugin} from '@threepipe/plugin-blueprintjs'
-
- const viewer = new ThreeViewer({...})
-
- // Add the plugin
- const plugin = viewer.addPluginSync(new BlueprintJsUiPlugin(true)) // true to show expanded the UI by default
-
- // Add the UI for the viewer
- plugin.appendChild(viewer.uiConfig)
- // Add UI for some plugins
- plugin.setupPlugins(TonemapPlugin, DropzonePlugin)
- ```
-
- ## @threepipe/plugin-tweakpane-editor
-
- Tweakpane Editor Plugin for ThreePipe
-
- [//]: # (todo: image)
-
- [Example](https://threepipe.org/examples/#tweakpane-editor/) —
- [Source Code](./plugins/tweakpane-editor/src/TweakpaneEditorPlugin.ts) —
- [API Reference](https://threepipe.org/plugins/tweakpane-editor/docs/classes/TweakpaneEditorPlugi —
-
- NPM: `npm install @threepipe/plugin-tweakpane-editor`
-
- CDN: https://threepipe.org/plugins/tweakpane-editor/dist/index.mjs
-
- TweakpaneEditorPlugin uses TweakpaneUiPlugin to create an editor for editing viewer,
- plugins, model and material configurations in the browser.
-
- ```typescript
- import {IObject3D, ThreeViewer, TonemapPlugin} from 'threepipe'
- import {TweakpaneEditorPlugin} from '@threepipe/plugin-tweakpane-editor'
-
- const viewer = new ThreeViewer({...})
-
- viewer.addPluginSync(new TweakpaneUiPlugin(true))
- const editor = viewer.addPluginSync(new TweakpaneEditorPlugin())
-
- // Add some plugins to the viewer
- await viewer.addPlugins([
- new ViewerUiConfigPlugin(),
- // new SceneUiConfigPlugin(), // this is already in ViewerUiPlugin
- new DepthBufferPlugin(HalfFloatType, true, true),
- new NormalBufferPlugin(HalfFloatType, false),
- new RenderTargetPreviewPlugin(false),
- ])
-
- // Load the plugin UI in the editor and tweakpane ui with categories.
- editor.loadPlugins({
- ['Viewer']: [ViewerUiConfigPlugin, SceneUiConfigPlugin, DropzonePlugin, FullScreenPlugin],
- ['GBuffer']: [DepthBufferPlugin, NormalBufferPlugin],
- ['Post-processing']: [TonemapPlugin],
- ['Debug']: [RenderTargetPreviewPlugin],
- })
- ```
-
- ## @threepipe/plugins-extra-importers
-
- Exports several plugins to add support for various file types.
-
- [Example](https://threepipe.org/examples/#extra-importer-plugins/) —
- [Source Code](./plugins/extra-importers/src/index.ts) —
- [API Reference](https://threepipe.org/plugins/extra-importers/docs)
-
- NPM: `npm install @threepipe/plugins-extra-importers`
-
- CDN: https://threepipe.org/plugins/extra-importers/dist/index.mjs
-
- This package exports several plugins to add support for several file types using the following plugins
-
- - [TDSLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/TDSLoadPlugin.html) - Load 3DS Max (.3ds) files
- - [ThreeMFLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/ThreeMFLoadPlugin.html) - Load 3MF (.3mf) files
- - [ColladaLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/ColladaLoadPlugin.html) - Load Collada (.dae) files
- - [AMFLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/AMFLoadPlugin.html) - Load AMF (.amf) files
- - [BVHLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/BVHLoadPlugin.html) - Load BVH (.bvh) files
- - [VOXLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/VOXLoadPlugin.html) - Load MagicaVoxel (.vox) files
- - [GCodeLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/GCodeLoadPlugin.html) - Load GCode (.gcode) files
- - [MDDLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/MDDLoadPlugin.html) - Load MDD (.mdd) files
- - [PCDLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/PCDLoadPlugin.html) - Load Point cloud data (.pcd) files
- - [TiltLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/TiltLoadPlugin.html) - Load Tilt Brush (.tilt) files
- - [VRMLLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/VRMLLoadPlugin.html) - Load VRML (.wrl) files
- - [MPDLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/MPDLoadPlugin.html) - Load LDraw (.mpd) files
- - [VTKLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/VTKLoadPlugin.html) - Load VTK (.vtk) files
- - [XYZLoadPlugin](https://threepipe.org/plugins/extra-importers/docs/classes/XYZLoadPlugin.html) - Load XYZ (.xyz) files
-
- To add all the plugins at once use `extraImporters`. This adds support for loading all the above file types.
- ```typescript
- import {ThreeViewer} from 'threepipe'
- import {extraImporters} from '@threepipe/plugins-extra-importers'
-
- const viewer = new ThreeViewer({...})
- viewer.addPluginsSync(extraImporters)
-
- // Now load any file as is.
- const model = await viewer.load<IObject3D>('file.3mf')
-
- // To load the file as a data url, use the correct mimetype
- const model1 = await viewer.load<IObject3D>('data:model/3mf;base64,...')
- ```
-
- Remove the `<IObject3D>` if using javascript and not typescript.
-
- ## @threepipe/plugin-blend-importer
-
- Exports [BlendImporterPlugin](https://threepipe.org/plugins/blend-importer/docs/classes/BlendLoadPlugin.html) which adds support for loading .blend files.
-
- It uses [js.blend](https://github.com/acweathersby/js.blend) for parsing blend file structure.
-
- Note: This is still a WIP.
- Currently working: `Mesh`, `BufferGeometry` and basic `PointLight`.
- To be added: `PhysicalMaterial`, `UnlitMaterial` (similar to blender-gltf-io plugin)
-
- [Example](https://threepipe.org/examples/#blend-load/) —
- [Source Code](./plugins/blend-importer/src/index.ts) —
- [API Reference](https://threepipe.org/plugins/blend-importer/docs)
-
- NPM: `npm install @threepipe/plugin-blend-importer`
-
- ```typescript
- import {ThreeViewer} from 'threepipe'
- import {BlendLoadPlugin} from '@threepipe/plugin-blend-importer'
-
- const viewer = new ThreeViewer({...})
- viewer.addPluginSync(BlendLoadPlugin)
-
- // Now load any .blend file.
- const model = await viewer.load<IObject3D>('path/to/file.blend')
-
- // To load the file as a data url, use the correct mimetype
- const model1 = await viewer.load<IObject3D>('data:application/x-blender;base64,...')
-
- ```
-
- [//]: # ( TODO: The plugin should parse and references to other assets and find them relative to the .blend file or the current location.)
-
- ## @threepipe/plugin-geometry-generator
-
- Exports [GeometryGeneratorPlugin](https://threepipe.org/plugins/geometry-generator/docs/classes/BlendLoadPlugin.html) with several Geometry generators to create parametric and updatable geometries like plane, circle, sphere, box, torus, cylinder, cone etc.
-
- [Example](https://threepipe.org/examples/#geometry-generator-plugin/) —
- [Source Code](./plugins/geometry-generator/src/index.ts) —
- [API Reference](https://threepipe.org/plugins/geometry-generator/docs)
-
- NPM: `npm install @threepipe/plugin-geometry-generator`
-
- The generated geometries/meshes include the parameters in the userData and can be re-generated by changing the parameters from the UI or the plugin API.
-
- Includes the following generator which inherit from [AGeometryGenerator](https://threepipe.org/plugins/geometry-generator/docs/classes/AGeometryGenerator.html):
- - **plane**: [PlaneGeometryGenerator](https://threepipe.org/plugins/geometry-generator/docs/classes/PlaneGeometryGenerator),
- - **sphere**: [SphereGeometryGenerator](https://threepipe.org/plugins/geometry-generator/docs/classes/SphereGeometryGenerator),
- - **box**: [BoxGeometryGenerator](https://threepipe.org/plugins/geometry-generator/docs/classes/BoxGeometryGenerator),
- - **circle**: [CircleGeometryGenerator](https://threepipe.org/plugins/geometry-generator/docs/classes/CircleGeometryGenerator),
- - **torus**: [TorusGeometryGenerator](https://threepipe.org/plugins/geometry-generator/docs/classes/TorusGeometryGenerator),
- - **cylinder**: [CylinderGeometryGenerator](https://threepipe.org/plugins/geometry-generator/docs/classes/CylinderGeometryGenerator),
-
-
- Sample Usage:
-
- ```typescript
- import {ThreeViewer, UnlitMaterial} from 'threepipe'
- import {GeometryGeneratorPlugin} from '@threepipe/plugin-geometry-generator'
-
- const viewer = new ThreeViewer({...})
- const generator = viewer.addPluginSync(GeometryGeneratorPlugin)
-
- const sphere = generator.generateObject('sphere', {radius: 3})
- viewer.scene.addObject(sphere)
-
- // to update the geometry
- generator.updateGeometry(sphere.geometry, {radius: 4, widthSegments: 100})
-
- // to add a custom generator
- generator.generators.custom = new CustomGenerator('custom') // Extend from AGeometryGenerator or implement GeometryGenerator interface
- // refresh the ui so the new generator is available to select.
- generator.uiConfig.uiRefresh?.()
-
- // change the material type for all objects
- generator.defaultMaterialClass = UnlitMaterial // by default its PhysicalMaterial
- viewer.scene.addObject(generator.generateObject('box', {width: 2, height: 2, depth: 2}))
-
- ```
-
- ## @threepipe/plugin-gaussian-splatting
-
- Exports [GaussianSplattingPlugin](https://threepipe.org/plugins/gaussian-splatting/docs/classes/GaussianSplattingPlugin.html) which adds support for loading .blend files.
-
- It uses [`three-gaussian-splat`](./plugins/gaussian-splatting/src/three-gaussian-splat), a rewrite of [@zappar/three-guassian-splat](https://github.com/zappar-xr/three-gaussian-splat) (and [gsplat.js](https://github.com/huggingface/gsplat.js) and [antimatter15/splat](https://github.com/antimatter15/splat)) for loading splat files and rendering gaussian splats.
-
- [Example](https://threepipe.org/examples/#splat-load/) —
- [Source Code](./plugins/gaussian-splatting/src/index.ts) —
- [API Reference](https://threepipe.org/plugins/gaussian-splatting/docs)
-
- NPM: `npm install @threepipe/plugin-gaussian-splatting`
-
- Note: This is still a WIP.
-
- Currently working:
- * Importing .splat files (just array buffer of gaussian splat attributes)
- * ThreeGaussianSplatPlugin (Same as GaussianSplattingPlugin), add importer and update events to the viewer
- * GaussianSplatMaterialExtension for adding gaussian splat functionality to any material like Unlit, Physical
- * GaussianSplatMesh a subclass of Mesh2 for holding the gaussian splat geometry and a material with gaussian splat extension. also handles basic raycast in the splat geometry. (assuming simple points)
- * GaussianSplatGeometry holds the geometry data and and the sort worker. Computes correct bounding box and sphere.
- * SplatLoader for loading splat files and creating the geometry and material.
- * GaussianSplatMaterialUnlit, GaussianSplatMaterialRaw
- * GaussianSplatMaterialPhysical, working but normals are hardcoded to 0,1,0
-
- TBD:
- * Exporting/embedding splat files into glb
- * Rendering to depth/gbuffer
- * Estimate normals/read from file
- * Lighting in GaussianSplatMaterialPhysical
-
- ```typescript
- import {ThreeViewer} from 'threepipe'
- import {GaussianSplattingPlugin} from '@threepipe/plugin-gaussian-splatting'
-
- const viewer = new ThreeViewer({...})
- viewer.addPluginSync(GaussianSplattingPlugin)
-
- // Now load any .splat file.
- const model = await viewer.load<GaussianSplatMesh>('path/to/file.splat')
-
- ```
-
- ## @threepipe/plugin-svg-renderer
-
- Exports [ThreeSVGRendererPlugin](https://threepipe.org/plugins/svg-renderer/docs/classes/ThreeSVGRendererPlugin.html) and [BasicSVGRendererPlugin](https://threepipe.org/plugins/svg-renderer/docs/classes/BasicSVGRendererPlugin.html) which provide support for rendering the 3d scene as [SVG(Scalable Vector Graphics)](https://developer.mozilla.org/en-US/docs/Web/SVG). The generated SVG is compatible with browser rendering and other software like figma, illustrator etc.
-
- [Example](https://threepipe.org/examples/#three-svg-renderer/) —
- [Source Code](./plugins/svg-renderer/src/index.ts) —
- [API Reference](https://threepipe.org/plugins/svg-renderer/docs) —
- [GPLV3 License](./plugins/svg-renderer/LICENSE)
-
- NPM: `npm install @threepipe/plugin-svg-renderer`
-
- Note: This is still a WIP. API might change slightly
-
- `ThreeSVGRendererPlugin` uses [`three-svg-renderer`](./plugins/svg-renderer/src/three-svg-renderer), which is a modified version of [three-svg-renderer](https://www.npmjs.com/package/three-svg-renderer) (GPLV3 Licenced).
- The plugin renderers meshes in the viewer scene to svg objects by computing polygons and contours of the geometry in view space. Check [LokiResearch/three-svg-renderer](https://github.com/LokiResearch/three-svg-renderer?tab=readme-ov-file#references) for more details.
- In the modified version that is used here, support for some types of geometries is added and a rendered image in screen-space is used to create raster fill images for paths along with some other small changes. Check out the [Example](https://threepipe.org/examples/#three-svg-renderer/) for demo. See also [svg-geometry-playground example](https://threepipe.org/examples/#svg-geometry-playground/) for usage with other plugins `PickingPlugin`, `TransformControlsPlugin` and `GeometryGeneratorPlugin`.
-
- Note that this does not support all the features of three.js and may not work with all types of materials and geometries. Check the examples for a list of sample models that do and don't work.
-
- `BasicSVGRendererPlugin` is a sample plugin using [SVGRenderer](https://threejs.org/docs/index.html?q=svg#examples/en/renderers/SVGRenderer) from three.js addons. This renders all triangles in the scene to separate svg paths. Check the three.js docs for more details. Check out the [Example](https://threepipe.org/examples/#basic-svg-renderer/) for demo.
-
- ```typescript
- import {ThreeViewer} from 'threepipe'
- import {ThreeSVGRendererPlugin} from '@threepipe/plugin-svg-renderer'
-
- const viewer = new ThreeViewer({
- ...,
- rgbm: false, // this is required
- })
- const svgRender = viewer.addPluginSync(ThreeSVGRendererPlugin)
- svgRender.autoRender = true // automatically render when camera or any object changes.
- svgRender.autoMakeSvgObjects = true // automatically create SVG objects for all meshes in the scene.
- // svgRender.makeSVGObject(object) // manually create SVG object for an object. (if autoMakeSvgObjects is false)
-
- // Now load or generate any 3d model. Make sure its not very big. And the meshes are optimized.
- const model = await viewer.load<IOBject3D>('path/to/file.glb')
-
- // clear the background of the viewer
- viewer.scene.backgroundColor = null
- viewer.scene.background = null
-
- // disable damping to get better experience.
- viewer.scene.mainCamera.controls!.enableDamping = false
-
- // hide the canvas to see the underlying svg node.
- // note: do not set the display to none or remove the canvas as OrbitControls and other plugins might still be tracking the canvas.
- viewer.canvas.style.opacity = '0'
-
- // 3d pipeline can also be disabled like this if `drawImageFills` is `false` to get better performance. Do this only after loading the model.
- // await viewer.doOnce('postFrame') // wait for the first frame to be rendered (for autoScale etc)
- // viewer.renderManager.autoBuildPipeline = false
- // viewer.renderManager.pipeline = [] // this will disable main viewer rendering
- ```
|