VisualStudio 2017 C#, EdgeJsを使用しております。
C#上でReCapAPIを使用し、画像を3Dモデルに変換したいと考えています。
そこでReCapAPIを使用しているサンプルコード
recap-walkthrough-photo.to.3d-master(Node.js, JavaScript)
を利用し、最終的には3Dモデルに変換したい画像を使用してモデルを取得したいです。
お伺いしたいのですが、
C#上にてJavaScriptの変数に値を渡す方法(ここではAutodeskのClientIDなどを渡します)と、
渡した後に Node.jsからnpm startを実行する方法について
アドバイスをいただきたく思います。
JavaScript
1//------------------------------------------------------------------- 2// These packages are included in package.json. 3// Run `npm install` to install them. 4// 'path' is part of Node.js and thus not inside package.json. 5//------------------------------------------------------------------- 6var express = require('express'); // For web server 7var Axios = require('axios'); // A Promised base http client 8var bodyParser = require('body-parser'); // Receive JSON format 9 10// Set up Express web server 11var app = express(); 12app.use(bodyParser.json()); 13app.use(express.static(__dirname + '/www')); 14 15// This is for web server to start listening to port 3000 16app.set('port', 3000); 17var server = app.listen(app.get('port'), function () { 18 console.log('Server listening on port ' + server.address().port); 19}); 20 21//------------------------------------------------------------------- 22// Configuration for your Forge account 23// Initialize the 2-legged OAuth2 client, and 24// set specific scopes 25//------------------------------------------------------------------- 26var FORGE_CLIENT_ID = process.env.FORGE_CLIENT_ID; 27var FORGE_CLIENT_SECRET = process.env.FORGE_CLIENT_SECRET; 28var access_token = ''; 29var scopes = 'data:read data:write'; 30const querystring = require('querystring'); //querystring 31 32// // Route /api/forge/oauth 33app.get('/api/forge/oauth', function (req, res) { 34 Axios({ 35 method: 'POST', 36 url: 'https://developer.api.autodesk.com/authentication/v1/authenticate', 37 headers: { 38 'content-type': 'application/x-www-form-urlencoded', 39 }, 40 data: querystring.stringify({ 41 client_id: FORGE_CLIENT_ID, 42 client_secret: FORGE_CLIENT_SECRET, 43 grant_type: 'client_credentials', 44 scope: scopes 45 }) 46 }) 47 .then(function (response) { 48 // Success 49 access_token = response.data.access_token; 50 console.log(response); 51 res.send('<p>Authentication success!</p><a href="/api/forge/recap/photoscene/add">Add a photoscene</a>'); 52 }) 53 .catch(function (error) { 54 // Failed 55 console.log(error); 56 res.send('Failed to authenticate'); 57 }); 58}); 59// Route /api/forge/recap/photoscene/add 60// Creates and initializes a photoscene for reconstruction. 61app.get('/api/forge/recap/photoscene/add', function (req, res) { 62 Axios({ 63 method: 'POST', 64 url: 'https://developer.api.autodesk.com/photo-to-3d/v1/photoscene', 65 headers: { 66 'content-type': 'application/json', 67 'Authorization': 'Bearer ' + access_token 68 }, 69 data: querystring.stringify({ 70 scenename: 'myscenename', 71 format: 'obj' //rcm->obj, ply 72 }) 73 }) 74 .then(function (response) { 75 // Success 76 console.log(response); 77 if (response.data.Error) { 78 res.send(response.data.Error.msg); 79 } 80 var photosceneId = response.data.Photoscene.photosceneid; 81 var nextLink = '/api/forge/recap/photoscene/upload?photosceneid=' + photosceneId; 82 res.send('<p>Photoscene added!</p><a href="' + nextLink + '">Upload files to photoscene</a>'); 83 }) 84 .catch(function (error) { 85 // Failed 86 console.log(error); 87 res.send('Failed to create a photoscene'); 88 }); 89}); 90 91// Route /api/forge/recap/photoscene/upload 92// Adds one or more files to a photoscene. 93app.get('/api/forge/recap/photoscene/upload', function (req, res) { 94 var photosceneId = req.query.photosceneid; 95 Axios({ 96 method: 'POST', 97 url: 'https://developer.api.autodesk.com/photo-to-3d/v1/file', 98 headers: { 99 'content-type': 'application/x-www-form-urlencoded', 100 'Authorization': 'Bearer ' + access_token 101 }, 102 data: querystring.stringify({ 103 photosceneid: photosceneId, 104 type: 'image', 105 'file[0]': 'https://s3.amazonaws.com/adsk-recap-public/forge/lion/DSC_1158.JPG', 106 'file[1]': 'https://s3.amazonaws.com/adsk-recap-public/forge/lion/DSC_1159.JPG', 107 'file[2]': 'https://s3.amazonaws.com/adsk-recap-public/forge/lion/DSC_1160.JPG', 108 'file[3]': 'https://s3.amazonaws.com/adsk-recap-public/forge/lion/DSC_1162.JPG', 109 'file[4]': 'https://s3.amazonaws.com/adsk-recap-public/forge/lion/DSC_1163.JPG', 110 'file[5]': 'https://s3.amazonaws.com/adsk-recap-public/forge/lion/DSC_1164.JPG', 111 'file[6]': 'https://s3.amazonaws.com/adsk-recap-public/forge/lion/DSC_1165.JPG' 112 }) 113 }) 114 .then(function (response) { 115 // Success 116 console.log(response); 117 if (response.data.Error) { 118 res.send(response.data.Error.msg); 119 } 120 console.log(JSON.stringify(response.data.Files)); 121 var nextLink = '/api/forge/recap/photoscene/process?photosceneid=' + photosceneId; 122 res.send('<p>Files added to photoscene!</p><a href="' + nextLink + '">Begin processing photoscene</a>'); 123 }) 124 .catch(function (error) { 125 // Failed 126 console.log(error); 127 res.send('Failed to upload files to photoscene'); 128 }); 129}); 130//以下略...
C#
1//#define RECAP 2#define EDGE_JS 3using System; 4using System.Collections.Generic; 5using System.ComponentModel; 6using System.Data; 7using System.Drawing; 8using System.Linq; 9using System.Text; 10using System.Threading.Tasks; 11using System.Windows.Forms; 12using System.IO; 13using System.Text.RegularExpressions; 14using AForge.Video; 15using AForge.Video.FFMPEG; 16using AForge.Video.VFW; 17using AForge.Video.DirectShow; 18using EdgeJs; 19 20namespace software 21{ 22 public partial class MainForm : Form 23 { 24 private void ReCapButton_Click(object sender, EventArgs e) 25 { 26 //==== 指定URLにPOST通信を行う ====// 27 //----- AFORGE Client ID & Client Secret -----// 28 string client_ID = "~~~"; //JavaScriptへの入力値 29 string client_Secret = "~~~";//JavaScriptへの入力値 30 //以下にNode.js, JavaScript操作を作成したい 31 } 32 } 33}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/17 06:45
2019/02/18 02:46